LAMA
lama::Vector Class Reference

The class Vector is a abstract type that represents a distributed 1D real or complex vector. More...

#include <Vector.hpp>

Inheritance diagram for lama::Vector:

Public Types

typedef const VectorExpressionMemberType
 ExpressionMemberType is the type that is used the template Expression to store a Vector.

Public Member Functions

virtual ~Vector ()
 Releases all allocated resources.
Vectoroperator= (const Expression< Matrix, Vector, Times > &expression)
 The assignment operator assigns the result of the passed expression to this.
Vectoroperator= (const Expression< Scalar, Expression< Matrix, Vector, Times >, Times > &expression)
Vectoroperator= (const Expression< Expression< Scalar, Vector, Times >, Expression< Scalar, Vector, Times >, Plus > &expression)
Vectoroperator= (const Expression< Expression< Scalar, Expression< Matrix, Vector, Times >, Times >, Expression< Scalar, Vector, Times >, Plus > &expression)
Vectoroperator= (const Expression< Scalar, Vector, Times > &expression)
Vectoroperator= (const Expression< Vector, Vector, Plus > &expression)
Vectoroperator= (const Vector &other)
Vectoroperator*= (const Scalar value)
Vectoroperator+= (const Vector &other)
Vectoroperator+= (const Expression< Scalar, Vector, Times > &expression)
Vectoroperator-= (const Vector &other)
Vectoroperator= (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< Vectorcreate () 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< Vectorcreate (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 DistributiongetDistribution () const
DistributionPtr getDistributionPtr () const

Static Public Member Functions

static std::auto_ptr< VectorcreateVector (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

Detailed Description

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:

  • buildValues to get all local elements on one processor
  • getLocalValue( i ) the the i-th local element

This base class can be used to define dense and sparse vectors of any type.


Member Typedef Documentation

ExpressionMemberType is the type that is used the template Expression to store a Vector.


Constructor & Destructor Documentation

lama::Vector::~Vector ( ) [virtual]

Releases all allocated resources.

References lama::Distributed::getDistribution().

lama::Vector::Vector ( const IndexType  size = 0,
ContextPtr  context = ContextFactory::getContextContext::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::getContextContext::Host ) 
) [explicit, protected]

Constructor of Vector for derived classes by distribution.

Parameters:
[in]distributionthe distribution to use for the new Vector.
[in]contextis 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.

Parameters:
[in]otherthe 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.


Member Function Documentation

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.

Parameters:
[in]valuethe 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.

Parameters:
[out]localValueswill 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.

Parameters:
[in,out]valuesLAMA 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.

Returns:
a pointer to the new Vector, caller has the owner ship.

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.

Parameters:
[in]distributionthe distribution to use for the new Vector.
Returns:
a pointer to the new Vector, caller has the owner ship.

Implemented in lama::DenseVector< T >.

virtual Scalar lama::Vector::dotProduct ( const Vector other) const [pure virtual]

Implemented in lama::DenseVector< T >.

Referenced by operator*().

Getter for the context (pointer) of a vector.

References mContext.

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.

Returns:
the memory consumption of this vector.

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.

Parameters:
[in]globalIndexthe global index to get the value at.
Returns:
a copy of the value at the passed global position.

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.

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.

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().

Reimplemented in lama::DenseVector< T >.

virtual Scalar lama::Vector::max ( ) const [pure virtual]

returns the global maximum value of this.

Returns:
the global maximum value of this vector.

Implemented in lama::DenseVector< T >.

virtual Scalar lama::Vector::maxNorm ( ) const [pure virtual]

returns the max norm of this.

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.

Returns:
the global minimum value of this vector.

Implemented in lama::DenseVector< T >.

const Scalar lama::Vector::operator() ( const IndexType  i) const

returns a copy of the value at the passed global index.

Parameters:
[in]ithe global index to get the value at.
Returns:
a copy of the value at the passed global position.

As this operator requires communication ins SPMD mode it can be very inefficient in some situations.

References getValue().

Scalar lama::Vector::operator* ( const Vector other) const

returns the dot product of this and other

Parameters:
[in]otherthe vector do calculate the dot product with.
Returns:
the dot product of this and other

References dotProduct(), and LAMA_REGION.

Vector & lama::Vector::operator*= ( const Scalar  value)

References operator=().

Vector & lama::Vector::operator+= ( const Vector other)

References operator=().

Vector & lama::Vector::operator+= ( const Expression< Scalar, Vector, Times > &  expression)

References operator=(), and lama::Plus.

Vector & lama::Vector::operator-= ( const Vector other)

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.

Parameters:
[in]expressionthe input expression.
Returns:
a reference to this.
Exceptions:
Exceptionsthrown 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)
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< Scalar, Vector, Times > &  expression)
Vector & lama::Vector::operator= ( const Vector other)

References assign(), and operator=().

Vector & lama::Vector::operator= ( const Scalar  value)

Assigns the passed value to all elements of this.

Parameters:
[in]valuethe value to assign to all elements of this.
Returns:
a reference to 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.

Parameters:
[in]contextspecifies 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.

Parameters:
[in]distributionthe 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().

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]
virtual void lama::Vector::setValues ( const _LAMAArray values) [pure virtual]

Set the local values of a vector by an array.

Parameters:
[out]valuesis 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.

Returns:
the size of this vector.

References lama::Distributed::getDistributionPtr().

Referenced by lama::DenseVector< T >::DenseVector(), and lama::Solver::solveInit().

void lama::Distributed::swap ( Distributed other) [protected, inherited]
virtual void lama::Vector::swap ( Vector other) [pure virtual]

Swap the content of of this vector with another vector.

Parameters:
[in,out]otherthe 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.

Parameters:
[out]streamthe stream to write to.

Reimplemented from Printable.

Reimplemented in lama::DenseVector< T >.

References lama::Distributed::getDistributionPtr().


Field Documentation

decides about location of vector operations

Referenced by getContext(), setContext(), swapVector(), and Vector().


The documentation for this class was generated from the following files: