LAMA
/home/brandes/workspace/LAMA/src/lama/storage/ELLStorage.hpp
Go to the documentation of this file.
00001 
00034 #ifndef LAMA_ELLSTORAGE_HPP_
00035 #define LAMA_ELLSTORAGE_HPP_
00036 
00037 // for dll_import
00038 #include <lama/config.hpp>
00039 
00040 // base classes
00041 #include <lama/storage/CRTPMatrixStorage.hpp>
00042 
00043 namespace lama
00044 {
00045 
00065 template<typename T>
00066 class LAMA_DLL_IMPORTEXPORT ELLStorage : public CRTPMatrixStorage<ELLStorage<T>, T>
00067 {
00068 public:
00069 
00070     typedef T ValueType;  
00071 
00074     static const char* typeName();
00075 
00079     ELLStorage();
00080 
00087     ELLStorage( const IndexType numRows, const IndexType numColumns, const ContextType con = Context::Host );
00088 
00091     ELLStorage( const IndexType numRows, 
00092                 const IndexType numColumns,
00093                 const IndexType numValuesPerRows,
00094                 const LAMAArray<IndexType>& ia, 
00095                 const LAMAArray<IndexType>& ja, 
00096                 const LAMAArray<ValueType>& values  );
00097 
00100     ELLStorage( const ELLStorage<ValueType>& other );
00101 
00102     explicit ELLStorage( const _MatrixStorage& other ) {  assign( other ); }
00103 
00106     ELLStorage( const _MatrixStorage& other, const ContextPtr context )
00107             {  setContext(context); assign( other ); }
00108 
00111     virtual ~ELLStorage();
00112 
00113     ELLStorage<ValueType>& operator=( const _MatrixStorage& other)
00114     {  assign( other );  return *this; }
00115 
00118     virtual ELLStorage* copy() const;
00119 
00122     virtual ELLStorage* create() const;
00123 
00127     virtual void clear();
00128 
00134     void check( const char* msg ) const;
00135 
00138     void allocate( const IndexType numRows, const IndexType numColumns );
00139 
00142     virtual MatrixStorageFormat getFormat() const;
00143 
00146     virtual void purge();
00147 
00150     virtual void setIdentity( const IndexType size );
00151 
00160     template<typename OtherValueType>
00161     void buildCSR( LAMAArray<IndexType>& ia,
00162                    LAMAArray<IndexType>* ja,
00163                    LAMAArray<OtherValueType>* values,
00164                    const ContextPtr /* loc */ ) const;
00165 
00176     template<typename OtherValueType>
00177     void setCSRDataImpl( const IndexType numRows,
00178                          const IndexType numColumns,
00179                          const IndexType numValues,
00180                          const LAMAArray<IndexType>& ia,
00181                          const LAMAArray<IndexType>& ja,
00182                          const LAMAArray<OtherValueType>& values,
00183                          const ContextPtr loc );
00184 
00187     virtual void writeAt( std::ostream& stream ) const;
00188 
00191     const LAMAArray<IndexType>& getIA() const;
00192 
00193     const LAMAArray<IndexType>& getJA() const;
00194 
00195     const LAMAArray<ValueType>& getValues() const;
00196 
00199     virtual IndexType getNumValues() const;
00200 
00203     IndexType getNumValuesPerRow() const;
00204 
00207     template<typename OtherType>
00208     void getRowImpl( LAMAArray<OtherType>& row, const IndexType i ) const;
00209 
00216     template<typename OtherType>
00217     void getDiagonalImpl( LAMAArray<OtherType>& diagonal ) const;
00218 
00225     template<typename OtherType>
00226     void setDiagonalImpl( const LAMAArray<OtherType>& diagonal );
00227 
00234     void setDiagonalImpl( const Scalar scalar );
00235 
00236     /******************************************************************
00237     *  Scaling of elements in a matrix                                *
00238     ******************************************************************/
00239 
00242     template<typename OtherType>
00243     void scaleImpl( const LAMAArray<OtherType>& values );
00244 
00247     void scaleImpl( const Scalar value );
00248 
00257     ValueType getValue( IndexType i, IndexType j ) const;
00258 
00261     void prefetch( const ContextPtr location ) const;
00262 
00265     void wait() const;
00266 
00269     virtual void matrixTimesVector(
00270         LAMAArrayView<ValueType> result,
00271         const ValueType alpha, const LAMAArrayConstView<ValueType> x,
00272         const ValueType beta, const LAMAArrayConstView<ValueType> y ) const;
00273 
00276     virtual std::auto_ptr<SyncToken> matrixTimesVectorAsync(
00277         LAMAArrayView<ValueType> result,
00278         const ValueType alpha, const LAMAArrayConstView<ValueType> x,
00279         const ValueType beta, const LAMAArrayConstView<ValueType> y ) const;
00280 
00283     virtual void jacobiIterate(
00284         LAMAArrayView<ValueType> solution, const LAMAArrayConstView<ValueType> oldSolution,
00285         const LAMAArrayConstView<ValueType> rhs, const ValueType omega) const;
00286 
00289     virtual void jacobiIterateHalo(
00290         LAMAArrayView<ValueType> localSolution,
00291         const MatrixStorage<ValueType>& localStorage,
00292         const LAMAArrayConstView<ValueType> haloOldSolution,
00293         const ValueType omega ) const;
00294 
00297     virtual void matrixTimesMatrix(
00298         const ValueType alpha,
00299         const MatrixStorage<ValueType>& a,
00300         const MatrixStorage<ValueType>& b,
00301         const ValueType beta,
00302         const MatrixStorage<ValueType>& c );
00303 
00315     void compress( const ValueType eps = 0.0 );
00316 
00323     void swap( ELLStorage<ValueType>& other );
00324 
00325     virtual size_t getMemoryUsageImpl() const;
00326 
00327     using MatrixStorage<ValueType>::mNumRows;
00328     using MatrixStorage<ValueType>::mNumColumns;
00329     using MatrixStorage<ValueType>::mDiagonalProperty;
00330     using MatrixStorage<ValueType>::mRowIndexes;
00331     using MatrixStorage<ValueType>::mCompressThreshold;
00332 
00333     using MatrixStorage<ValueType>::assign;
00334     using MatrixStorage<ValueType>::prefetch;
00335     using MatrixStorage<ValueType>::getContextPtr;
00336     using MatrixStorage<ValueType>::setContext;
00337 
00340     void print() const;
00341 
00342 private:
00343 
00344     IndexType mNumValuesPerRow;   
00345 
00346     LAMAArray<IndexType> mIa;     
00347     LAMAArray<IndexType> mJa;     
00348     LAMAArray<ValueType> mValues; 
00349 
00352     inline IndexType ellindex( const IndexType i, const IndexType jj ) const { return jj * mNumRows + i; }
00353 
00354     // Alternative addressing row-wise 
00355     // inline IndexType ellindex( const IndexType i, const IndexType jj ) const { return i * mNumValuesPerRow + jj; }
00356 
00361     virtual bool checkDiagonalProperty() const;
00362 
00368     void buildRowIndexes( const ContextPtr loc );
00369 
00370     LAMA_LOG_DECL_STATIC_LOGGER( logger );  
00371 
00373     void matrixTimesMatrixELL( const ValueType alpha,
00374                                const ELLStorage<ValueType>& a,
00375                                const ELLStorage<ValueType>& b );
00376 
00378     void matrixAddMatrixELL( const ValueType alpha,
00379                              const ELLStorage<ValueType>& a,
00380                              const ValueType beta,
00381                              const ELLStorage<ValueType>& b );
00382 };
00383 
00384 } // namespace lama
00385 
00386 #endif // LAMA_ELLSTORAGE_HPP_