LAMA
/home/brandes/workspace/LAMA/src/lama/Vector.hpp
Go to the documentation of this file.
00001 
00033 #ifndef LAMA_VECTOR_HPP_
00034 #define LAMA_VECTOR_HPP_
00035 
00036 // for dll_import
00037 #include <lama/config.hpp>
00038 
00039 // base classes
00040 #include <lama/Distributed.hpp>
00041 
00042 // others
00043 #include <lama/expression/Expression.hpp>
00044 #include <lama/ContextFactory.hpp>
00045 
00046 #include <lama/LAMATypes.hpp>
00047 #include <lama/Scalar.hpp>
00048 #include <lama/Context.hpp>
00049 
00050 // logging
00051 #include <logging/logging.hpp>
00052 
00053 namespace lama
00054 {
00055 
00056 class Matrix;
00057 
00060 typedef boost::shared_ptr<class Vector> VectorPtr;
00061 
00078 class LAMA_DLL_IMPORTEXPORT Vector : public Distributed, 
00079                                      public Printable
00080 {
00081 public:
00082 
00083     static std::auto_ptr<Vector> createVector(
00084         const Scalar::ScalarType valueType,
00085         DistributionPtr distribution);
00086 
00090     typedef const Vector& ExpressionMemberType;
00091 
00095     virtual ~Vector();
00096 
00110     Vector& operator=(const Expression<Matrix,Vector,Times>& expression);
00111 
00112     Vector& operator=(const Expression<Scalar,
00113                                        Expression<Matrix,Vector,Times>,
00114                                        Times>& expression);
00115 
00116     Vector& operator=(const Expression<Expression<Scalar,Vector,Times>,
00117                                        Expression<Scalar,Vector,Times>,
00118                                        Plus >& expression);
00119 
00120     Vector& operator=(const Expression<Expression<Scalar,
00121                                                   Expression<Matrix,Vector,Times>,
00122                                                   Times>,
00123                                        Expression<Scalar,Vector,Times>,
00124                                        Plus>& expression);
00125 
00126     Vector& operator= (const Expression<Scalar,Vector,Times>& expression);
00127 
00128     Vector& operator= (const Expression<Vector,Vector,Plus>& expression);
00129 
00130     Vector& operator= (const Vector& other);
00131 
00132     Vector& operator*= ( const Scalar value );
00133 
00134     Vector& operator+= ( const Vector& other );
00135 
00136     Vector& operator+= ( const Expression<Scalar, Vector, Times>& expression );
00137 
00138     Vector& operator-= ( const Vector& other );
00139 
00146     Vector& operator=( const Scalar value );
00147 
00156     const Scalar operator()( const IndexType i ) const;
00157 
00164     Scalar operator*( const Vector& other ) const;
00165   
00173     virtual void buildValues( _LAMAArray& values ) const = 0;
00174 
00183     virtual void setValues( const _LAMAArray& values ) = 0;
00184 
00188     virtual Scalar::ScalarType getValueType() const = 0;
00189 
00198     virtual Scalar getValue(IndexType globalIndex) const =0;
00199 
00205     virtual Scalar min() const =0;
00206 
00212     virtual Scalar max() const =0;
00213 
00221     virtual Scalar l1Norm() const =0;
00222 
00230     virtual Scalar l2Norm() const =0;
00231 
00239     virtual Scalar maxNorm() const =0;
00240 
00241     //TODO: This is an uninitialized create, do we need a initialized create?
00242     //      What is a good interface for an initialized create?
00248     virtual std::auto_ptr<Vector> create() const =0;
00249 
00256     virtual std::auto_ptr<Vector> create( DistributionPtr distribution) const =0;
00257 
00263     inline IndexType size() const;
00264 
00273     virtual void swap( Vector& other ) = 0;
00274 
00280     virtual void writeAt(std::ostream& stream) const;
00281 
00286     virtual void assign( const Vector& other ) =0;
00287 
00292     virtual void assign( const _LAMAArray& localValues, DistributionPtr distribution ) = 0;
00293   
00303     virtual void buildLocalValues( _LAMAArray& localValues ) const = 0;
00304 
00310     virtual void assign( const Scalar value ) =0;
00311 
00315     virtual void assign( const Expression<Expression<Scalar,Vector,Times>,
00316                                           Expression<Scalar,Vector,Times>,
00317                                           Plus >& expression ) =0;
00318 
00319     virtual Scalar dotProduct( const Vector& other ) const =0;
00320 
00326     virtual void prefetch( const ContextPtr context ) const =0;
00327 
00331     virtual void wait() const =0;
00332 
00337     virtual void invert() =0;
00338 
00342     void setContext( ContextPtr location );
00343 
00347     inline ContextPtr getContext() const;
00348 
00357     virtual size_t getMemoryUsage() const =0;
00358 
00365     void resize( DistributionPtr distributionPtr );
00366 
00375     virtual void redistribute( DistributionPtr distribution ) =0;
00376 
00377 protected:
00378 
00383     explicit Vector( const IndexType size = 0, ContextPtr context = ContextFactory::getContext( Context::Host )  );
00384 
00391     explicit Vector( DistributionPtr distribution, ContextPtr context = ContextFactory::getContext( Context::Host ) );
00392 
00400     Vector( const Vector& other );
00401 
00406     void swapVector( Vector& other ); 
00407 
00408     virtual void resizeImpl() =0;
00409 
00410     ContextPtr mContext;   
00411 
00412     LAMA_LOG_DECL_STATIC_LOGGER( logger );
00413 };
00414 
00415 IndexType Vector::size() const
00416 {
00417     return getDistributionPtr()->getGlobalSize();
00418 }
00419 
00420 ContextPtr Vector::getContext() const
00421 {
00422     return mContext;
00423 }
00424 
00425 }
00426 
00427 #endif // LAMA_VECTOR_HPP_