LAMA
/home/brandes/workspace/LAMA/src/lama/storage/DenseStorage.hpp
Go to the documentation of this file.
00001 
00033 #ifndef LAMA_DENSESTORAGE_HPP_
00034 #define LAMA_DENSESTORAGE_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/HostReadAccess.hpp>
00045 #include <lama/HostWriteAccess.hpp>
00046 #include <lama/Scalar.hpp>
00047 
00048 #include <lama/openmp/OpenMPDenseUtils.hpp>
00049 
00050 namespace lama
00051 {
00052 
00053 template<typename T> class DenseStorage;
00054 
00061 template<typename T>
00062 class LAMA_DLL_IMPORTEXPORT DenseStorageView : public CRTPMatrixStorage<DenseStorageView<T>, T>
00063 {
00064 public:
00065 
00066     typedef T ValueType;  
00067 
00070     static const char* typeName();
00071 
00080     DenseStorageView( LAMAArray<ValueType>& data, 
00081                      const IndexType numRows, 
00082                      const IndexType numColumns,
00083                      bool initializedData = true );
00084 
00087     virtual ~DenseStorageView();
00088 
00091     virtual DenseStorageView<ValueType>* copy() const;
00092 
00095     virtual DenseStorageView<ValueType>* create() const;
00096 
00102     void check( const char* msg ) const;
00103 
00106     virtual void assign( const _MatrixStorage& other );
00107 
00110     virtual Scalar::ScalarType getValueType() const;
00111 
00114     virtual MatrixStorageFormat getFormat() const;
00115 
00121     void setIdentity( const IndexType size );
00122 
00126     void setIdentity();
00127 
00131     void setZero();
00132 
00143     template<typename OtherValueType>
00144     void setCSRDataImpl( const IndexType numRows,
00145                          const IndexType numColumns,
00146                          const IndexType numValues,
00147                          const LAMAArray<IndexType>& ia,
00148                          const LAMAArray<IndexType>& ja,
00149                          const LAMAArray<OtherValueType>& values,
00150                          const ContextPtr loc );
00151 
00154     virtual void writeAt( std::ostream& stream ) const;
00155 
00164     ValueType getValue( IndexType i, IndexType j ) const;
00165 
00168     void prefetch( const ContextPtr location ) const;
00169 
00172     void wait() const;
00173 
00176     LAMAArray<ValueType>& getData();
00177 
00180     const LAMAArray<ValueType>& getData() const;
00181 
00184     virtual IndexType getNumValues() const;
00185 
00188     virtual void clear()
00189     {
00190         mNumRows = 0;
00191         mNumColumns = 0;
00192         mData.clear();
00193     }
00194 
00195     virtual void purge()
00196     {
00197         mNumRows = 0;
00198         mNumColumns = 0;
00199         mData.purge();
00200     }
00201 
00204     template<typename OtherValueType>
00205     void buildCSR( LAMAArray<IndexType>& ia,
00206                    LAMAArray<IndexType>* ja,
00207                    LAMAArray<OtherValueType>* values,
00208                    const ContextPtr /* loc */ ) const;
00209 
00210     /******************************************************************
00211     *   invert                                                        *
00212     ******************************************************************/
00213 
00218     virtual void invert( const MatrixStorage<ValueType>& other );
00219 
00222     virtual void matrixTimesVector(
00223         LAMAArrayView<ValueType> result,
00224         const ValueType alpha, const LAMAArrayConstView<ValueType> x,
00225         const ValueType beta, const LAMAArrayConstView<ValueType> y ) const;
00226 
00229     virtual void matrixTimesMatrix( const ValueType alpha,
00230                                     const MatrixStorage<ValueType>& a,
00231                                     const MatrixStorage<ValueType>& b,
00232                                     const ValueType beta,
00233                                     const MatrixStorage<ValueType>& c );
00234 
00237     virtual ValueType maxDiffNorm ( const MatrixStorage<ValueType>& other );
00238 
00241     virtual ValueType maxDiffNormImpl ( const DenseStorageView<ValueType>& other );
00242 
00245     template<typename OtherType>
00246     void getRowImpl( LAMAArray<OtherType>& row, const IndexType i ) const;
00247 
00250     template<typename OtherType>
00251     void getDiagonalImpl( LAMAArray<OtherType>& diagonal ) const;
00252 
00259     template<typename OtherType>
00260     void setDiagonalImpl( const LAMAArray<OtherType>& diagonal );
00261 
00264     void setDiagonalImpl( const Scalar scalar );
00265 
00266     /******************************************************************
00267     *  Scaling of elements in a matrix                                *
00268     ******************************************************************/
00269 
00272     template<typename OtherType>
00273     void scaleImpl( const LAMAArray<OtherType>& values );
00274 
00277     virtual void scaleImpl( const Scalar value );
00278 
00279     virtual size_t getMemoryUsageImpl() const;
00280 
00281     void swap( DenseStorageView<ValueType>& other );
00282 
00283     void allocate( const IndexType numRows, const IndexType numColumns );
00284 
00285     using MatrixStorage<ValueType>::mNumRows;
00286     using MatrixStorage<ValueType>::mNumColumns;
00287     using MatrixStorage<ValueType>::mDiagonalProperty;
00288     using MatrixStorage<ValueType>::prefetch;
00289     using MatrixStorage<ValueType>::assign;
00290     using MatrixStorage<ValueType>::mContext;
00291     using MatrixStorage<ValueType>::getTypeName;
00292 
00295     void print() const;
00296 
00297 protected:
00298 
00299     LAMAArray<ValueType>& mData;   
00300 
00301     LAMA_LOG_DECL_STATIC_LOGGER( logger );  
00302 
00303 private:
00304 
00305     DenseStorageView();   // disable the default constructor
00306 
00307     virtual bool checkDiagonalProperty() const;
00308 
00309     template<typename OtherType>
00310     void assignDenseStorageImpl( const DenseStorageView<OtherType>& otherDenseStorage );
00311 
00314     void matrixTimesMatrixDense( const ValueType alpha,
00315                                  const DenseStorageView<ValueType>& a,
00316                                  const DenseStorageView<ValueType>& b,
00317                                  const ValueType beta,
00318                                  const DenseStorageView<ValueType>& c );
00319 
00322     void invertDense( const DenseStorageView<ValueType>& other );
00323 };
00324 
00325 /* --------------------------------------------------------------------------- */
00326 
00329 template<typename T>
00330 class LAMA_DLL_IMPORTEXPORT DenseStorage : public DenseStorageView<T>
00331 {
00332 public:
00333 
00334     typedef T ValueType;  
00335 
00338     static const char* typeName();
00339 
00342     DenseStorage();
00343 
00350     DenseStorage( const IndexType numRows, const IndexType numColumns );
00351 
00359     DenseStorage( const LAMAArray<ValueType>& data, const IndexType numRows, const IndexType numColumns );
00360 
00363     DenseStorage( const DenseStorage<ValueType>& other );
00364 
00367     explicit DenseStorage( const _MatrixStorage& other );
00368 
00371     DenseStorage( const _MatrixStorage& other, const ContextPtr context );
00372 
00375     const char* getTypeName() const;
00376 
00377     DenseStorage<ValueType>& operator=( const _MatrixStorage& other);
00378 
00379     DenseStorage<ValueType>& operator=( const DenseStorage<ValueType>& other);
00380 
00383     virtual ~DenseStorage();
00384 
00385     using MatrixStorage<ValueType>::mNumRows;
00386     using MatrixStorage<ValueType>::mNumColumns;
00387     using MatrixStorage<ValueType>::assign;
00388 
00389     using DenseStorageView<ValueType>::mData;
00390 
00391 private:
00392 
00393     LAMAArray<ValueType> mDataArray;   
00394 
00395 };
00396 
00397 }
00398 
00399 #endif // LAMA_DENSESTORAGE_HPP_