LAMA
|
The class Vector is a abstract type that represents a distributed 1D real or complex vector. More...
#include <Vector.hpp>
Public Types | |
typedef const Vector & | ExpressionMemberType |
ExpressionMemberType is the type that is used the template Expression to store a Vector. | |
Public Member Functions | |
virtual | ~Vector () |
Releases all allocated resources. | |
Vector & | operator= (const Expression< Matrix, Vector, Times > &expression) |
The assignment operator assigns the result of the passed expression to this. | |
Vector & | operator= (const Expression< Scalar, Expression< Matrix, Vector, Times >, Times > &expression) |
Vector & | operator= (const Expression< Expression< Scalar, Vector, Times >, Expression< Scalar, Vector, Times >, Plus > &expression) |
Vector & | operator= (const Expression< Expression< Scalar, Expression< Matrix, Vector, Times >, Times >, Expression< Scalar, Vector, Times >, Plus > &expression) |
Vector & | operator= (const Expression< Scalar, Vector, Times > &expression) |
Vector & | operator= (const Expression< Vector, Vector, Plus > &expression) |
Vector & | operator= (const Vector &other) |
Vector & | operator*= (const Scalar value) |
Vector & | operator+= (const Vector &other) |
Vector & | operator+= (const Expression< Scalar, Vector, Times > &expression) |
Vector & | operator-= (const Vector &other) |
Vector & | operator= (const Scalar value) |
Assigns the passed value to all elements of this. | |
const Scalar | operator() (const IndexType i) const |
returns a copy of the value at the passed global index. | |
Scalar | operator* (const Vector &other) const |
returns the dot product of this and other | |
virtual void | buildValues (_LAMAArray &values) const =0 |
Build an array with local values of the vector. | |
virtual void | setValues (const _LAMAArray &values)=0 |
Set the local values of a vector by an array. | |
virtual Scalar::ScalarType | getValueType () const =0 |
Query the value type of the vector elements, e.g. | |
virtual Scalar | getValue (IndexType globalIndex) const =0 |
returns a copy of the value at the passed global index. | |
virtual Scalar | min () const =0 |
returns the global minimum value of this. | |
virtual Scalar | max () const =0 |
returns the global maximum value of this. | |
virtual Scalar | l1Norm () const =0 |
returns the L1 norm of this. | |
virtual Scalar | l2Norm () const =0 |
returns the L2 norm of this. | |
virtual Scalar | maxNorm () const =0 |
returns the max norm of this. | |
virtual std::auto_ptr< Vector > | create () const =0 |
Create is a virtual constructor, which creates a new Vector with the same concrete class, size and distribuiton than this. | |
virtual std::auto_ptr< Vector > | create (DistributionPtr distribution) const =0 |
Create is a virtual constructor, which creates a new Vector with the same concrete class than this. | |
IndexType | size () const |
Returns the size of the vector. | |
virtual void | swap (Vector &other)=0 |
Swap the content of of this vector with another vector. | |
virtual void | writeAt (std::ostream &stream) const |
Write some information about this to the passed stream. | |
virtual void | assign (const Vector &other)=0 |
Assign an arbitrary vector to this vector. | |
virtual void | assign (const _LAMAArray &localValues, DistributionPtr distribution)=0 |
Assignment to vector by local values and distribution. | |
virtual void | buildLocalValues (_LAMAArray &localValues) const =0 |
Build an array with local values of a distributed vector. | |
virtual void | assign (const Scalar value)=0 |
Assigns the passed value to all elements of this. | |
virtual void | assign (const Expression< Expression< Scalar, Vector, Times >, Expression< Scalar, Vector, Times >, Plus > &expression)=0 |
Assignment of a 'full' vector expression. | |
virtual Scalar | dotProduct (const Vector &other) const =0 |
virtual void | prefetch (const ContextPtr context) const =0 |
Starts a prefetch to make this valid at the passed context. | |
virtual void | wait () const =0 |
wait for a possibly running prefetch. | |
virtual void | invert ()=0 |
This method inverts all elements of the vector and is completely local. | |
void | setContext (ContextPtr location) |
Set the 'preferred' context where data resides and computations are done. | |
ContextPtr | getContext () const |
Getter for the context (pointer) of a vector. | |
virtual size_t | getMemoryUsage () const =0 |
getMemoryUsage returns the global memory that is allocated to hold this vector. | |
void | resize (DistributionPtr distributionPtr) |
Allocate this vector for a given distribution. | |
virtual void | redistribute (DistributionPtr distribution)=0 |
redistributes this vector to the new passed distribution. | |
const Distribution & | getDistribution () const |
DistributionPtr | getDistributionPtr () const |
Static Public Member Functions | |
static std::auto_ptr< Vector > | createVector (const Scalar::ScalarType valueType, DistributionPtr distribution) |
Protected Member Functions | |
Vector (const IndexType size=0, ContextPtr context=ContextFactory::getContext(Context::Host)) | |
Constructor of Vector for derived classes by size and/or context. | |
Vector (DistributionPtr distribution, ContextPtr context=ContextFactory::getContext(Context::Host)) | |
Constructor of Vector for derived classes by distribution. | |
Vector (const Vector &other) | |
Creates a copy of the passed Vector. | |
void | swapVector (Vector &other) |
Swap member variables of Vector class. | |
virtual void | resizeImpl ()=0 |
LAMA_LOG_DECL_STATIC_LOGGER (logger) | |
void | swap (Distributed &other) |
void | setDistributionPtr (DistributionPtr distributionPtr) |
Protected Attributes | |
ContextPtr | mContext |
decides about location of vector operations |
The class Vector is a abstract type that represents a distributed 1D real or complex vector.
Vector is one of the LAMA base types and should be used in all situations where it is not necessary to access a single element or to create a new Vector.
As this class is an abstract class, all constructors are protected.
The following methods must be implemented by derived classes:
This base class can be used to define dense and sparse vectors of any type.
typedef const Vector& lama::Vector::ExpressionMemberType |
ExpressionMemberType is the type that is used the template Expression to store a Vector.
lama::Vector::~Vector | ( | ) | [virtual] |
Releases all allocated resources.
References lama::Distributed::getDistribution().
lama::Vector::Vector | ( | const IndexType | size = 0 , |
ContextPtr | context = ContextFactory::getContext( Context::Host ) |
||
) | [explicit, protected] |
Constructor of Vector for derived classes by size and/or context.
References LAMA_ASSERT_ERROR, and mContext.
lama::Vector::Vector | ( | DistributionPtr | distribution, |
ContextPtr | context = ContextFactory::getContext( Context::Host ) |
||
) | [explicit, protected] |
Constructor of Vector for derived classes by distribution.
[in] | distribution | the distribution to use for the new Vector. |
[in] | context | is optional, will be Host context |
References lama::Distributed::getDistribution(), LAMA_ASSERT_ERROR, and mContext.
lama::Vector::Vector | ( | const Vector & | other | ) | [protected] |
Creates a copy of the passed Vector.
[in] | other | the Vector to take a copy from. |
Inherits size/distribution and the context of the passed vector.
References lama::Distributed::getDistribution(), lama::Distribution::getGlobalSize(), LAMA_ASSERT_ERROR, and mContext.
virtual void lama::Vector::assign | ( | const Vector & | other | ) | [pure virtual] |
Assign an arbitrary vector to this vector.
Implemented in lama::DenseVector< T >.
Referenced by lama::DenseMatrix< T >::getDiagonal(), and operator=().
virtual void lama::Vector::assign | ( | const _LAMAArray & | localValues, |
DistributionPtr | distribution | ||
) | [pure virtual] |
Assignment to vector by local values and distribution.
Implemented in lama::DenseVector< T >.
virtual void lama::Vector::assign | ( | const Scalar | value | ) | [pure virtual] |
Assigns the passed value to all elements of this.
[in] | value | the value to assign to all elements of this. |
Implemented in lama::DenseVector< T >.
virtual void lama::Vector::assign | ( | const Expression< Expression< Scalar, Vector, Times >, Expression< Scalar, Vector, Times >, Plus > & | expression | ) | [pure virtual] |
Assignment of a 'full' vector expression.
Implemented in lama::DenseVector< T >.
virtual void lama::Vector::buildLocalValues | ( | _LAMAArray & | localValues | ) | const [pure virtual] |
Build an array with local values of a distributed vector.
[out] | localValues | will be an array that contains local values of the vector |
For different value types, implicit format conversion will be done. A sparse vector should generate an array with all values.
Implemented in lama::DenseVector< T >.
Referenced by lama::DenseVector< T >::assign().
virtual void lama::Vector::buildValues | ( | _LAMAArray & | values | ) | const [pure virtual] |
Build an array with local values of the vector.
[in,out] | values | LAMA array that will be filled with the local values. |
Only the type of the LAMA array is used as input arg to determine the value type.
Implemented in lama::DenseVector< T >.
Referenced by lama::SparseMatrix< T >::scale(), and lama::SparseMatrix< T >::setDiagonal().
virtual std::auto_ptr<Vector> lama::Vector::create | ( | ) | const [pure virtual] |
Create is a virtual constructor, which creates a new Vector with the same concrete class, size and distribuiton than this.
Implemented in lama::DenseVector< T >.
Referenced by lama::SolutionProxy::create(), lama::Solver::getResidual(), operator=(), lama::SpecializedJacobi::solveInit(), and lama::DefaultJacobi::solveInit().
virtual std::auto_ptr<Vector> lama::Vector::create | ( | DistributionPtr | distribution | ) | const [pure virtual] |
Create is a virtual constructor, which creates a new Vector with the same concrete class than this.
[in] | distribution | the distribution to use for the new Vector. |
Implemented in lama::DenseVector< T >.
std::auto_ptr< Vector > lama::Vector::createVector | ( | const Scalar::ScalarType | valueType, |
DistributionPtr | distribution | ||
) | [static] |
References lama::File::DOUBLE, lama::File::FLOAT, and LAMA_THROWEXCEPTION.
Referenced by lama::SingleGridSetup::initialize(), lama::SpecializedJacobi::initialize(), and lama::DefaultJacobi::initialize().
virtual Scalar lama::Vector::dotProduct | ( | const Vector & | other | ) | const [pure virtual] |
Implemented in lama::DenseVector< T >.
Referenced by operator*().
ContextPtr lama::Vector::getContext | ( | ) | const [inline] |
Getter for the context (pointer) of a vector.
References mContext.
const Distribution & lama::Distributed::getDistribution | ( | ) | const [inline, inherited] |
References lama::Distributed::mDistribution.
Referenced by lama::SparseMatrix< T >::assignTransposeImpl(), lama::Matrix::checkSettings(), lama::LUSolver::computeLUFactorization(), lama::InverseSolver::decompose(), lama::DenseMatrix< T >::DenseMatrix(), lama::DenseVector< T >::DenseVector(), lama::DenseVector< T >::dotProduct(), lama::MatrixCreator< T >::fillRandom(), lama::SparseMatrix< T >::getLocalRow(), lama::SparseMatrix< T >::getRow(), lama::DenseMatrix< T >::getRow(), lama::DenseMatrixOps::invert(), lama::InverseSolver::invert(), lama::DenseMatrixOps::invertCyclic(), lama::DenseMatrixOps::invertReplicated(), lama::Matrix::Matrix(), lama::DenseMatrix< T >::matrixTimesMatrix(), lama::SparseMatrix< T >::matrixTimesMatrixImpl(), lama::CRTPMatrix< DenseMatrix< T >, T >::matrixTimesVector(), lama::SparseMatrix< T >::matrixTimesVector(), lama::SparseMatrix< T >::matrixTimesVectorNImpl(), lama::DenseMatrix< T >::maxDiffNorm(), lama::SparseMatrix< T >::maxDiffNorm(), lama::DenseMatrix< T >::maxDiffNormImpl(), lama::SparseMatrix< T >::maxDiffNormImpl(), lama::Matrix::operator=(), lama::SparseMatrix< T >::scale(), lama::SparseMatrix< T >::setDiagonal(), lama::LUSolver::solve(), lama::Solver::solveInit(), Vector(), and ~Vector().
DistributionPtr lama::Distributed::getDistributionPtr | ( | ) | const [inline, inherited] |
References lama::Distributed::mDistribution.
Referenced by lama::SparseMatrix< T >::assign(), lama::DenseMatrix< T >::assign(), lama::DenseVector< T >::assign(), lama::DenseMatrix< T >::assignSparse(), lama::SparseMatrix< T >::assignTransposeImpl(), lama::DenseMatrix< T >::copyDenseMatrix(), lama::DenseVector< T >::DenseVector(), lama::MatrixCreator< T >::fillRandom(), lama::SingleGridSetup::initialize(), lama::CG::initialize(), lama::DefaultJacobi::initialize(), lama::GMRES::initialize(), lama::DenseMatrixOps::invert(), lama::DenseMatrix< T >::invert(), lama::DenseMatrixOps::invertCyclic(), lama::GMRES::iterate(), lama::SparseMatrix< T >::matrixTimesMatrixImpl(), lama::CRTPMatrix< DenseMatrix< T >, T >::matrixTimesVector(), operator=(), size(), and writeAt().
virtual size_t lama::Vector::getMemoryUsage | ( | ) | const [pure virtual] |
getMemoryUsage returns the global memory that is allocated to hold this vector.
getMemoryUsage returns the global memory that is allocated to hold this vector. For a distributed vector all partitions are summed together.
Implemented in lama::DenseVector< T >.
virtual Scalar lama::Vector::getValue | ( | IndexType | globalIndex | ) | const [pure virtual] |
returns a copy of the value at the passed global index.
[in] | globalIndex | the global index to get the value at. |
As this operation requires communication in SPMD mode it can be very inefficient in some situations.
Implemented in lama::DenseVector< T >.
Referenced by lama::DenseVector< T >::assign(), and operator()().
virtual Scalar::ScalarType lama::Vector::getValueType | ( | ) | const [pure virtual] |
Query the value type of the vector elements, e.g.
DOUBLE or FLOAT.
Implemented in lama::DenseVector< T >.
Referenced by lama::DenseMatrix< T >::getDiagonal(), and lama::DenseMatrix< T >::getRow().
virtual void lama::Vector::invert | ( | ) | [pure virtual] |
This method inverts all elements of the vector and is completely local.
Implemented in lama::DenseVector< T >.
virtual Scalar lama::Vector::l1Norm | ( | ) | const [pure virtual] |
returns the L1 norm of this.
l1Norm computes the sum of the absolute values of this.
Implemented in lama::DenseVector< T >.
Referenced by lama::l1Norm().
virtual Scalar lama::Vector::l2Norm | ( | ) | const [pure virtual] |
returns the L2 norm of this.
l2Norm computes the sum of the absolute values of this.
Implemented in lama::DenseVector< T >.
Referenced by lama::GMRES::iterate(), and lama::l2Norm().
lama::Vector::LAMA_LOG_DECL_STATIC_LOGGER | ( | logger | ) | [protected] |
Reimplemented in lama::DenseVector< T >.
virtual Scalar lama::Vector::max | ( | ) | const [pure virtual] |
returns the global maximum value of this.
Implemented in lama::DenseVector< T >.
virtual Scalar lama::Vector::maxNorm | ( | ) | const [pure virtual] |
returns the max norm of this.
maxNorm computes the value of this with the largest magnitude.
Implemented in lama::DenseVector< T >.
Referenced by lama::maxNorm().
virtual Scalar lama::Vector::min | ( | ) | const [pure virtual] |
returns the global minimum value of this.
Implemented in lama::DenseVector< T >.
returns a copy of the value at the passed global index.
[in] | i | the global index to get the value at. |
As this operator requires communication ins SPMD mode it can be very inefficient in some situations.
References getValue().
returns the dot product of this and other
[in] | other | the vector do calculate the dot product with. |
References dotProduct(), and LAMA_REGION.
References operator=().
References operator=().
Vector & lama::Vector::operator+= | ( | const Expression< Scalar, Vector, Times > & | expression | ) |
References operator=(), and lama::Plus.
References operator=(), and lama::Plus.
Vector & lama::Vector::operator= | ( | const Expression< Matrix, Vector, Times > & | expression | ) |
The assignment operator assigns the result of the passed expression to this.
The assignment operator assigns the result of the passed expression to this, if necessary new memory will be allocated. The Vector will hold the result of the Matrix Vector multiplication represented by expression.
[in] | expression | the input expression. |
Exceptions | thrown by the Allocator |
References lama::Expression< T1, T2, type >::getArg1(), lama::Plus, resize(), and lama::Times.
Referenced by operator*=(), operator+=(), operator-=(), and operator=().
Vector & lama::Vector::operator= | ( | const Expression< Scalar, Expression< Matrix, Vector, Times >, Times > & | expression | ) |
References lama::Distributed::getDistributionPtr(), operator=(), lama::Plus, resize(), and lama::Times.
Vector & lama::Vector::operator= | ( | const Expression< Expression< Scalar, Vector, Times >, Expression< Scalar, Vector, Times >, Plus > & | expression | ) |
References assign(), and LAMA_THROWEXCEPTION.
Vector & lama::Vector::operator= | ( | const Expression< Expression< Scalar, Expression< Matrix, Vector, Times >, Times >, Expression< Scalar, Vector, Times >, Plus > & | expression | ) |
Vector & lama::Vector::operator= | ( | const Expression< Scalar, Vector, Times > & | expression | ) |
References assign(), lama::Expression< T1, T2, type >::getArg2(), and lama::Plus.
Vector & lama::Vector::operator= | ( | const Expression< Vector, Vector, Plus > & | expression | ) |
References assign(), and operator=().
Assigns the passed value to all elements of this.
[in] | value | the value to assign to all elements of this. |
Reimplemented in lama::DenseVector< T >.
References assign().
virtual void lama::Vector::prefetch | ( | const ContextPtr | context | ) | const [pure virtual] |
Starts a prefetch to make this valid at the passed context.
[in] | context | specifies the location to make this vector valid at |
Implemented in lama::DenseVector< T >.
virtual void lama::Vector::redistribute | ( | DistributionPtr | distribution | ) | [pure virtual] |
redistributes this vector to the new passed distribution.
[in] | distribution | the new distribution for this vector. |
The global vector itself remains unchanged; only local parts can be now different.
Implemented in lama::DenseVector< T >.
void lama::Vector::resize | ( | DistributionPtr | distributionPtr | ) |
Allocate this vector for a given distribution.
All elements of the vector are undefined after this operation. Elements can be set e.g. with
References resizeImpl(), and lama::Distributed::setDistributionPtr().
Referenced by lama::SparseMatrix< T >::getDiagonal(), lama::CRTPMatrix< DenseMatrix< T >, T >::matrixTimesVector(), lama::SparseMatrix< T >::matrixTimesVector(), and operator=().
virtual void lama::Vector::resizeImpl | ( | ) | [protected, pure virtual] |
Implemented in lama::DenseVector< T >.
Referenced by resize().
void lama::Vector::setContext | ( | ContextPtr | location | ) |
Set the 'preferred' context where data resides and computations are done.
References mContext.
Referenced by lama::DenseVector< T >::create(), and lama::GMRES::initialize().
void lama::Distributed::setDistributionPtr | ( | DistributionPtr | distributionPtr | ) | [protected, inherited] |
References lama::Distributed::mDistribution.
Referenced by resize(), and lama::Matrix::setDistributedMatrix().
virtual void lama::Vector::setValues | ( | const _LAMAArray & | values | ) | [pure virtual] |
Set the local values of a vector by an array.
[out] | values | is the array with local vector values. |
Note: A conversion operator must be available for values.getValueType() to the type of this vector.
Implemented in lama::DenseVector< T >.
Referenced by lama::SparseMatrix< T >::getDiagonal().
IndexType lama::Vector::size | ( | ) | const [inline] |
Returns the size of the vector.
References lama::Distributed::getDistributionPtr().
Referenced by lama::DenseVector< T >::DenseVector(), and lama::Solver::solveInit().
void lama::Distributed::swap | ( | Distributed & | other | ) | [protected, inherited] |
References lama::Distributed::mDistribution.
Referenced by lama::Matrix::swapMatrix().
virtual void lama::Vector::swap | ( | Vector & | other | ) | [pure virtual] |
Swap the content of of this vector with another vector.
[in,out] | other | the Vector to swap the contents with. |
Swap is only possible if both vectors are of the same kind (DENSE) and have the same value type.
Implemented in lama::DenseVector< T >.
Referenced by operator=(), and swapVector().
void lama::Vector::swapVector | ( | Vector & | other | ) | [protected] |
Swap member variables of Vector class.
References mContext, and swap().
Referenced by lama::DenseVector< T >::swap().
virtual void lama::Vector::wait | ( | ) | const [pure virtual] |
wait for a possibly running prefetch.
Implemented in lama::DenseVector< T >.
void lama::Vector::writeAt | ( | std::ostream & | stream | ) | const [virtual] |
Write some information about this to the passed stream.
[out] | stream | the stream to write to. |
Reimplemented from Printable.
Reimplemented in lama::DenseVector< T >.
References lama::Distributed::getDistributionPtr().
ContextPtr lama::Vector::mContext [protected] |
decides about location of vector operations
Referenced by getContext(), setContext(), swapVector(), and Vector().