LAMA
lama::_MatrixStorage Class Reference

The class _MatrixStorage is the base class for all matrix storage classes supported by LAMA. More...

#include <MatrixStorage.hpp>

Inheritance diagram for lama::_MatrixStorage:

Public Member Functions

 _MatrixStorage (const IndexType numRows, const IndexType numColumns)
 Constructor for storage of a matrix of size numRows x numColumns.
 _MatrixStorage ()
 Default constructor.
virtual ~_MatrixStorage ()
virtual const char * getTypeName () const =0
 This method returns the type name of a matrix storage, e.g.
void init (const IndexType numRows, const IndexType numColumns)
 Initialization of base class due to a resize.
virtual Scalar::ScalarType getValueType () const =0
 Objects of this class should give info about their value type.
virtual void clear ()=0
 Clear the matrix storage, resets size to 0 x 0.
virtual void purge ()=0
 Purge clears the matrix and even frees the allocated memory.
virtual void allocate (const IndexType numRows, const IndexType numColumns)=0
 This method allocates new matrix storage for the matrix.
void setContext (ContextPtr context)
 Set the preferred context for the matrix storage.
ContextPtr getContextPtr () const
 Getter for the preferred context of the storage data, returns pointer.
const ContextgetContext () const
 Getter for the preferred context of the storage data.
virtual void prefetch (const ContextPtr context) const =0
 Pure method that prefetches storage data into a given context.
void prefetch () const
 Method that prefetches storage data to its preferred location.
virtual void wait () const =0
 Will wait for all outstanding asynchronous data transfers.
void setCompressThreshold (float ratio)
 Allow for additional row compression.
IndexType getNumRows () const
IndexType getNumColumns () const
virtual void writeAt (std::ostream &stream) const
 Writes some Information about this to the passed stream.
void resetDiagonalProperty ()
bool hasDiagonalProperty () const
virtual MatrixStorageFormat getFormat () const =0
virtual void setIdentity (const IndexType n)=0
 This method sets storage for the identity matrix.
virtual void getRow (_LAMAArray &row, const IndexType i) const =0
 This method returns the i-th row of the matrix.
virtual void getDiagonal (_LAMAArray &diagonal) const =0
 This method returns the diagonal of the matrix.
virtual void setDiagonal (const _LAMAArray &diagonal)=0
 This method sets the diagonal of a matrix storage.
virtual void setDiagonal (const Scalar value)=0
virtual void scale (const Scalar value)=0
 This method scales all matrix values with a scalar.
virtual void scale (const _LAMAArray &values)=0
 This method scales each row of a matrix with a separate value.
virtual void localize (const _MatrixStorage &global, const Distribution &rowDist)
 This operation localizes the matrix storage of a full matrix to the part that is owned by this processor.
virtual IndexType getNumValues () const
 Get the total number of non-zero values in the matrix.
const LAMAArray< IndexType > & getRowIndexes () const
virtual void buildCSRSizes (LAMAArray< IndexType > &csrIA) const =0
 Get the number of entries in each row.
virtual void buildCSRData (LAMAArray< IndexType > &csrIA, LAMAArray< IndexType > &csrJA, _LAMAArray &csrValues) const =0
 Get the matrix data of the storage in CSR format.
virtual void setCSRData (const IndexType numRows, const IndexType numColumns, const IndexType numValues, const LAMAArray< IndexType > &csrIA, const LAMAArray< IndexType > &csrJA, const _LAMAArray &csrValues)=0
 Each storage class must provide a routine to set CSR storage data.
virtual void assign (const _MatrixStorage &other)=0
 Assign of matrix storage with any format or value type.
virtual void copyTo (_MatrixStorage &other) const =0
 The opposite routine to assign, for convenience as the other way around is sometimes more efficient.
_MatrixStorageoperator= (const _MatrixStorage &other)
 Override default assignment operator.
size_t getMemoryUsage () const
 Returns the number of bytes needed for the current matrix.
virtual void check (const char *msg) const =0
virtual _MatrixStoragecreate () const =0
 Each matrix storage must provide a routine that creates a new object of the same matrix type (same format and same value type).
virtual _MatrixStoragecopy () const =0
 Each matrix storage must provide a routine that makes a new copy of the input matrix (same format and same value type).

Static Public Member Functions

static void offsets2sizes (LAMAArray< IndexType > &offsets)
 Help routines to convert arrays with sizes to offsets and vice versa.
static void offsets2sizes (LAMAArray< IndexType > &sizes, const LAMAArray< IndexType > &offsets)
static IndexType sizes2offsets (LAMAArray< IndexType > &sizes)
 Utitily to compute the offset array from a sizes array.

Protected Member Functions

void swap (_MatrixStorage &other)
 Swaps this with other.
virtual void _assignTranspose (const _MatrixStorage &other)
virtual void _assign (const _MatrixStorage &other)
virtual size_t getMemoryUsageImpl () const =0
 Returns the number of bytes needed for the current matrix.
 LAMA_LOG_DECL_STATIC_LOGGER (logger)
 logger for this matrix format

Protected Attributes

IndexType mNumRows
IndexType mNumColumns
LAMAArray< IndexTypemRowIndexes
 used in case of sparse representation of ia
float mCompressThreshold
 ratio at which compression is done, 0 for never, 1 for always
bool mDiagonalProperty
 if true, diagonal elements are always stored at first position in each row
ContextPtr mContext
 preferred context for the storage

Private Member Functions

virtual bool checkDiagonalProperty () const =0
 checkDiagonalProperty checks if the diagonal property of this is full filled.

Detailed Description

The class _MatrixStorage is the base class for all matrix storage classes supported by LAMA.

In contratry to a matrix a matrix storage is never distributed. It contains local parts of a distributed matrix that are typically submatrices.

This base class is also common for all supported value types for matrix elements.

Note: Default copy constructor and assignment operator can be used.

Each matrix storage has a context that will be taken as the preferred location where the matrix data resides and where operations on the matrix storage should take place.


Constructor & Destructor Documentation

lama::_MatrixStorage::_MatrixStorage ( const IndexType  numRows,
const IndexType  numColumns 
)

Constructor for storage of a matrix of size numRows x numColumns.

References init(), mNumColumns, and mNumRows.

Default constructor.

References init().


Member Function Documentation

virtual void lama::_MatrixStorage::allocate ( const IndexType  numRows,
const IndexType  numColumns 
) [pure virtual]

This method allocates new matrix storage for the matrix.

The matrix contains only zero elements.

Note: This method contains an implicit clear, but not a purge. So allocation of a much smaller matrix compared to the existing one might result in some waste of memory.

Implemented in lama::CSRStorage< T >, lama::DenseStorageView< T >, lama::JDSStorage< T >, lama::DIAStorage< T >, lama::COOStorage< T >, lama::ELLStorage< T >, and lama::SparseAssemblyStorage< T >.

Referenced by lama::MatrixStorage< T >::splitHalo().

virtual void lama::_MatrixStorage::assign ( const _MatrixStorage other) [pure virtual]

Assign of matrix storage with any format or value type.

Format conversion and type conversion is done implicitly. Derived clauses might override this method with more efficient solutions.

Parameters:
[in]otheris the matrix storage to be assigned

Implemented in lama::MatrixStorage< T >, lama::MatrixStorage< ValueType >, lama::CSRStorage< T >, and lama::DenseStorageView< T >.

Referenced by operator=().

virtual void lama::_MatrixStorage::buildCSRData ( LAMAArray< IndexType > &  csrIA,
LAMAArray< IndexType > &  csrJA,
_LAMAArray csrValues 
) const [pure virtual]

Get the matrix data of the storage in CSR format.

Parameters:
[out]csrIAoffset array for rows, csrIA.size() == numRows + 1
[out]csrJAcolumn indexes, csrJA.size() == csrIA[ csrIA.size() ]
[out]csrValuesare the non-zero matrix values, csrJA.size() == csrValues.size()

The csr data will have the diagonal property if this->hasDiagonalProperty() is true.

Note: This routine supports also type conversion between different value types.

     DenseStorage<double> dense( ... )
     LAMAArray<IndexType> ia, ja;
     LAMAArray<float> values;
     // get non-zero values of dense matrix as float values
     dense.buildCSRData( ia, ja, values );  

This routine must be provided by each matrix storage format.

Implemented in lama::CRTPMatrixStorage< Derived, ValueType >, lama::CRTPMatrixStorage< COOStorage< T >, T >, lama::CRTPMatrixStorage< ELLStorage< T >, T >, lama::CRTPMatrixStorage< JDSStorage< T >, T >, lama::CRTPMatrixStorage< SparseAssemblyStorage< T >, T >, lama::CRTPMatrixStorage< DenseStorageView< T >, T >, lama::CRTPMatrixStorage< DIAStorage< T >, T >, and lama::CRTPMatrixStorage< CSRStorage< T >, T >.

Referenced by lama::CSRStorage< T >::assign(), lama::MatrixStorage< T >::assign(), lama::DenseMatrix< T >::assignLocal(), lama::MatrixStorage< T >::exchangeHalo(), lama::MatrixStorage< T >::joinHalo(), lama::MatrixStorage< T >::localize(), and lama::MatrixStorage< T >::redistribute().

virtual void lama::_MatrixStorage::buildCSRSizes ( LAMAArray< IndexType > &  csrIA) const [pure virtual]

Get the number of entries in each row.

Parameters:
[out]csrIAsize array for rows, csrIA.size() == numRows

If this->hasDiagonalProperty() is true, diagonal elements are also counted.

     DenseStorage<double> dense( ... )
     LAMAArray<IndexType> ia;
     dense.buildCSRSizes( ia );

This routine must be provided by each matrix storage format.

Implemented in lama::CRTPMatrixStorage< Derived, ValueType >, lama::CRTPMatrixStorage< COOStorage< T >, T >, lama::CRTPMatrixStorage< ELLStorage< T >, T >, lama::CRTPMatrixStorage< JDSStorage< T >, T >, lama::CRTPMatrixStorage< SparseAssemblyStorage< T >, T >, lama::CRTPMatrixStorage< DenseStorageView< T >, T >, lama::CRTPMatrixStorage< DIAStorage< T >, T >, and lama::CRTPMatrixStorage< CSRStorage< T >, T >.

Referenced by getNumValues().

virtual bool lama::_MatrixStorage::checkDiagonalProperty ( ) const [private, pure virtual]

checkDiagonalProperty checks if the diagonal property of this is full filled.

Returns:
true if the diagonal property is fulfilled for the matrix data

Implemented in lama::CSRStorage< T >, lama::SparseAssemblyStorage< T >, lama::ELLStorage< T >, lama::DIAStorage< T >, lama::JDSStorage< T >, lama::COOStorage< T >, and lama::DenseStorageView< T >.

Referenced by resetDiagonalProperty().

virtual void lama::_MatrixStorage::clear ( ) [pure virtual]

Clear the matrix storage, resets size to 0 x 0.

Clearing of matrix storage will not free allocated data, so resize to the original size is a cheap operation.

Implemented in lama::DenseStorageView< T >, lama::JDSStorage< T >, lama::ELLStorage< T >, lama::CSRStorage< T >, lama::SparseAssemblyStorage< T >, lama::DIAStorage< T >, and lama::COOStorage< T >.

virtual _MatrixStorage* lama::_MatrixStorage::copy ( ) const [pure virtual]

Each matrix storage must provide a routine that makes a new copy of the input matrix (same format and same value type).

The implementations in derived classes should use covariant return types to allow polymorphic creation of objects.

Note: as shared_ptr cannot be used for for covariant return types this routine returns directly a new created object that should be wrapped as a shared pointer at calling site.

Implemented in lama::MatrixStorage< T >, lama::MatrixStorage< ValueType >, lama::SparseAssemblyStorage< T >, lama::COOStorage< T >, lama::CSRStorage< T >, lama::JDSStorage< T >, lama::ELLStorage< T >, lama::DIAStorage< T >, and lama::DenseStorageView< T >.

virtual void lama::_MatrixStorage::copyTo ( _MatrixStorage other) const [pure virtual]

The opposite routine to assign, for convenience as the other way around is sometimes more efficient.

Implemented in lama::MatrixStorage< T >, lama::MatrixStorage< ValueType >, and lama::CSRStorage< T >.

Referenced by lama::MatrixStorage< T >::assign().

virtual _MatrixStorage* lama::_MatrixStorage::create ( ) const [pure virtual]

Each matrix storage must provide a routine that creates a new object of the same matrix type (same format and same value type).

The implementations in derived classes should use covariant return types to allow polymorphic creation of objects.

Note: as shared_ptr cannot be used for for covariant return types this routine returns directly a new created object that should be wrapped as a shared pointer at calling site.

Implemented in lama::MatrixStorage< T >, lama::MatrixStorage< ValueType >, lama::SparseAssemblyStorage< T >, lama::COOStorage< T >, lama::CSRStorage< T >, lama::JDSStorage< T >, lama::ELLStorage< T >, lama::DIAStorage< T >, and lama::DenseStorageView< T >.

const Context& lama::_MatrixStorage::getContext ( ) const [inline]

Getter for the preferred context of the storage data.

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

Getter for the preferred context of the storage data, returns pointer.

Referenced by lama::SpecializedJacobi::iterateTyped(), and lama::JDSStorage< T >::JDSStorage().

Returns the number of bytes needed for the current matrix.

Note: This routine does not tell how many memory is really allocated. Storage data might be allocated on more than one device. Furthermore, it is possible that arrays have more memory reserved than needed for its current size.

References getMemoryUsageImpl(), mRowIndexes, and lama::_LAMAArray::size().

virtual size_t lama::_MatrixStorage::getMemoryUsageImpl ( ) const [protected, pure virtual]

Returns the number of bytes needed for the current matrix.

This pure function must be implemented by each derived class. Relevant for the number of bytes is the current size of the used (LAMA) arrays.

Note: This routine does not tell how many memory is really allocated. Storage data might be allocated on more than one device. Furthermore, it is possible that arrays have more memory reserved than needed for its current size.

Implemented in lama::CSRStorage< T >, lama::ELLStorage< T >, lama::DIAStorage< T >, lama::COOStorage< T >, lama::JDSStorage< T >, lama::DenseStorageView< T >, and lama::SparseAssemblyStorage< T >.

Referenced by getMemoryUsage().

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

Returns:
total number of non-zero values

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).

This routine gives exactly the same number of elements that will be the size of the ja and values array when calling buildCSRData.

The default implementation uses the routine buildCSRSizes, but derived classes should override it if they can do it more efficiently.

Reimplemented in lama::SparseAssemblyStorage< T >, lama::JDSStorage< T >, lama::CSRStorage< T >, lama::COOStorage< T >, lama::ELLStorage< T >, and lama::DenseStorageView< T >.

References buildCSRSizes(), lama::ReadAccess< T >::get(), mNumRows, and lama::OpenMPUtils::sum().

References mRowIndexes.

void lama::_MatrixStorage::localize ( const _MatrixStorage global,
const Distribution rowDist 
) [virtual]

This operation localizes the matrix storage of a full matrix to the part that is owned by this processor.

This means that only the owned rows of the matrix will be kept.

Notes:

* routine can also be used if global is aliased with this matrix. * this routine is the same as an assign in case of a replicated distribution

References lama::Distribution::getGlobalSize(), getNumColumns(), getNumRows(), LAMA_ASSERT_EQUAL_ERROR, and LAMA_THROWEXCEPTION.

void lama::_MatrixStorage::offsets2sizes ( LAMAArray< IndexType > &  offsets) [static]

Help routines to convert arrays with sizes to offsets and vice versa.

References lama::WriteAccess< T >::resize(), and lama::_LAMAArray::size().

Referenced by offsets2sizes().

virtual void lama::_MatrixStorage::prefetch ( const ContextPtr  context) const [pure virtual]
void lama::_MatrixStorage::prefetch ( ) const [inline]

Method that prefetches storage data to its preferred location.

References prefetch().

Referenced by prefetch().

virtual void lama::_MatrixStorage::purge ( ) [pure virtual]

Allow for additional row compression.

References LAMA_THROWEXCEPTION, and mCompressThreshold.

Referenced by lama::MatrixStorage< T >::splitHalo().

Set the preferred context for the matrix storage.

Parameters:
[in]contextspecifies where the storage should be allocated and where operations should be done

References mContext.

Referenced by lama::CSRStorage< T >::CSRStorage(), lama::DenseStorage< T >::DenseStorage(), and lama::ELLStorage< T >::ELLStorage().

virtual void lama::_MatrixStorage::setCSRData ( const IndexType  numRows,
const IndexType  numColumns,
const IndexType  numValues,
const LAMAArray< IndexType > &  csrIA,
const LAMAArray< IndexType > &  csrJA,
const _LAMAArray csrValues 
) [pure virtual]

Each storage class must provide a routine to set CSR storage data.

Parameters:
numRowsnumber of rows
numColumnsnumber of columns
numValuesnumber of non-zero values
csrIAoffset array ia for column indexes, size is numRows + 1
csrJAare the column indexes of matrix entries, size is numValues
csrValuesare the values of matrix entries, size is numValues

Implemented in lama::CRTPMatrixStorage< Derived, ValueType >, lama::CRTPMatrixStorage< COOStorage< T >, T >, lama::CRTPMatrixStorage< ELLStorage< T >, T >, lama::CRTPMatrixStorage< JDSStorage< T >, T >, lama::CRTPMatrixStorage< SparseAssemblyStorage< T >, T >, lama::CRTPMatrixStorage< DenseStorageView< T >, T >, lama::CRTPMatrixStorage< DIAStorage< T >, T >, and lama::CRTPMatrixStorage< CSRStorage< T >, T >.

Referenced by lama::CSRStorage< T >::copyTo(), lama::MatrixStorage< T >::copyTo(), and lama::MatrixStorage< T >::splitHalo().

virtual void lama::_MatrixStorage::setIdentity ( const IndexType  n) [pure virtual]

This method sets storage for the identity matrix.

Parameters:
in)n is the size of the square matrix

Implemented in lama::SparseAssemblyStorage< T >, lama::DIAStorage< T >, lama::JDSStorage< T >, lama::CSRStorage< T >, lama::ELLStorage< T >, lama::COOStorage< T >, and lama::DenseStorageView< T >.

Utitily to compute the offset array from a sizes array.

References lama::WriteAccess< T >::resize(), and lama::_LAMAArray::size().

Referenced by lama::SparseAssemblyStorage< T >::buildCSR().

void lama::_MatrixStorage::swap ( _MatrixStorage other) [protected]

Swaps this with other.

swap is protected to avoid accidently wrong swaps of base classes which do not implement their own swap.

Parameters:
[in,out]otherthe _MatrixStorage to swap this with

References mCompressThreshold, mContext, mDiagonalProperty, mNumColumns, mNumRows, mRowIndexes, and lama::LAMAArray< T >::swap().

virtual void lama::_MatrixStorage::wait ( ) const [pure virtual]
void lama::_MatrixStorage::writeAt ( std::ostream &  stream) const [virtual]

Writes some Information about this to the passed stream.

If a deriving class does not overrides writeAt, typeid(this).name() is written to stream.

Parameters:
[out]streamthe stream to write to.

Reimplemented from Printable.

Reimplemented in lama::DIAStorage< T >, lama::JDSStorage< T >, lama::CSRStorage< T >, lama::ELLStorage< T >, lama::COOStorage< T >, lama::DenseStorageView< T >, and lama::SparseAssemblyStorage< T >.

References mNumColumns, and mNumRows.


Field Documentation

ratio at which compression is done, 0 for never, 1 for always

Referenced by _assign(), _assignTranspose(), init(), setCompressThreshold(), and swap().

preferred context for the storage

Referenced by setContext(), and swap().

used in case of sparse representation of ia

Referenced by _assign(), _assignTranspose(), getMemoryUsage(), getRowIndexes(), and swap().


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