LAMA
|
00001 00034 #ifndef LAMA_COOSTORAGE_HPP_ 00035 #define LAMA_COOSTORAGE_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 COOStorage: public CRTPMatrixStorage<COOStorage<T>, T> 00067 { 00068 public: 00069 00070 typedef T ValueType; 00071 00074 static const char* typeName(); 00075 00082 COOStorage(const IndexType numRows, const IndexType numColumns); 00083 00087 COOStorage(const IndexType numRows, const IndexType numColumns, 00088 const LAMAArray<IndexType>& ia, 00089 const LAMAArray<IndexType>& ja, 00090 const LAMAArray<ValueType>& values ); 00091 00094 COOStorage(); 00095 00098 COOStorage( const COOStorage<ValueType>& other ); 00099 00102 explicit COOStorage( const _MatrixStorage& other ) { assign(other); } 00103 00106 COOStorage( const _MatrixStorage& other, const ContextPtr context ); 00107 //{ setContext(context); assign( other ); } 00108 00111 COOStorage<ValueType>& operator=( const COOStorage<ValueType>& other) 00112 { assign( other ); return *this; } 00113 00114 COOStorage<ValueType>& operator=( const _MatrixStorage& other) 00115 { assign( other ); return *this; } 00116 00117 virtual void clear(); 00118 00121 virtual ~COOStorage(); 00122 00127 void check( const char* msg ) const; 00128 00131 virtual MatrixStorageFormat getFormat() const; 00132 00141 void allocate(const IndexType numRows, const IndexType numColumns); 00142 00145 virtual void purge(); 00146 00149 virtual void setIdentity( const IndexType size ); 00150 00153 template<typename OtherValueType> 00154 void buildCSR( LAMAArray<IndexType>& ia, 00155 LAMAArray<IndexType>* ja, 00156 LAMAArray<OtherValueType>* values, 00157 const ContextPtr /* loc */ ) const; 00158 00170 template<typename OtherValueType> 00171 void setCSRDataImpl( const IndexType numRows, 00172 const IndexType numColumns, 00173 const IndexType numValues, 00174 const LAMAArray<IndexType>& ia, 00175 const LAMAArray<IndexType>& ja, 00176 const LAMAArray<OtherValueType>& values, 00177 const ContextPtr loc ); 00178 00181 virtual void writeAt(std::ostream& stream) const; 00182 00193 const LAMAArray<IndexType>& getIA() const; 00194 00195 const LAMAArray<IndexType>& getJA() const; 00196 00197 const LAMAArray<ValueType>& getValues() const; 00198 00201 virtual IndexType getNumValues() const; 00202 00205 template<typename OtherType> 00206 void getRowImpl( LAMAArray<OtherType>& row, const IndexType i ) const; 00207 00214 template<typename OtherType> 00215 void getDiagonalImpl( LAMAArray<OtherType>& diagonal ) const; 00216 00219 template<typename OtherType> 00220 void setDiagonalImpl( const LAMAArray<OtherType>& diagonal ); 00221 00224 virtual void setDiagonalImpl( const Scalar scalar ); 00225 00228 virtual COOStorage* copy() const; 00229 00232 virtual COOStorage* create() const; 00233 00234 /****************************************************************** 00235 * Matrix times Vector * 00236 ******************************************************************/ 00237 00240 virtual void matrixTimesVector( 00241 LAMAArrayView<ValueType> result, 00242 const ValueType alpha, const LAMAArrayConstView<ValueType> x, 00243 const ValueType beta, const LAMAArrayConstView<ValueType> y ) const; 00244 00245 00248 virtual std::auto_ptr<SyncToken> matrixTimesVectorAsyncToDo( 00249 LAMAArrayView<ValueType> result, 00250 const ValueType alpha, const LAMAArrayConstView<ValueType> x, 00251 const ValueType beta, const LAMAArrayConstView<ValueType> y ) const; 00252 00255 virtual void jacobiIterate( 00256 LAMAArrayView<ValueType> solution, const LAMAArrayConstView<ValueType> oldSolution, 00257 const LAMAArrayConstView<ValueType> rhs, const ValueType omega) const; 00258 00259 /****************************************************************** 00260 * Scaling of elements in a matrix * 00261 ******************************************************************/ 00262 00265 template<typename OtherType> 00266 void scaleImpl( const LAMAArray<OtherType>& values ); 00267 00270 void scaleImpl( const Scalar value ); 00271 00280 ValueType getValue( IndexType i, IndexType j ) const; 00281 00284 void prefetch(const ContextPtr location) const; 00285 00288 void wait() const; 00289 00293 void swap( COOStorage<ValueType>& other ); 00294 00295 virtual size_t getMemoryUsageImpl() const; 00296 00297 using MatrixStorage<ValueType>::mNumRows; 00298 using MatrixStorage<ValueType>::mNumColumns; 00299 using MatrixStorage<ValueType>::mDiagonalProperty; 00300 using MatrixStorage<ValueType>::mRowIndexes; 00301 using MatrixStorage<ValueType>::mCompressThreshold; 00302 00303 using MatrixStorage<ValueType>::assign; 00304 using MatrixStorage<ValueType>::prefetch; 00305 using MatrixStorage<ValueType>::getContextPtr; 00306 00307 IndexType mNumValues; 00308 00309 LAMAArray<IndexType> mIa; 00310 LAMAArray<IndexType> mJa; 00311 LAMAArray<ValueType> mValues; 00312 00313 private: 00314 00318 virtual bool checkDiagonalProperty() const; 00319 00320 // values are stored in row-major order 00321 00322 // TODO: index at irow / icolumn, not supported yet 00323 00324 // inline IndexType index(IndexType irow, IndexType icolumn) const { return icolumn * mNumRows + irow; } 00325 00326 LAMA_LOG_DECL_STATIC_LOGGER( logger ); 00327 }; 00328 00329 } // namespace lama 00330 00331 #endif // LAMA_COOSTORAGE_HPP_