LAMA
/home/brandes/workspace/LAMA/src/lama/storage/SparseAssemblyStorage.hpp
Go to the documentation of this file.
00001 
00033 #ifndef LAMA_SPARSEASSEMBLYSTORAGE_HPP_
00034 #define LAMA_SPARSEASSEMBLYSTORAGE_HPP_
00035 
00036 // for dll_import
00037 #include <lama/config.hpp>
00038 
00039 // others
00040 #include <lama/storage/CRTPMatrixStorage.hpp>
00041 
00042 namespace lama
00043 {
00044 
00055 template<typename T>
00056 class LAMA_DLL_IMPORTEXPORT SparseAssemblyStorage: 
00057 
00058     public CRTPMatrixStorage<SparseAssemblyStorage<T>, T>
00059 {
00060 public:
00064     typedef T ValueType;
00065 
00068     static const char* typeName();
00069 
00073     SparseAssemblyStorage();
00074 
00081     SparseAssemblyStorage( const SparseAssemblyStorage<ValueType>& other );
00082 
00089     explicit SparseAssemblyStorage( const _MatrixStorage& other );
00090 
00105     SparseAssemblyStorage(
00106         const IndexType numRows,
00107         const IndexType numColumns,
00108         const IndexType numValuesPerRow = 10);
00109 
00113     virtual ~SparseAssemblyStorage();
00114 
00117     virtual void writeAt(std::ostream& stream) const;
00118 
00123     virtual void clear();
00124 
00127     virtual void purge();
00128 
00133     void swap( SparseAssemblyStorage<ValueType>& other );
00134 
00137     void allocate(const IndexType numRows, const IndexType numColumns );
00138 
00146     SparseAssemblyStorage<T>& operator=( const SparseAssemblyStorage<T>& other );
00147 
00150     SparseAssemblyStorage<T>& operator=( const _MatrixStorage& other );
00151 
00165     ValueType operator()( const IndexType i, const IndexType j ) const;
00166 
00167     ValueType getValue( const IndexType i, const IndexType j ) const
00168     {
00169         return (*this)( i, j );
00170     }
00171 
00174     virtual MatrixStorageFormat getFormat() const;
00175 
00178     virtual void setIdentity(const IndexType size);
00179 
00193     void set(const IndexType i,const IndexType j, const ValueType value);
00194 
00202     const std::vector<IndexType>& getJa(const IndexType i) const;
00203 
00204     std::vector<IndexType>& getJa(const IndexType i);
00205 
00213     const std::vector<ValueType>& getValues(const IndexType i) const;
00214 
00217     virtual void prefetch( const ContextPtr location ) const;
00218 
00221     void wait() const;
00222 
00228     IndexType getNumValues() const;
00229 
00232     virtual size_t getMemoryUsageImpl() const;
00233 
00245     void setRow(
00246         const IndexType i,
00247         const LAMAArrayConstView<IndexType>& ja,
00248         const LAMAArrayConstView<ValueType>& a);
00249 
00258     void fixDiagonalProperty(const IndexType i);
00259 
00268     void setNumColumns(const IndexType i);
00269 
00272     template<typename OtherType>
00273     void getRowImpl( LAMAArray<OtherType>& row, const IndexType i ) const;
00274 
00279     template<typename OtherValueType>
00280     void getDiagonalImpl( LAMAArray<OtherValueType>& diagonal ) const;
00281 
00286     template<typename OtherValueType>
00287     void setDiagonalImpl( const LAMAArray<OtherValueType>& diagonal );
00288 
00291     void setDiagonalImpl( const Scalar scalar );
00292 
00293     /******************************************************************
00294     *  Scaling of elements in a matrix                                *
00295     ******************************************************************/
00296 
00299     template<typename OtherType>
00300     void scaleImpl( const LAMAArray<OtherType>& values );
00301 
00304     void scaleImpl( const Scalar value );
00305 
00314     template<typename OtherValueType>
00315     void buildCSR( LAMAArray<IndexType>& ia,
00316                    LAMAArray<IndexType>* ja,
00317                    LAMAArray<OtherValueType>* values,
00318                    const ContextPtr /* loc */ ) const;
00319 
00331     template<typename OtherValueType>
00332     void setCSRDataImpl( const IndexType numRows,
00333                          const IndexType numColumns,
00334                          const IndexType numValues,
00335                          const LAMAArray<IndexType>& ia,
00336                          const LAMAArray<IndexType>& ja,
00337                          const LAMAArray<OtherValueType>& values,
00338                          const ContextPtr loc );
00339 
00345     void check( const char* msg ) const;
00346 
00347     virtual SparseAssemblyStorage* copy() const
00348     {
00349         return new SparseAssemblyStorage( *this );
00350     }
00351 
00354     virtual SparseAssemblyStorage* create() const
00355     {
00356         return new SparseAssemblyStorage();
00357     }
00358 
00359     using MatrixStorage<ValueType>::assign;
00360 
00361 private:
00362 
00363     void print() const;
00364 
00365     using CRTPMatrixStorage<SparseAssemblyStorage<T>, T>::mDiagonalProperty;
00366     using CRTPMatrixStorage<SparseAssemblyStorage<T>, T>::mNumRows;
00367     using CRTPMatrixStorage<SparseAssemblyStorage<T>, T>::mNumColumns;
00368 
00369     struct Row
00370     {
00371         std::vector<IndexType> ja;
00372         std::vector<ValueType> values;
00373         Row();
00374         Row( const Row& other );
00375         Row( const IndexType numValuesPerRow );
00376         Row& operator=( const Row& other );
00377         void reserve(const IndexType numValuesPerRow);
00378         void scale( const ValueType val );
00379     };
00380 
00381     std::vector<Row> mRows;
00382 
00383     IndexType mNumValues;  
00384 
00389     virtual bool checkDiagonalProperty() const;
00390 
00391     LAMA_LOG_DECL_STATIC_LOGGER( logger );
00392 };
00393 
00394 } //namespace lama
00395 
00396 #endif // LAMA_SPARSEASSEMBLYSTORAGE_HPP_