LAMA
|
00001 00033 #ifndef LAMA_JDSSTORAGE_HPP_ 00034 #define LAMA_JDSSTORAGE_HPP_ 00035 00036 // for dll_import 00037 #include <lama/config.hpp> 00038 00039 // base classes 00040 #include <lama/storage/CRTPMatrixStorage.hpp> 00041 00042 // others 00043 #include <lama/LAMAArray.hpp> 00044 #include <lama/Scalar.hpp> 00045 00046 #include <lama/distribution/Distribution.hpp> 00047 00048 namespace lama 00049 { 00050 00066 template<typename T> 00067 class LAMA_DLL_IMPORTEXPORT JDSStorage : public CRTPMatrixStorage<JDSStorage<T>, T> 00068 { 00069 public: 00070 00071 typedef T ValueType; 00072 00075 static const char* typeName(); 00076 00083 JDSStorage( const IndexType numRows, const IndexType numColumns ); 00084 00087 JDSStorage( const IndexType numRows, 00088 const IndexType numColumns, 00089 const IndexType numValues, 00090 const IndexType numDiagonals, 00091 const LAMAArray<IndexType>& dlg, 00092 const LAMAArray<IndexType>& ilg, 00093 const LAMAArray<IndexType>& perm, 00094 const LAMAArray<IndexType>& ja, 00095 const LAMAArray<ValueType>& values ); 00096 00099 JDSStorage(); 00100 00103 JDSStorage( const JDSStorage<ValueType>& other ); 00104 00107 explicit JDSStorage( const _MatrixStorage& other ); 00108 00111 JDSStorage( const _MatrixStorage& other, const ContextPtr context ); 00112 00115 JDSStorage<ValueType>& operator=( const JDSStorage<ValueType>& other); 00116 00119 JDSStorage<ValueType>& operator=( const _MatrixStorage& other); 00120 00123 virtual JDSStorage* copy() const; 00124 00127 virtual JDSStorage* create() const; 00128 00131 virtual void clear(); 00132 00135 virtual ~JDSStorage(); 00136 00141 void check( const char* msg ) const; 00142 00145 void allocate( const IndexType numRows, const IndexType numColumns ); 00146 00149 virtual MatrixStorageFormat getFormat() const; 00150 00153 virtual void purge(); 00154 00157 virtual void setIdentity( const IndexType size ); 00158 00167 template<typename OtherValueType> 00168 void buildCSR( LAMAArray<IndexType>& ia, 00169 LAMAArray<IndexType>* ja, 00170 LAMAArray<OtherValueType>* values, 00171 const ContextPtr /* loc */ ) const; 00172 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 matrixTimesVector( 00188 LAMAArrayView<ValueType> result, 00189 const ValueType alpha, const LAMAArrayConstView<ValueType> x, 00190 const ValueType beta, const LAMAArrayConstView<ValueType> y ) const; 00191 00194 virtual void jacobiIterate( 00195 LAMAArrayView<ValueType> solution, const LAMAArrayConstView<ValueType> oldSolution, 00196 const LAMAArrayConstView<ValueType> rhs, const ValueType omega) const; 00197 00200 virtual void jacobiIterateHalo( 00201 LAMAArrayView<ValueType> localSolution, 00202 const MatrixStorage<ValueType>& localStorage, 00203 const LAMAArrayConstView<ValueType> haloOldSolution, 00204 const ValueType omega ) const; 00205 00208 virtual void writeAt( std::ostream& stream ) const; 00209 00210 const LAMAArray<IndexType>& getJA() const; 00211 00212 const LAMAArray<IndexType>& getPerm() const; 00213 00214 const LAMAArray<IndexType>& getDlg() const; 00215 00216 const LAMAArray<IndexType>& getIlg() const; 00217 00218 const LAMAArray<ValueType>& getValues() const; 00219 00220 IndexType getNumDiagonals() const; 00221 00224 virtual IndexType getNumValues() const; 00225 00228 template<typename OtherType> 00229 void getRowImpl( LAMAArray<OtherType>& row, const IndexType i ) const; 00230 00237 template<typename OtherType> 00238 void getDiagonalImpl( LAMAArray<OtherType>& diagonal ) const; 00239 00246 template<typename OtherType> 00247 void setDiagonalImpl( const LAMAArray<OtherType>& diagonal ); 00248 00249 void setDiagonalImpl( const Scalar ); 00250 00251 /****************************************************************** 00252 * Scaling of elements in a matrix * 00253 ******************************************************************/ 00254 00257 template<typename OtherType> 00258 void scaleImpl( const LAMAArray<OtherType>& values ); 00259 00262 void scaleImpl( const Scalar value ); 00263 00272 ValueType getValue( IndexType i, IndexType j ) const; 00273 00276 void prefetch( const ContextPtr location ) const; 00277 00280 void wait() const; 00281 00285 void swap( JDSStorage<ValueType>& other ); 00286 00287 virtual size_t getMemoryUsageImpl() const; 00288 00289 using MatrixStorage<ValueType>::assign; 00290 using MatrixStorage<ValueType>::prefetch; 00291 using MatrixStorage<ValueType>::getContext; 00292 using MatrixStorage<ValueType>::getContextPtr; 00293 00294 protected: 00295 00296 using MatrixStorage<ValueType>::mNumRows; 00297 using MatrixStorage<ValueType>::mNumColumns; 00298 using MatrixStorage<ValueType>::mDiagonalProperty; 00299 using MatrixStorage<ValueType>::mRowIndexes; 00300 using MatrixStorage<ValueType>::mCompressThreshold; 00301 00302 IndexType mNumDiagonals; 00303 IndexType mNumValues; 00304 00305 LAMAArray<IndexType> mDlg; 00306 LAMAArray<IndexType> mIlg; 00307 LAMAArray<IndexType> mPerm; 00308 LAMAArray<IndexType> mJa; 00309 LAMAArray<ValueType> mValues; 00310 00311 private: 00312 00315 void assignJDS( const JDSStorage<ValueType>& other ); 00316 00320 virtual bool checkDiagonalProperty() const; 00321 00325 void sortRows( ContextPtr loc ); 00326 00329 void setupData( ContextPtr loc ); 00330 00335 /* 00336 * NOT USED ANYMORE 00337 void setCompressJDS( const JDSStorage<ValueType>& other ); 00338 */ 00339 00340 void print() const; 00341 00342 LAMA_LOG_DECL_STATIC_LOGGER( logger ); 00343 }; 00344 00345 } // namespace lama 00346 00347 #endif // LAMA_JDSSTORAGE_HPP_