LAMA
lama::DenseMatrix< T > Class Template Reference

Class for dense matrices where rows are distributed among rows and columns are splitted according to a column distribution. More...

#include <DenseMatrix.hpp>

Inheritance diagram for lama::DenseMatrix< T >:

Public Types

typedef T ValueType
typedef boost::shared_ptr
< DenseStorage< T > > 
DenseStoragePtr
enum  SyncKind { ASYNCHRONOUS, SYNCHRONOUS }
 SyncKind describes if the communication and computation should be done synchronously or asynchronously. More...
enum  MatrixKind { DENSE, SPARSE }
 MatrixKind describes if a matrix is dense or sparse. More...
typedef const MatrixExpressionMemberType
 ExpressionMemberType is the type that is used the template Expression to store a Vector.

Public Member Functions

 DenseMatrix ()
 Default constructor.
 DenseMatrix (const IndexType numRows, const IndexType numColumns)
 Constructor of a replicated dense matrix.
 DenseMatrix (DistributionPtr rowDist, DistributionPtr colDist)
 Constructor of a distributed dense matrix.
 DenseMatrix (DistributionPtr dist)
 Construct a square unity matrix.
 DenseMatrix (const DenseMatrix< ValueType > &other)
 Overwrite default copy constructor so it uses other copy constructor.
 DenseMatrix (const Matrix &other)
 Construct a dense matrix from any other matrix that can be of a different type.
 DenseMatrix (const Matrix &other, DistributionPtr distribution, DistributionPtr colDistribution)
 Construct a dense matrix from any other matrix with new distributions.
 DenseMatrix (const DenseMatrix< ValueType > &matrix, DistributionPtr distribution, DistributionPtr colDistribution)
 DenseMatrix (const _MatrixStorage &localData, DistributionPtr rowDist, DistributionPtr colDist)
 Constructor of a dense matrix by local storage.
template<typename OtherValueType >
 DenseMatrix (const IndexType numRows, const IndexType numColumns, const IndexType numNoneZeros, const IndexType *const ia, const IndexType *const ja, const OtherValueType *const values)
 Creates a replicated dense matrix from the passed csr sparse matrix.
 DenseMatrix (const Expression< Expression< Scalar, Expression< Matrix, Matrix, Times >, Times >, Expression< Scalar, Matrix, Times >, Plus > expression)
 DenseMatrix (const Expression< Matrix, Matrix, Times > expression)
 DenseMatrix (const Expression< Scalar, Expression< Matrix, Matrix, Times >, Times > expression)
 DenseMatrix (const Expression< Scalar, Matrix, Times > expression)
 DenseMatrix (const std::string &filename)
 Constructor of a replicated dense matrix by reading the matrix data from a file.
virtual ~DenseMatrix ()
DenseMatrixoperator= (const DenseMatrix &matrix)
 Override default assignment operator needed to guarantee deep copy.
DenseMatrixoperator= (const Matrix &matrix)
 the assignment operator for matrix.
DenseMatrixoperator= (const Expression< Scalar, Matrix, Times > expression)
 the assignment operator for a scalar matrix multiplication.
DenseMatrixoperator= (const Expression< Matrix, Matrix, Times > expression)
 the assignment operator for a matrix matrix multiplication.
DenseMatrixoperator= (const Expression< Scalar, Expression< Matrix, Matrix, Times >, Times > expression)
 the assignment operator for a scalar matrix matrix multiplication.
DenseMatrixoperator= (const Expression< Expression< Scalar, Expression< Matrix, Matrix, Times >, Times >, Expression< Scalar, Matrix, Times >, Plus > expression)
 the assignment operator for a GEMM expression.
const char * getTypeName () const
 Implementation for Matrix::getTypeName()
Matrix::MatrixKind getMatrixKind () const
 Each derived matrix must give info about its kind (DENSE or SPARSE).
virtual void setContext (const ContextPtr context)
 specifies on which compute back end the matrix operations should take place.
virtual ContextPtr getContextPtr () const
 Getter routine for the context.
virtual void setIdentity ()
 Operator that sets the matrix to the identity matrix.
template<typename OtherValueType >
void setRawDenseData (const IndexType numRows, const IndexType numColumns, const OtherValueType values[], const OtherValueType eps=0.0)
 Set matrix with global dense data.
virtual void buildCSRData (LAMAArray< IndexType > &rowIA, LAMAArray< IndexType > &rowJA, _LAMAArray &rowValues) const
 Implementation of pure method for the dense storage format.
virtual void setCSRData (const LAMAArray< IndexType > &rowIA, const LAMAArray< IndexType > &rowJA, const _LAMAArray &rowValues, DistributionPtr rowDistribution, DistributionPtr colDistribution)
 Implementation of pure method.
void setCSRDataLocal (const LAMAArray< IndexType > &rowIA, const LAMAArray< IndexType > &rowJA, const _LAMAArray &rowValues) const
 Local version of setCSRData .
virtual void clear ()
 Implementation of pure method.
virtual void allocate (const IndexType numRows, const IndexType numColumns)
 Reallocate this matrix to a replicated zero-matrix of the given shape.
virtual void allocate (DistributionPtr rowDistribution, DistributionPtr colDistribution)
 Reallocate this matrix to a distributed zero-matrix by the given distributions.
virtual void assign (const Matrix &other)
 This method assigns a matrix to this matrix with automatic conversion to the needed matrix type and the current row / column distribution of.
void swap (DenseMatrix< ValueType > &other)
 Swap will swap all member variables of the two dense matrices.
void assignSparse (const _SparseMatrix &other)
void assign (const _MatrixStorage &storage)
 Assign replicated storage for a replicated matrix.
void assign (const _MatrixStorage &storage, DistributionPtr rowDist, DistributionPtr colDist)
 Assign local storage for a distributed matrix.
void assignLocal (const _MatrixStorage &other)
virtual void buildLocalStorage (_MatrixStorage &storage) const
 Implementation of Matrix::buildLocalStorage.
void redistribute (DistributionPtr rowDistribution, DistributionPtr colDistribution)
 Implementation of pure method.
virtual void getDiagonal (Vector &diagonal) const
 This method returns the diagonal.
virtual void getRow (Vector &row, const IndexType globalRowIndex) const
 This method returns one row of the matrix.
virtual void setDiagonal (const Vector &diagonal)
 This method replaces the diagonal.
virtual void setDiagonal (const Scalar diagonalValue)
 This method replaces the diagonal by a diagonal value.
virtual void scale (const Vector &values)
 This method scales all values with a vector.
virtual void scale (const Scalar value)
 This method scales all matrix values with a scalar.
Scalar getValue (lama::IndexType i, lama::IndexType j) const
 returns a copy of the value at the passed global indexes.
void matrixTimesScalar (const Matrix &other, const Scalar alpha)
 matrixTimesScalar computes this = alpha * other
void matrixTimesVectorImpl (DenseVector< ValueType > &denseResult, const ValueType alphaValue, const DenseVector< ValueType > &denseX, const ValueType betaValue, const DenseVector< ValueType > &denseY) const
 Matrix times vector with same values types and correct distributions.
virtual void invert (const Matrix &other)
 Set this matrix with the inverse of another square matrix.
void invert ()
 Invert in place.
Scalar maxDiffNorm (const Matrix &other) const
 Implementation of Matrix::maxDiffNorm for dense matrices.
ValueType maxDiffNormImpl (const DenseMatrix< ValueType > &other) const
 Get the maximal difference between two elements for dense matrices of same type.
void matrixTimesMatrix (Matrix &result, const Scalar alpha, const Matrix &x, const Scalar beta, const Matrix &y) const
 Implementation of pure method Matrix::matrixTimesMatrix.
virtual void prefetch () const
 Prefetch matrix data to its 'preferred' context location.
void prefetch (lama::ContextPtr loc) const
void wait () const
 wait for a possibly running prefetch.
const DenseStorage< ValueType > & getLocalStorage () const
 This method returns the storage containing the local data regarding row/col distribution.
DenseStorage< ValueType > & getLocalStorage ()
virtual IndexType getLocalNumValues () const
 Implementation of Matrix::getLocalNumValues, getLocalNumRows, getLocalNumColumns.
virtual IndexType getLocalNumRows () const
 Getter routine for the local number of rows.
virtual IndexType getLocalNumColumns () const
 Getter routine for the local number of rows and columns.
virtual IndexType getNumValues () const
 Get the total number of non-zero values in the matrix.
std::vector< DenseStoragePtr > & getCyclicLocalValues ()
const std::vector
< DenseStoragePtr > & 
getCyclicLocalValues () const
virtual bool hasDiagonalProperty () const
 hasDiagonalProperty returns the diagonalProperty of the local storage.
virtual void resetDiagonalProperty ()
 resetDiagonalProperty rechecks the storages for their diagonal property
virtual void writeAt (std::ostream &stream) const
 Write some information about this to the passed stream.
virtual Scalar::ScalarType getValueType () const
 Query the value type of the matrix elements, e.g.
void writeToFile (const std::string &fileName, const File::FileType fileType=File::BINARY, const File::DataType dataType=File::INTERNAL, const File::IndexDataType indexDataTypeIA=File::INT, const File::IndexDataType indexDataTypeJA=File::INT) const
 Method writes dense matrix to a file.
virtual std::auto_ptr< Matrixcreate () const
 Constructing a new object by the default constructor.
virtual std::auto_ptr< Matrixcopy () const
 Constructing a new object by the copy constructor.
virtual size_t getMemoryUsage () const
 getMemoryUsage returns the global memory that is allocated to hold this matrix.
const std::vector< PartitionId > & getOwners () const
template<typename OtherValueType >
void getDiagonalImpl (DenseVector< OtherValueType > &diagonal) const
template<>
const char * typeName ()
template<>
const char * typeName ()
template<typename OtherValueType >
void copyDenseMatrix (const DenseMatrix< OtherValueType > &other)
void matrixTimesVector (Vector &result, const Scalar alpha, const Vector &x, const Scalar beta, const Vector &y) const
 matrixTimesVector computes result = alpha * this * x + beta * y
std::auto_ptr< _LAMAArraycreateArray () const
 This routine creates a LAMA array with the same value type as the matrix.
Scalar operator() (IndexType i, IndexType j) const
 returns a copy of the value at the passed global indexes.
IndexType getNumRows () const
 Returns the number of global rows.
IndexType getNumColumns () const
 Returns the number of columns.
double getSparsityRate () const
virtual void matrix2CSRGraph (IndexType *xadj, IndexType *adjncy, IndexType *vwgt, CommunicatorPtr comm, const IndexType *globalRowIndices=NULL, IndexType *vtxdist=NULL) const
 transformation from matrix type to a csr graph
const DistributiongetColDistribution () const
 gets a constant reference to the column distribution.
DistributionPtr getColDistributionPtr () const
 gets a pointer to the column distribution.
virtual void setContext (const ContextPtr localContext, const ContextPtr haloContext)
 Only sparse matrices will override this method, others will ignore second argument.
const ContextgetContext () const
SyncKind getCommunicationKind () const
 get the communication kind.
SyncKind getComputeKind () const
 get the compute kind.
void setCommunicationKind (SyncKind communicationKind)
 set the communication kind.
virtual void setComputeKind (SyncKind computeKind)
 set the compute kind.
void inheritAttributes (const Matrix &other)
 Inherit context and kind arguments from another matrix.
std::auto_ptr< Matrixcreate (const IndexType numRows, const IndexType numColumns) const
 Constructor creates a replicated matrix of same type as a given matrix.
std::auto_ptr< Matrixcreate (const IndexType size) const
 Constructor creates a distributed zero matrix of same type as a given matrix.
std::auto_ptr< Matrixcreate (DistributionPtr rowDistribution, DistributionPtr colDistribution) const
 Constructor creates a distributed zero matrix of same type as a given matrix.
std::auto_ptr< Matrixcreate (DistributionPtr distribution) const
 Constructor creates a distributed zero matrix of same type as a given matrix.
VectorPtr createDenseVector (DistributionPtr distribution, const Scalar value) const
 Constructor creates a distributed dense vector of same type as a given matrix.
const DistributiongetDistribution () const
DistributionPtr getDistributionPtr () const

Static Public Member Functions

static const char * typeName ()
 Getter for the type name of the class.

Data Fields

std::vector< boost::shared_ptr
< DenseStorage< ValueType > > > 
mData
 local data is allocated in chunks according to column distribution

Protected Member Functions

void setReplicatedMatrix (const IndexType numRows, const IndexType numColumns)
 Set the global/local size of replicated matrix.
void setDistributedMatrix (DistributionPtr distribution, DistributionPtr colDistribution)
 Set the global and local size of distributed matrix.
void checkSettings ()
void swapMatrix (Matrix &other)
void swap (Distributed &other)
void setDistributionPtr (DistributionPtr distributionPtr)

Protected Attributes

std::vector< PartitionIdmOwners
DistributionPtr mColDistribution
IndexType mNumRows
IndexType mNumColumns

Private Member Functions

void allocateData ()
 Allocate of storage for the column blocks.
template<typename otherT >
void copyDenseMatrix (const DenseMatrix< otherT > &other)
 Copy a dense matrix with different data type; inherits sizes and distributions.
template<typename OtherT >
void getDiagonalImpl (DenseVector< OtherT > &diagonal) const
 Optimized implementation for dense vectors as diagonal.
void redistributeRows (DistributionPtr rowDistribution)
void splitColumns (DistributionPtr colDistribution)
 Split the replicated columns into chunks according to the column distribution.
void getRow (DenseVector< ValueType > &row, const IndexType i) const
 LAMA_LOG_DECL_STATIC_LOGGER (logger)
void computeOwners ()
void invertCyclic ()
 Special implementation of invert in place for a cyclic distributed matrix.

Static Private Member Functions

static void joinColumnData (DenseStorage< ValueType > &result, const std::vector< boost::shared_ptr< DenseStorage< ValueType > > > &chunks, const std::vector< IndexType > &columnOwners)
 Join dense storage of column distributed data.
static void splitColumnData (std::vector< boost::shared_ptr< DenseStorage< ValueType > > > &chunks, const DenseStorage< ValueType > &columnData, const PartitionId numChunks, const std::vector< IndexType > &columnOwners)
 Split dense storage data according to a distribution into chunks.
static void localize (DenseStorage< ValueType > &local, const DenseStorage< ValueType > &global, const Distribution &rowDistribution)
 Restrict dense storage of a replicated matrix to its local part according to row distribution.

Private Attributes

LAMAArray< ValueTypemSendValues
LAMAArray< ValueTypemReceiveValues

Detailed Description

template<typename T>
class lama::DenseMatrix< T >

Class for dense matrices where rows are distributed among rows and columns are splitted according to a column distribution.

The local rows are splitted according to a column distribution into different blocks that are stored in a vector of shared pointers. A copy of this vector will not make deep copies of the blocks so default copy constructor and assignment operator must be overridden.


Member Typedef Documentation

template<typename T>
typedef boost::shared_ptr<DenseStorage<T> > lama::DenseMatrix< T >::DenseStoragePtr
typedef const Matrix& lama::Matrix::ExpressionMemberType [inherited]

ExpressionMemberType is the type that is used the template Expression to store a Vector.

template<typename T>
typedef T lama::DenseMatrix< T >::ValueType

Member Enumeration Documentation

enum lama::Matrix::MatrixKind [inherited]

MatrixKind describes if a matrix is dense or sparse.

Enumerator:
DENSE 

matrix kind for a dense matrix

SPARSE 

matrix kind for a sparse matrix

enum lama::Matrix::SyncKind [inherited]

SyncKind describes if the communication and computation should be done synchronously or asynchronously.

Enumerator:
ASYNCHRONOUS 
SYNCHRONOUS 

Constructor & Destructor Documentation

template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( )

Default constructor.

template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const IndexType  numRows,
const IndexType  numColumns 
)

Constructor of a replicated dense matrix.

References lama::DenseMatrix< T >::computeOwners(), and lama::DenseMatrix< T >::mData.

template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( DistributionPtr  rowDist,
DistributionPtr  colDist 
)

Constructor of a distributed dense matrix.

References lama::DenseMatrix< T >::allocateData(), and lama::DenseMatrix< T >::computeOwners().

template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const DenseMatrix< ValueType > &  other)

Overwrite default copy constructor so it uses other copy constructor.

Note: Default copy constructor would not make deep copies of the storages, so it must be overridden

References lama::DenseMatrix< T >::assign().

template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const Matrix other)

Construct a dense matrix from any other matrix that can be of a different type.

New dense matrix has the same size and the same distribution.

template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const Matrix other,
DistributionPtr  distribution,
DistributionPtr  colDistribution 
)

Construct a dense matrix from any other matrix with new distributions.

The following codes are equivalent:

      DenseMatrix dense( other, rowDist, colDist );
      // same as
      DenseMatrix dense( other );
      dense->redistribute( rowDist, colDist );

The constructor with distributions is more convenient and might be more efficient due to less memory allocations as less temporary data is needed.

template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const _MatrixStorage localData,
DistributionPtr  rowDist,
DistributionPtr  colDist 
)

Constructor of a dense matrix by local storage.

Parameters:
[in]localDatacontains local rows of the distributed matrix
[in]rowDistis distribution of localData
[in]colDistspecifies how to split columns of local rows

This constructor works also fine if localData is the full global matrix; in this case only local rows will be taken on this processor.

template<typename ValueType >
template<typename OtherValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const IndexType  numRows,
const IndexType  numColumns,
const IndexType  numNoneZeros,
const IndexType *const  ia,
const IndexType *const  ja,
const OtherValueType *const  values 
)

Creates a replicated dense matrix from the passed csr sparse matrix.

Parameters:
[in]numRowsthe number of rows of the matrix
[in]numColumnsthe number of columns of the matrix
[in]numNoneZerosthe number of none zeros of the matrix
[in]iarow pointer of the input csr sparse matrix
[in]jacolumn indexes of the input csr sparse matrix
[in]valuesthe none zero values of the input csr sparse matrix

References lama::DenseMatrix< T >::computeOwners(), lama::DenseMatrix< T >::mData, lama::Matrix::mNumColumns, and lama::Matrix::mNumRows.

template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const Expression< Expression< Scalar, Expression< Matrix, Matrix, Times >, Times >, Expression< Scalar, Matrix, Times >, Plus expression)
template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const Expression< Matrix, Matrix, Times expression)
template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const Expression< Scalar, Expression< Matrix, Matrix, Times >, Times expression)
template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const Expression< Scalar, Matrix, Times expression)
template<typename ValueType >
lama::DenseMatrix< ValueType >::DenseMatrix ( const std::string &  filename)

Constructor of a replicated dense matrix by reading the matrix data from a file.

Next releases will also support distributed/parallel I/O. In the meantime this constructor should be used with a following call of the redistribute method.

References lama::Matrix::setReplicatedMatrix().

template<typename ValueType >
lama::DenseMatrix< ValueType >::~DenseMatrix ( ) [virtual]

Member Function Documentation

template<typename ValueType >
void lama::DenseMatrix< ValueType >::allocate ( const IndexType  numRows,
const IndexType  numColumns 
) [virtual]

Reallocate this matrix to a replicated zero-matrix of the given shape.

Implements lama::Matrix.

References LAMA_ASSERT_ERROR, and lama::Matrix::setReplicatedMatrix().

Referenced by lama::SparseMatrix< T >::matrixTimesVectorNImpl().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::allocate ( DistributionPtr  rowDistribution,
DistributionPtr  colDistribution 
) [virtual]

Reallocate this matrix to a distributed zero-matrix by the given distributions.

Implements lama::Matrix.

References LAMA_THROWEXCEPTION, and lama::Matrix::setDistributedMatrix().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::allocateData ( ) [private]

Allocate of storage for the column blocks.

References LAMA_ASSERT_DEBUG, and LAMA_ASSERT_EQUAL_DEBUG.

Referenced by lama::DenseMatrix< T >::DenseMatrix().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::assign ( const Matrix other) [virtual]

This method assigns a matrix to this matrix with automatic conversion to the needed matrix type and the current row / column distribution of.

Parameters:
[in]othermust be matrix with same global sizes

Implements lama::Matrix.

References lama::Matrix::DENSE, lama::Scalar::DOUBLE, lama::Scalar::FLOAT, lama::Matrix::getColDistributionPtr(), lama::Distributed::getDistributionPtr(), lama::Matrix::getMatrixKind(), lama::Matrix::getValueType(), LAMA_THROWEXCEPTION, and lama::Matrix::setDistributedMatrix().

Referenced by lama::DenseMatrix< T >::DenseMatrix().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::assign ( const _MatrixStorage storage) [virtual]

Assign replicated storage for a replicated matrix.

Implements lama::Matrix.

References lama::_MatrixStorage::getNumColumns(), lama::_MatrixStorage::getNumRows(), and lama::Matrix::setReplicatedMatrix().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::assignLocal ( const _MatrixStorage other)
template<typename ValueType >
void lama::DenseMatrix< ValueType >::buildCSRData ( LAMAArray< IndexType > &  rowIA,
LAMAArray< IndexType > &  rowJA,
_LAMAArray rowValues 
) const [virtual]

Implementation of pure method for the dense storage format.

References lama::_LAMAArray::getValueType(), and LAMA_THROWEXCEPTION.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::buildLocalStorage ( _MatrixStorage storage) const [virtual]

Implementation of Matrix::buildLocalStorage.

Implements lama::Matrix.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::clear ( ) [virtual]

Implementation of pure method.

Implements lama::Matrix.

References lama::Matrix::setReplicatedMatrix().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::computeOwners ( ) [private]
template<typename ValueType >
std::auto_ptr< Matrix > lama::DenseMatrix< ValueType >::copy ( ) const [virtual]

Constructing a new object by the copy constructor.

Implements lama::Matrix.

template<typename T>
template<typename otherT >
void lama::DenseMatrix< T >::copyDenseMatrix ( const DenseMatrix< otherT > &  other) [private]

Copy a dense matrix with different data type; inherits sizes and distributions.

template<typename ValueType >
std::auto_ptr< Matrix > lama::DenseMatrix< ValueType >::create ( ) const [virtual]

Constructing a new object by the default constructor.

Implements lama::Matrix.

std::auto_ptr< Matrix > lama::Matrix::create ( const IndexType  numRows,
const IndexType  numColumns 
) const [inherited]

Constructor creates a replicated matrix of same type as a given matrix.

References lama::Matrix::create().

std::auto_ptr< Matrix > lama::Matrix::create ( const IndexType  size) const [inherited]

Constructor creates a distributed zero matrix of same type as a given matrix.

References lama::Matrix::create().

std::auto_ptr< Matrix > lama::Matrix::create ( DistributionPtr  rowDistribution,
DistributionPtr  colDistribution 
) const [inherited]

Constructor creates a distributed zero matrix of same type as a given matrix.

References lama::Matrix::create().

std::auto_ptr< Matrix > lama::Matrix::create ( DistributionPtr  distribution) const [inherited]

Constructor creates a distributed zero matrix of same type as a given matrix.

References lama::Matrix::create().

std::auto_ptr< _LAMAArray > lama::Matrix::createArray ( ) const [inherited]

This routine creates a LAMA array with the same value type as the matrix.

: returns an auto pointer to the LAMA array.

Same as _LAMAArray::create( this.getValueType() )

Value type is known only at runtime, so pointer to the base class is returned. Auto pointer indicates that calling routine takes ownership of the allocated array.

References lama::Matrix::create(), and lama::Matrix::getValueType().

VectorPtr lama::Matrix::createDenseVector ( DistributionPtr  distribution,
const Scalar  value 
) const [inherited]

Constructor creates a distributed dense vector of same type as a given matrix.

References lama::Scalar::DOUBLE, lama::Scalar::FLOAT, lama::Scalar::getValue(), lama::Matrix::getValueType(), and LAMA_THROWEXCEPTION.

Matrix::SyncKind lama::Matrix::getComputeKind ( ) const [inline, inherited]

get the compute kind.

Returns:
the compute kind.

References lama::Matrix::mComputeKind.

Referenced by lama::Matrix::inheritAttributes().

const Context& lama::Matrix::getContext ( ) const [inline, inherited]
template<typename T>
virtual ContextPtr lama::DenseMatrix< T >::getContextPtr ( ) const [inline, virtual]

Getter routine for the context.

Note: Only for SparseMatrix the context of the halo can be queried.

Implements lama::Matrix.

Referenced by lama::DenseMatrixOps::invertCyclic().

template<typename ValueType >
std::vector< typename DenseMatrix< ValueType >::DenseStoragePtr > & lama::DenseMatrix< ValueType >::getCyclicLocalValues ( )
template<typename ValueType >
const std::vector< typename DenseMatrix< ValueType >::DenseStoragePtr > & lama::DenseMatrix< ValueType >::getCyclicLocalValues ( ) const
template<typename ValueType >
void lama::DenseMatrix< ValueType >::getDiagonal ( Vector diagonal) const [virtual]

This method returns the diagonal.

Parameters:
[out]diagonalis the destination array

Calculations are dependent to the diagonal property.

Implements lama::Matrix.

References lama::Vector::assign(), lama::Scalar::DOUBLE, lama::Scalar::FLOAT, lama::Vector::getValueType(), and LAMA_THROWEXCEPTION.

template<typename T>
template<typename OtherT >
void lama::DenseMatrix< T >::getDiagonalImpl ( DenseVector< OtherT > &  diagonal) const [private]

Optimized implementation for dense vectors as diagonal.

template<typename T>
template<typename OtherValueType >
void lama::DenseMatrix< T >::getDiagonalImpl ( DenseVector< OtherValueType > &  diagonal) const
template<typename ValueType >
IndexType lama::DenseMatrix< ValueType >::getLocalNumColumns ( ) const [virtual]

Getter routine for the local number of rows and columns.

Implements lama::Matrix.

template<typename ValueType >
IndexType lama::DenseMatrix< ValueType >::getLocalNumRows ( ) const [virtual]

Getter routine for the local number of rows.

Implements lama::Matrix.

template<typename ValueType >
IndexType lama::DenseMatrix< ValueType >::getLocalNumValues ( ) const [virtual]

Implementation of Matrix::getLocalNumValues, getLocalNumRows, getLocalNumColumns.

Implements lama::Matrix.

template<typename ValueType >
const DenseStorage< ValueType > & lama::DenseMatrix< ValueType >::getLocalStorage ( ) const
template<typename ValueType >
DenseStorage< ValueType > & lama::DenseMatrix< ValueType >::getLocalStorage ( )
template<typename T>
Matrix::MatrixKind lama::DenseMatrix< T >::getMatrixKind ( ) const [inline, virtual]

Each derived matrix must give info about its kind (DENSE or SPARSE).

Implements lama::Matrix.

References lama::DENSE.

template<typename ValueType >
size_t lama::DenseMatrix< ValueType >::getMemoryUsage ( ) const [virtual]

getMemoryUsage returns the global memory that is allocated to hold this matrix.

getMemoryUsage returns the global memory that is allocated to hold this matrix. For a distributed matrix all partitions are summed together.

Returns:
the memory consumption of this matrix.

Implements lama::Matrix.

template<typename ValueType >
IndexType lama::DenseMatrix< ValueType >::getNumValues ( ) const [virtual]

Get the total number of non-zero values in the matrix.

An element is considered to be non-zero if its absolute value is greater equal than mEpsilon. Zero diagonal elements are also counted if this->hasDiagonalProperty() is given.

This routine does not count zero elements even if they are stored (e.g. for dense or dia storage data).

Returns:
the number of non-zero values in this matrix.

Implements lama::Matrix.

template<typename T>
const std::vector<PartitionId>& lama::DenseMatrix< T >::getOwners ( ) const [inline]
template<typename ValueType >
void lama::DenseMatrix< ValueType >::getRow ( Vector row,
const IndexType  globalRowIndex 
) const [virtual]

This method returns one row of the matrix.

Parameters:
[out]rowis a replicated vector with all values of the row

Note: the value type of the vector should be the same type as the matrix (otherwise conversion) and it should be a replicated vector (otherwise reallocation)

Unclear: should the distribution always be unchanged ?

Implements lama::Matrix.

References lama::Vector::getValueType(), LAMA_ASSERT_DEBUG, and LAMA_THROWEXCEPTION.

template<typename ValueType >
const char * lama::DenseMatrix< ValueType >::getTypeName ( ) const [virtual]

Implementation for Matrix::getTypeName()

Implements lama::Matrix.

template<typename ValueType >
Scalar lama::DenseMatrix< ValueType >::getValue ( lama::IndexType  i,
lama::IndexType  j 
) const [virtual]

returns a copy of the value at the passed global indexes.

Parameters:
[in]ithe global row index
[in]jthe global column index
Returns:
a copy of the value at the passed global position.

As this operation requires communication ins SPMD mode it can be very inefficient in some situations.

Implements lama::Matrix.

References lama::Distribution::getCommunicator(), lama::Distribution::getNumPartitions(), lama::Communicator::getRank(), lama::Distribution::global2local(), lama::Distribution::isLocal(), LAMA_ASSERT_ERROR, lama::nIndex, and lama::Communicator::sum().

template<typename ValueType >
Scalar::ScalarType lama::DenseMatrix< ValueType >::getValueType ( ) const [virtual]

Query the value type of the matrix elements, e.g.

DOUBLE or FLOAT.

Implements lama::Matrix.

template<typename ValueType >
bool lama::DenseMatrix< ValueType >::hasDiagonalProperty ( ) const [virtual]

hasDiagonalProperty returns the diagonalProperty of the local storage.

Returns:
if the diagonal property is full filled.

Implements lama::Matrix.

void lama::Matrix::inheritAttributes ( const Matrix other) [inherited]

Inherit context and kind arguments from another matrix.

This routine will also be used by copy constructors in base classes.

References lama::Matrix::getCommunicationKind(), lama::Matrix::getComputeKind(), lama::Matrix::getContextPtr(), lama::Matrix::setCommunicationKind(), lama::Matrix::setComputeKind(), and lama::Matrix::setContext().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::invert ( const Matrix other) [virtual]

Set this matrix with the inverse of another square matrix.

This matrix will have afterwards the same distribution as the other matrix.

Implements lama::Matrix.

References lama::Matrix::getColDistributionPtr(), lama::Distribution::getCommunicatorPtr(), lama::Distributed::getDistributionPtr(), lama::Matrix::getNumColumns(), lama::Matrix::getNumRows(), and LAMA_ASSERT_ERROR.

Referenced by lama::SparseMatrix< T >::invert().

template<typename T>
void lama::DenseMatrix< T >::invert ( ) [inline]

Invert in place.

References lama::DenseMatrix< T >::invert().

Referenced by lama::DenseMatrix< T >::invert().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::joinColumnData ( DenseStorage< ValueType > &  result,
const std::vector< boost::shared_ptr< DenseStorage< ValueType > > > &  chunks,
const std::vector< IndexType > &  columnOwners 
) [static, private]

Join dense storage of column distributed data.

Parameters:
[out]resultwill be the joined storage
[in]chunksis a vector of all chunks, one chunk for each partition
[in]columnOnwersvector with owner for each column

Note: the column distribution itself is given implicitly by the vector of owners

References lama::DenseStorageView< T >::getData(), lama::_MatrixStorage::getNumColumns(), lama::_MatrixStorage::getNumRows(), LAMA_ASSERT_EQUAL_ERROR, and LAMA_ASSERT_ERROR.

template<typename T>
lama::DenseMatrix< T >::LAMA_LOG_DECL_STATIC_LOGGER ( logger  ) [private]

Reimplemented from lama::Matrix.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::localize ( DenseStorage< ValueType > &  local,
const DenseStorage< ValueType > &  global,
const Distribution rowDistribution 
) [static, private]

Restrict dense storage of a replicated matrix to its local part according to row distribution.

Parameters:
[out]localis the local part of the dense storage for this partition
[in]globalis the replicated dense storage
[in]rowDistributiondistribution used to localize the dense storage.

References lama::DenseStorageView< T >::allocate(), lama::DenseStorageView< T >::getData(), lama::Distribution::getGlobalSize(), lama::Distribution::getLocalSize(), lama::_MatrixStorage::getNumColumns(), lama::_MatrixStorage::getNumRows(), LAMA_ASSERT_EQUAL_ERROR, and lama::Distribution::local2global().

Referenced by lama::DenseMatrix< T >::DenseMatrix().

void lama::Matrix::matrix2CSRGraph ( IndexType xadj,
IndexType adjncy,
IndexType vwgt,
CommunicatorPtr  comm,
const IndexType globalRowIndices = NULL,
IndexType vtxdist = NULL 
) const [virtual, inherited]

transformation from matrix type to a csr graph

transformation from matrix type to a csr graph, so that it (Par)Metis can work with it.

Parameters:
[out]xadjthe ia array of the csr graph
[out]adjncythe ja array of the csr graph

References LAMA_THROWEXCEPTION.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::matrixTimesScalar ( const Matrix other,
const Scalar  alpha 
) [virtual]

matrixTimesScalar computes this = alpha * other

Parameters:
[out]otherthe Matrix to mutliply
[in]alphathe Scalar of the expression

matrixTimesScalar computes this = alpha * other.

Implements lama::Matrix.

References lama::Scalar::getValue().

void lama::CRTPMatrix< DenseMatrix< T > , T >::matrixTimesVector ( Vector result,
const Scalar  alpha,
const Vector x,
const Scalar  beta,
const Vector y 
) const [inline, virtual, inherited]

matrixTimesVector computes result = alpha * this * x + beta * y

Parameters:
[out]resultthe Vector to store the result to
[in]alphathe Scalar alpha of the expression
[in]xthe Vector x of the expression
[in]betathe Scalar beta of the expression
[in]ythe Vector y of the expression

matrixTimesVector computes result = alpha * this * x + beta * y. If result == x or result == y new storage is allocated to store the result.

Implements lama::Matrix.

References lama::Matrix::getColDistribution(), lama::Distributed::getDistribution(), lama::Distributed::getDistributionPtr(), lama::Scalar::getValue(), LAMA_ASSERT, LAMA_ASSERT_EQUAL, LAMA_REGION, LAMA_THROWEXCEPTION, and lama::Vector::resize().

template<typename ValueType >
Scalar lama::DenseMatrix< ValueType >::maxDiffNorm ( const Matrix other) const [virtual]
template<typename ValueType >
ValueType lama::DenseMatrix< ValueType >::maxDiffNormImpl ( const DenseMatrix< ValueType > &  other) const

Get the maximal difference between two elements for dense matrices of same type.

References lama::Matrix::getColDistribution(), lama::Distributed::getDistribution(), LAMA_ASSERT_EQUAL_ERROR, lama::Communicator::max(), and lama::DenseMatrix< T >::mData.

Scalar lama::Matrix::operator() ( IndexType  i,
IndexType  j 
) const [inherited]

returns a copy of the value at the passed global indexes.

Parameters:
[in]ithe global row index
[in]jthe global column index
Returns:
a copy of the value at the passed global position.

As this operator requires communication ins SPMD mode it can be very inefficient in some situations.

References lama::Matrix::getValue().

template<typename ValueType >
DenseMatrix< ValueType > & lama::DenseMatrix< ValueType >::operator= ( const DenseMatrix< T > &  matrix)

Override default assignment operator needed to guarantee deep copy.

template<typename ValueType >
DenseMatrix< ValueType > & lama::DenseMatrix< ValueType >::operator= ( const Matrix other)

the assignment operator for matrix.

Parameters:
[in]otheris the input matrix.

The assignment operator will make a deep copy of the input matrix. Size and distributions are inherited, but there might be implicit conversions regarding storage format and/or value type of the matrix elements.

Reimplemented from lama::Matrix.

template<typename ValueType >
DenseMatrix< ValueType > & lama::DenseMatrix< ValueType >::operator= ( const Expression< Scalar, Matrix, Times exp)

the assignment operator for a scalar matrix multiplication.

Reimplemented from lama::Matrix.

References lama::Matrix::operator=().

template<typename ValueType >
DenseMatrix< ValueType > & lama::DenseMatrix< ValueType >::operator= ( const Expression< Matrix, Matrix, Times exp)

the assignment operator for a matrix matrix multiplication.

Reimplemented from lama::Matrix.

References lama::Matrix::operator=().

template<typename ValueType >
DenseMatrix< ValueType > & lama::DenseMatrix< ValueType >::operator= ( const Expression< Scalar, Expression< Matrix, Matrix, Times >, Times exp)

the assignment operator for a scalar matrix matrix multiplication.

the assignment operator for a matrix matrix multiplication.

Reimplemented from lama::Matrix.

References lama::Matrix::operator=().

template<typename ValueType >
DenseMatrix< ValueType > & lama::DenseMatrix< ValueType >::operator= ( const Expression< Expression< Scalar, Expression< Matrix, Matrix, Times >, Times >, Expression< Scalar, Matrix, Times >, Plus exp)

the assignment operator for a GEMM expression.

Reimplemented from lama::Matrix.

References lama::Matrix::operator=().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::prefetch ( ) const [virtual]

Prefetch matrix data to its 'preferred' context location.

Implements lama::Matrix.

Referenced by lama::DenseMatrix< T >::matrixTimesMatrix().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::prefetch ( lama::ContextPtr  loc) const
template<typename ValueType >
void lama::DenseMatrix< ValueType >::redistribute ( DistributionPtr  rowDistribution,
DistributionPtr  colDistribution 
) [virtual]

Implementation of pure method.

Implements lama::Matrix.

References LAMA_REGION, and lama::Matrix::mColDistribution.

Referenced by lama::DenseMatrixOps::invert().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::resetDiagonalProperty ( ) [virtual]

resetDiagonalProperty rechecks the storages for their diagonal property

Returns:
if the diagonal property is full filled.

Implements lama::Matrix.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::scale ( const Vector scaling) [virtual]

This method scales all values with a vector.

Parameters:
[in]valuesis the source array

row wise calculations

Implements lama::Matrix.

References lama::Scalar::DOUBLE, lama::Scalar::FLOAT, lama::DenseVector< T >::getLocalValues(), and LAMA_THROWEXCEPTION.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::scale ( const Scalar  scaling) [virtual]

This method scales all matrix values with a scalar.

Parameters:
[in]valueis the source value

Implements lama::Matrix.

References LAMA_THROWEXCEPTION.

void lama::Matrix::setCommunicationKind ( SyncKind  communicationKind) [inherited]

set the communication kind.

Parameters:
[in]communicationKindthe communication kind.

References lama::Matrix::mCommunicationKind.

Referenced by lama::Matrix::inheritAttributes().

void lama::Matrix::setComputeKind ( SyncKind  computeKind) [virtual, inherited]

set the compute kind.

Parameters:
[in]computeKindthe compute kind.

Reimplemented in lama::SparseMatrix< T >, and lama::SparseMatrix< ValueType >.

References lama::Matrix::mComputeKind.

Referenced by lama::Matrix::inheritAttributes().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::setContext ( const ContextPtr  context) [virtual]

specifies on which compute back end the matrix operations should take place.

Parameters:
[in]contextthe compute back to use for calculations with matrix

Note: Only for sparse matrices it is possible to specify separate locations for local and halo computations.

Implements lama::Matrix.

void lama::Matrix::setContext ( const ContextPtr  localContext,
const ContextPtr  haloContext 
) [virtual, inherited]

Only sparse matrices will override this method, others will ignore second argument.

Reimplemented in lama::SparseMatrix< T >, and lama::SparseMatrix< ValueType >.

References lama::Matrix::setContext().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::setCSRData ( const LAMAArray< IndexType > &  rowIA,
const LAMAArray< IndexType > &  rowJA,
const _LAMAArray rowValues,
DistributionPtr  rowDistribution,
DistributionPtr  colDistribution 
) [virtual]

Implementation of pure method.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::setCSRDataLocal ( const LAMAArray< IndexType > &  rowIA,
const LAMAArray< IndexType > &  rowJA,
const _LAMAArray rowValues 
) const

Local version of setCSRData .

References lama::_LAMAArray::size().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::setDiagonal ( const Vector diagonal) [virtual]

This method replaces the diagonal.

Parameters:
[in]diagonalis the source array

Calculations are dependent to the diagonal property

Implements lama::Matrix.

References lama::Scalar::DOUBLE, lama::Scalar::FLOAT, lama::DenseVector< T >::getLocalValues(), and LAMA_THROWEXCEPTION.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::setDiagonal ( const Scalar  scalar) [virtual]

This method replaces the diagonal by a diagonal value.

Parameters:
[in]scalaris the source value

Calculations are dependent to the diagonal property

Implements lama::Matrix.

References LAMA_THROWEXCEPTION.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::setIdentity ( ) [virtual]

Operator that sets the matrix to the identity matrix.

 void sub( ..., Matrix& a, ... )
 ...
 LAMA_ASSERT_EQUAL_DEBUG( a.getNumRows(), a.getNumColumns() );
 A.setIdentity();

Implements lama::Matrix.

References lama::Communicator::getRank(), lama::Communicator::getSize(), LAMA_ASSERT_EQUAL_DEBUG, and LAMA_THROWEXCEPTION.

template<typename ValueType >
template<typename OtherValueType >
void lama::DenseMatrix< ValueType >::setRawDenseData ( const IndexType  numRows,
const IndexType  numColumns,
const OtherValueType  values[],
const OtherValueType  eps = 0.0 
)

Set matrix with global dense data.

void lama::Matrix::setReplicatedMatrix ( const IndexType  numRows,
const IndexType  numColumns 
) [protected, inherited]

Set the global/local size of replicated matrix.

Parameters:
[in]numRowsnumber of rows, must be non-negative.
[in]numColumnsnumber of columns, must be non-negative.

References lama::Matrix::setDistributedMatrix().

Referenced by lama::DenseMatrix< T >::allocate(), lama::DenseMatrix< T >::assign(), lama::DenseMatrix< T >::clear(), and lama::DenseMatrix< T >::DenseMatrix().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::splitColumnData ( std::vector< boost::shared_ptr< DenseStorage< ValueType > > > &  chunks,
const DenseStorage< ValueType > &  columnData,
const PartitionId  numChunks,
const std::vector< IndexType > &  columnOwners 
) [static, private]

Split dense storage data according to a distribution into chunks.

Parameters:
[out]chunksvector of shared pointer to the new allocated chunks
[in]columnDatais the dense storage to split
[in]numChunksis the number of chunks, same as #partitions of distribution
[in]columnOnwersowner for each column

References lama::DenseStorageView< T >::getData(), lama::_MatrixStorage::getNumColumns(), lama::_MatrixStorage::getNumRows(), LAMA_ASSERT_DEBUG, and LAMA_ASSERT_EQUAL_ERROR.

Referenced by lama::DenseMatrix< T >::DenseMatrix().

template<typename ValueType >
void lama::DenseMatrix< ValueType >::splitColumns ( DistributionPtr  colDistribution) [private]

Split the replicated columns into chunks according to the column distribution.

References LAMA_ASSERT_EQUAL_ERROR, and lama::Matrix::setDistributedMatrix().

void lama::Distributed::swap ( Distributed other) [protected, inherited]
template<typename ValueType >
void lama::DenseMatrix< ValueType >::swap ( DenseMatrix< ValueType > &  other)

Swap will swap all member variables of the two dense matrices.

This operation might be useful in iteration loops where a dense matrix is updated each iteration. It is more convenient than a solution that is based on using pointers in the application.

References lama::DenseMatrix< T >::mData, lama::DenseMatrix< T >::mOwners, and lama::Matrix::swapMatrix().

template<typename T>
static const char* lama::DenseMatrix< T >::typeName ( ) [static]

Getter for the type name of the class.

template<>
const char * lama::DenseMatrix< float >::typeName ( )
template<>
const char * lama::DenseMatrix< double >::typeName ( )
template<typename ValueType >
void lama::DenseMatrix< ValueType >::wait ( ) const [virtual]

wait for a possibly running prefetch.

Implements lama::Matrix.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::writeAt ( std::ostream &  stream) const [virtual]

Write some information about this to the passed stream.

Parameters:
[out]streamthe stream to write to.

Reimplemented from lama::Matrix.

template<typename ValueType >
void lama::DenseMatrix< ValueType >::writeToFile ( const std::string &  fileName,
const File::FileType  fileType = File::BINARY,
const File::DataType  dataType = File::INTERNAL,
const File::IndexDataType  indexDataTypeIA = File::INT,
const File::IndexDataType  indexDataTypeJA = File::INT 
) const

Method writes dense matrix to a file.

Writing is only supported for a replicated matrix.

References lama::Communicator::getRank(), LAMA_THROWEXCEPTION, and lama::Communicator::synchronize().


Field Documentation

template<typename T>
std::vector<boost::shared_ptr<DenseStorage<ValueType> > > lama::DenseMatrix< T >::mData
template<typename T>
std::vector<PartitionId> lama::DenseMatrix< T >::mOwners [protected]
template<typename T>
LAMAArray<ValueType> lama::DenseMatrix< T >::mReceiveValues [mutable, private]
template<typename T>
LAMAArray<ValueType> lama::DenseMatrix< T >::mSendValues [mutable, private]

The documentation for this class was generated from the following files: