LAMA
|
00001 00034 #ifndef LAMA_METAMATRIX_HPP_ 00035 #define LAMA_METAMATRIX_HPP_ 00036 00037 // for dll_import 00038 #include <lama/config.hpp> 00039 00040 // base classes 00041 #include <lama/matrix/Matrix.hpp> 00042 #include <lama/distribution/Distribution.hpp> 00043 #include <lama/Context.hpp> 00044 #include <lama/CommunicatorManager.hpp> 00045 #include <lama/CommunicatorFactory.hpp> 00046 00047 // spirit 00048 #include <boost/spirit/include/qi.hpp> 00049 00050 #include <string> 00051 #include <fstream> 00052 00053 namespace lama 00054 { 00055 00056 namespace phoenix = boost::phoenix; 00057 namespace qi = boost::spirit::qi; 00058 namespace ascii = boost::spirit::ascii; 00059 00060 class LAMA_DLL_IMPORTEXPORT MetaMatrix : public Matrix 00061 { 00062 public: 00063 typedef std::string::const_iterator StringIterator; 00064 00072 MetaMatrix( Matrix& other, const std::string& config ); 00073 00077 virtual ~MetaMatrix(); 00078 00079 /* 00080 * @brief If arg is a file it reads the files content. If not it calls the direct interpretation 00081 * 00082 * @param[in] arg Input string which is a file name or a configuration string 00083 */ 00084 void interpreteArgument( Matrix& other, const std::string& arg ); 00085 00086 /* 00087 * @brief Parses the given configuration and constructs the MetaMatrix 00088 * 00089 * Parses the given configuration in mConfiguration and constructs the MetaMatrix with the 00090 * described settings. 00091 */ 00092 void parseConfiguration( Matrix& other, const std::string& configuration ); 00093 00094 // **** Forward methods to provide matrix functionality **** 00095 00099 virtual const char* getTypeName() const; 00100 00111 virtual void clear(); 00112 00122 virtual void allocate( const IndexType numRows, const IndexType numColumns ); 00123 00132 virtual void allocate( DistributionPtr rowDistribution, DistributionPtr colDistribution ); 00133 00144 virtual void setIdentity(); 00145 00152 virtual void assign( const Matrix& other ); 00153 00159 virtual void assign( const _MatrixStorage& other ); 00160 00163 virtual void assign( const _MatrixStorage& storage, DistributionPtr rowDist, DistributionPtr colDist ); 00164 00174 virtual void buildLocalStorage( _MatrixStorage& storage ) const; 00175 00182 virtual void redistribute( DistributionPtr rowDistribution , DistributionPtr colDistribution ); 00183 00193 virtual void getRow( Vector& row, const IndexType globalRowIndex ) const; 00194 00201 virtual void getDiagonal( Vector& diagonal ) const; 00202 00209 virtual void setDiagonal( const Vector& diagonal ); 00210 00217 virtual void setDiagonal( const Scalar scalar ); 00218 00225 virtual void scale( const Vector& scaling ); 00226 00231 virtual void scale( const Scalar scaling ); 00232 00242 virtual Scalar getValue( IndexType i, IndexType j ) const; 00243 00255 virtual IndexType getNumValues() const; 00256 00269 virtual void matrixTimesVector( 00270 Vector& result, const Scalar alpha, const Vector& x, 00271 const Scalar beta, const Vector& y ) const; 00272 00281 virtual void matrixTimesScalar( 00282 const Matrix& other, const Scalar alpha ); 00283 00295 virtual void matrixTimesMatrix( 00296 Matrix& result, const Scalar alpha, const Matrix& B, 00297 const Scalar beta, const Matrix& C ) const; 00298 00301 virtual IndexType getLocalNumValues() const; 00302 00305 virtual IndexType getLocalNumRows() const; 00306 00309 virtual IndexType getLocalNumColumns() const; 00310 00319 virtual void setContext( const ContextPtr context ); 00320 00326 virtual ContextPtr getContextPtr() const; 00327 00330 virtual MatrixKind getMatrixKind() const; 00331 00335 virtual void prefetch() const; 00336 00340 virtual void wait() const; 00341 00344 virtual void invert( const Matrix& other ); 00345 00355 virtual Scalar maxDiffNorm( const Matrix& other ) const; 00356 00381 virtual std::auto_ptr<Matrix> create() const; 00382 00395 virtual std::auto_ptr<Matrix> copy() const; 00396 00400 virtual Scalar::ScalarType getValueType() const; 00401 00406 virtual bool hasDiagonalProperty() const; 00407 00412 virtual void resetDiagonalProperty(); 00413 00422 virtual size_t getMemoryUsage() const; 00423 00424 private: 00425 MatrixPtr mMatrix; 00426 00427 LAMA_LOG_DECL_STATIC_LOGGER(logger); 00428 00429 }; 00430 00431 class MatrixConfigGrammar : 00432 public qi::grammar<std::string::const_iterator, MatrixPtr( Matrix* ), qi::locals<Matrix*>, ascii::space_type> 00433 { 00434 public: 00435 typedef std::string::const_iterator StringIterator; 00436 MatrixConfigGrammar(); 00437 00438 private: 00439 qi::rule<StringIterator, MatrixPtr( Matrix* ), qi::locals<Matrix*>, ascii::space_type> 00440 mRMatrixConfiguration; 00441 00442 qi::rule<StringIterator, Matrix*( Matrix* ), ascii::space_type> mRType; 00443 00444 qi::rule<StringIterator, void( Matrix* ), ascii::space_type> mRContextDef; 00445 00446 qi::rule<StringIterator, ContextPtr(), ascii::space_type> mRContext; 00447 00448 qi::rule<StringIterator, ContextManager*(), ascii::space_type> mRContextManager; 00449 00450 qi::symbols<char, Context::ContextType> mRContextMap; 00451 00452 qi::rule<StringIterator, void( Matrix* ), ascii::space_type> mRDistributions; 00453 00454 qi::rule<StringIterator, DistributionPtr( int ), ascii::space_type> mRDistribution; 00455 00456 qi::rule<StringIterator, CommunicatorPtr(), ascii::space_type> mRComm; 00457 00458 qi::rule<StringIterator, boost::shared_ptr<CommunicatorManager>(), ascii::space_type> mRCommMan; 00459 00460 qi::rule<StringIterator, std::string()> mRId; 00461 00462 MatrixPtr mMatrix; 00463 00464 LAMA_LOG_DECL_STATIC_LOGGER(logger); 00465 }; 00466 00467 } //namespace lama 00468 00469 #endif /* LAMA_METAMATRIX_HPP_ */