LAMA
lama::LAMAArray< T > Class Template Reference

LAMAArray is the base array containter for all compute relevant data within LAMA. More...

#include <LAMAArray.hpp>

Inheritance diagram for lama::LAMAArray< T >:

Public Types

typedef T ValueType
 ValueType is the type stored in this container.

Public Member Functions

 LAMAArray ()
 LAMAArray() creates an empty LAMAArray with size 0.
 LAMAArray (const IndexType n)
 LAMAArray( const IndexType n ) creates a LAMAArray of size n.
 LAMAArray (const IndexType n, const ValueType &value)
 creates a LAMAArray of size n
template<typename OtherValueType >
 LAMAArray (const IndexType n, const OtherValueType *const values)
 creates a LAMAArray of size n
 LAMAArray (const LAMAArray< ValueType > &other)
 creates a copy of the passed LAMAArray
virtual ~LAMAArray ()
 Releases all used resources.
LAMAArray< ValueType > & operator= (const LAMAArray< ValueType > &other)
 Copies the passed LAMAArray into this.
void assign (const LAMAArray< ValueType > &other, ContextPtr context)
 Copies the passed LAMAArray into this.
void swap (LAMAArray< ValueType > &other)
 swaps the contens of this with other
void prefetch (ContextPtr context) const
 prefetches the contents of the container to the passed context
bool isAvailableAt (ContextPtr context) const
 Checks if the data of this LAMAArray is available at the passed context.
ContextPtr getValidContext (const Context::ContextType preferredType=Context::Host) const
 Gets the fist context where the data of this LAMAArray is available.
void wait () const
 waits for potentially running prefetch
void clear ()
 sets the size of this to 0 but does not free any memory
void purge ()
 sets the size of this to 0 an frees all memory
virtual void writeAt (std::ostream &stream) const
 writes the current status of this to the passed stream
virtual Scalar::ScalarType getValueType () const
 Implementation of pure method.
IndexType size () const
 Query the current size of the LAMA array, i.e.

Static Public Member Functions

static std::auto_ptr< _LAMAArraycreate (const Scalar::ScalarType)

Protected Member Functions

ValueTypeget (size_t index)
const ValueTypeget (const size_t index) const
void clear (const size_t index)
void resize (const size_t index, const IndexType newSize)
void reserve (const size_t index, const IndexType capacity, const bool copy) const
IndexType capacity (const size_t index) const
int acquireReadAccess (ContextPtr context) const
 Complete handling to get read access for a certain context.
void releaseReadAccess (const size_t index) const
int acquireWriteAccess (ContextPtr context, bool keepFlag)
 Complete handling to get write access for a certain context.
int acquireWriteAccess ()
void releaseWriteAccess (const size_t index)
void copy (const int toIndex, const int fromIndex) const
void fetch (Context::ContextData &target, const Context::ContextData &source) const
 Copy data from a valid source context to an invalid target context.
std::auto_ptr< SyncTokenfetchAsync (Context::ContextData &target, const Context::ContextData &source) const
 Asynchronous copy data from a valid source context to an invalid target context.
void getAccess (size_t &contextIndex, size_t &validIndex, ContextPtr context, Context::ContextData::AccessKind kind) const
void setHostContext ()
 LAMA_LOG_DECL_STATIC_LOGGER (logger)

Protected Attributes

std::vector
< Context::ContextData * > 
mContextData
std::auto_ptr< SyncTokenmSyncToken
 outstanding transfers
boost::recursive_mutex access_mutex
IndexType mSize
 number of entries for the context array, common for all contexts
bool constFlag
 if true the array cannot be written

Static Protected Attributes

static size_t nContextIndex = std::numeric_limits<std::size_t>::max()

Friends

class LAMAArrayView< T >
class LAMAArrayConstView< T >

Detailed Description

template<typename T>
class lama::LAMAArray< T >

LAMAArray is the base array containter for all compute relevant data within LAMA.

LAMAArray its contens on all supported Locations, e.g. Host, CUDA and OpenCL. It transparently handles synchronization between the Locations. To enforce the consitency of the data a LAMAArray can be only indirectly accessed via a ReadAccess or a WriteAccess.


Member Typedef Documentation

template<typename T>
typedef T lama::LAMAArray< T >::ValueType

ValueType is the type stored in this container.


Constructor & Destructor Documentation

template<typename ValueType >
lama::LAMAArray< ValueType >::LAMAArray ( )

LAMAArray() creates an empty LAMAArray with size 0.

References lama::LAMAArray< T >::setHostContext().

template<typename ValueType >
lama::LAMAArray< ValueType >::LAMAArray ( const IndexType  n) [explicit]

LAMAArray( const IndexType n ) creates a LAMAArray of size n.

Parameters:
[in]nthe size of the LAMAArray to create

LAMAArray( const IndexType n ) creates a LAMAArray of size n and allocates uninitialized Host memory.

References lama::Context::ContextData::allocate(), lama::LAMAArray< T >::mContextData, lama::_LAMAArray::mSize, and lama::LAMAArray< T >::setHostContext().

template<typename ValueType >
lama::LAMAArray< ValueType >::LAMAArray ( const IndexType  n,
const ValueType value 
)

creates a LAMAArray of size n

Parameters:
[in]nthe size of the LAMAArray to create
[in]valuethe value to initialize the container contens with

LAMAArray( const IndexType n ) creates a LAMAArray of size n, allocates Host memory and fills the Host memory with the passed value.

References lama::Context::ContextData::allocate(), lama::LAMAArray< T >::mContextData, lama::_LAMAArray::mSize, lama::Context::ContextData::pointer, lama::LAMAArray< T >::setHostContext(), and lama::Context::ContextData::valid.

template<typename ValueType >
template<typename OtherValueType >
lama::LAMAArray< ValueType >::LAMAArray ( const IndexType  n,
const OtherValueType *const  values 
)

creates a LAMAArray of size n

Parameters:
[in]nthe size of the LAMAArray to create
[in]valuesthe values to initialize the container contens with

LAMAArray( const IndexType n ) creates a LAMAArray of size n, allocates Host memory and fills the Host memory with the passed values.

References lama::Context::ContextData::allocate(), lama::LAMAArray< T >::mContextData, lama::_LAMAArray::mSize, lama::Context::ContextData::pointer, lama::LAMAArray< T >::setHostContext(), and lama::Context::ContextData::valid.

template<typename ValueType >
lama::LAMAArray< ValueType >::LAMAArray ( const LAMAArray< ValueType > &  other)

creates a copy of the passed LAMAArray

Parameters:
[in]otherthe LAMAArray to copy

LAMAArray(const LAMAArray<ValueType>& other) copies the passed LAMAArray. The container contens is copied for all currently valid Locations.

References lama::LAMAArray< T >::operator=(), and lama::LAMAArray< T >::setHostContext().

template<typename ValueType >
lama::LAMAArray< ValueType >::~LAMAArray ( ) [virtual]

Releases all used resources.


Member Function Documentation

template<typename ValueType >
int lama::LAMAArray< ValueType >::acquireReadAccess ( ContextPtr  context) const [protected]

Complete handling to get read access for a certain context.

Returns:
index of context data array that contains the valid entry.

References lama::Context::ContextData::context, LAMA_ASSERT_DEBUG, lama::Context::ContextData::lock, and lama::Context::ContextData::valid.

template<typename ValueType >
int lama::LAMAArray< ValueType >::acquireWriteAccess ( ContextPtr  context,
bool  keepFlag 
) [protected]

Complete handling to get write access for a certain context.

Returns:
index of context data array that contains the valid entry.

References lama::Context::ContextData::context, LAMA_ASSERT_DEBUG, lama::Context::ContextData::lock, and lama::Context::ContextData::valid.

template<typename ValueType >
void lama::LAMAArray< ValueType >::assign ( const LAMAArray< ValueType > &  other,
ContextPtr  context 
)

Copies the passed LAMAArray into this.

Parameters:
[in]otherthe LAMAArray to copy
[in]contextthe context where the assignment should be carried out

The assign method copies the passed LAMAArray. The container content is copied for the passed contexts. If necessary other is copied to context to carry this out.

References lama::Context::ContextData::context, LAMA_ASSERT_ERROR, LAMA_THROWEXCEPTION, lama::Context::ContextData::lock, lama::LAMAArray< T >::mContextData, lama::_LAMAArray::mSize, lama::LAMAArray< T >::prefetch(), lama::Context::ContextData::valid, and lama::LAMAArray< T >::wait().

template<typename ValueType >
IndexType lama::LAMAArray< ValueType >::capacity ( const size_t  index) const [protected]

References LAMA_ASSERT_DEBUG.

template<typename ValueType >
void lama::LAMAArray< ValueType >::clear ( )

sets the size of this to 0 but does not free any memory

This operation should be used before a write-only access that is followed by a resize of the array. It avoids data transfer between two contextes.

References LAMA_ASSERT.

Referenced by lama::_MatrixStorage::_assign(), lama::_MatrixStorage::_assignTranspose(), lama::Halo::clear(), and lama::Communicator::shiftAsync().

template<typename ValueType >
void lama::LAMAArray< ValueType >::clear ( const size_t  index) [protected]
template<typename ValueType >
void lama::LAMAArray< ValueType >::copy ( const int  toIndex,
const int  fromIndex 
) const [protected]

References LAMA_THROWEXCEPTION.

std::auto_ptr< _LAMAArray > lama::_LAMAArray::create ( const Scalar::ScalarType  valueType) [static, inherited]
template<typename ValueType >
void lama::LAMAArray< ValueType >::fetch ( Context::ContextData target,
const Context::ContextData source 
) const [protected]

Copy data from a valid source context to an invalid target context.

This routine assumes that there is already sufficient memory allocated in the target context.

References lama::Context::ContextData::context, LAMA_ASSERT, LAMA_ASSERT_DEBUG, lama::Context::ContextData::pointer, lama::Context::ContextData::size, and lama::Context::ContextData::valid.

template<typename ValueType >
std::auto_ptr< SyncToken > lama::LAMAArray< ValueType >::fetchAsync ( Context::ContextData target,
const Context::ContextData source 
) const [protected]
template<typename ValueType >
ValueType * lama::LAMAArray< ValueType >::get ( size_t  index) [protected]

References LAMA_ASSERT_DEBUG.

template<typename ValueType >
const ValueType * lama::LAMAArray< ValueType >::get ( const size_t  index) const [protected]

References LAMA_ASSERT_DEBUG.

template<typename ValueType >
void lama::LAMAArray< ValueType >::getAccess ( size_t &  contextIndex,
size_t &  validIndex,
ContextPtr  context,
Context::ContextData::AccessKind  kind 
) const [protected]
template<typename ValueType >
ContextPtr lama::LAMAArray< ValueType >::getValidContext ( const Context::ContextType  preferredType = Context::Host) const

Gets the fist context where the data of this LAMAArray is available.

If possible a context of the passed preferred type is returned.

Parameters:
[in]preferredTypethe preferred type for the valid context.
Returns:
a context there the data of this LAMAArray is available.

References lama::Context::ContextData::context, LAMA_ASSERT_DEBUG, lama::Context::ContextData::lock, and lama::Context::ContextData::valid.

Referenced by lama::LAMAArrayUtils::gather().

template<typename ValueType >
Scalar::ScalarType lama::LAMAArray< ValueType >::getValueType ( ) const [virtual]

Implementation of pure method.

Implements lama::_LAMAArray.

Referenced by lama::LAMAArrayUtils::assignImpl1().

template<typename ValueType >
bool lama::LAMAArray< ValueType >::isAvailableAt ( ContextPtr  context) const

Checks if the data of this LAMAArray is available at the passed context.

Parameters:
[in]contextthe context to check for availability of data.
Returns:
if the data of this LAMAArray is available at context

References LAMA_ASSERT_ERROR.

template<typename T>
lama::LAMAArray< T >::LAMA_LOG_DECL_STATIC_LOGGER ( logger  ) [protected]
template<typename ValueType >
LAMAArray< ValueType > & lama::LAMAArray< ValueType >::operator= ( const LAMAArray< ValueType > &  other)

Copies the passed LAMAArray into this.

Parameters:
[in]otherthe LAMAArray to copy

The assignment operator copies the passed LAMAArray. The container content is copied for all contexts where a valid copy is available (at least one).

References lama::Context::ContextData::context, LAMA_ASSERT_ERROR, LAMA_THROWEXCEPTION, lama::Context::ContextData::lock, lama::LAMAArray< T >::mContextData, lama::_LAMAArray::mSize, lama::Context::ContextData::valid, and lama::LAMAArray< T >::wait().

Referenced by lama::LAMAArray< T >::LAMAArray().

template<typename ValueType >
void lama::LAMAArray< ValueType >::prefetch ( ContextPtr  context) const

prefetches the contents of the container to the passed context

Parameters:
[in]contextthe context to prefetch to

This method prefetches the contents of the container to the context. If this valid at location nothing happens,if not a transfer from a valid location to the passed location is started. Because the transfer is handled by LAMAArray and to maintain the consistency of the container only one running transfer can exist at any point in time. There for if two prefetches to two different invalid locations are started one after the other the second transfer does not start before the first one is finished.

References LAMA_ASSERT_DEBUG, LAMA_ASSERT_ERROR, and lama::Context::ContextData::valid.

Referenced by lama::LAMAArray< T >::assign(), and lama::SpecializedJacobi::iterateTyped().

template<typename ValueType >
void lama::LAMAArray< ValueType >::purge ( )

sets the size of this to 0 an frees all memory

References lama::Context::ContextData::free(), LAMA_ASSERT, and lama::Context::ContextData::lock.

template<typename ValueType >
void lama::LAMAArray< ValueType >::releaseReadAccess ( const size_t  index) const [protected]

References LAMA_ASSERT, and LAMA_ASSERT_DEBUG.

template<typename ValueType >
void lama::LAMAArray< ValueType >::releaseWriteAccess ( const size_t  index) [protected]

References LAMA_ASSERT, and LAMA_ASSERT_DEBUG.

template<typename ValueType >
void lama::LAMAArray< ValueType >::reserve ( const size_t  index,
const IndexType  capacity,
const bool  copy 
) const [protected]
template<typename ValueType >
void lama::LAMAArray< ValueType >::resize ( const size_t  index,
const IndexType  newSize 
) [protected]
template<typename ValueType >
void lama::LAMAArray< ValueType >::setHostContext ( ) [protected]
IndexType lama::_LAMAArray::size ( ) const [inline, inherited]

Query the current size of the LAMA array, i.e.

number of entries.

Returns:
the number of entries of the array.

References lama::_LAMAArray::mSize.

Referenced by lama::CommunicationPlan::allocate(), lama::LAMAArrayUtils::assign(), lama::DenseVector< T >::assign(), lama::MatrixStorage< T >::assign(), lama::LAMAArrayUtils::assignImpl2(), lama::MatrixStorage< T >::assignTranspose(), lama::SparseMatrix< T >::assignTransposeImpl(), lama::SparseAssemblyStorage< T >::buildCSR(), lama::_StorageMethods::buildHalo(), lama::MatrixStorage< T >::buildHalo(), lama::MatrixStorage< T >::convertCSR2CSC(), lama::COOStorage< T >::COOStorage(), lama::MatrixStorage< T >::copyTo(), lama::Redistributor::copyV(), lama::DenseStorage< T >::DenseStorage(), lama::DenseStorageView< T >::DenseStorageView(), lama::DenseVector< T >::DenseVector(), lama::Communicator::exchangeByPlan(), lama::Communicator::exchangeByPlanAsync(), lama::MatrixStorage< T >::exchangeHalo(), lama::StorageMethods< T >::exchangeHaloCSR(), lama::LAMAArrayUtils::gather(), lama::Redistributor::gatherV(), lama::_MatrixStorage::getMemoryUsage(), lama::DenseMatrix< T >::invertCyclic(), lama::SpecializedJacobi::iterateTyped(), lama::StorageMethods< T >::joinCSR(), lama::MatrixStorage< T >::joinHalo(), lama::LAMAArrayRef< T >::LAMAArrayRef(), lama::MatrixStorage< T >::localize(), lama::StorageMethods< T >::localizeCSR(), lama::DenseMatrix< T >::matrixTimesVectorImpl(), lama::SparseMatrix< T >::matrixTimesVectorImpl(), lama::_MatrixStorage::offsets2sizes(), lama::MatrixStorage< T >::readFromFile(), lama::Redistributor::redistribute(), lama::MatrixStorage< T >::redistribute(), lama::StorageMethods< T >::redistributeCSR(), lama::Redistributor::redistributeN(), lama::MatrixStorage< T >::replicate(), lama::StorageMethods< T >::replicateCSR(), lama::CRTPMatrixStorage< CSRStorage< T >, T >::scale(), lama::SparseAssemblyStorage< T >::scaleImpl(), lama::CSRStorage< T >::scaleImpl(), lama::Redistributor::scatterV(), lama::DenseMatrix< T >::setCSRDataLocal(), lama::CRTPMatrixStorage< CSRStorage< T >, T >::setDiagonal(), lama::CSRStorage< T >::setDiagonalImpl(), lama::DIAStorage< T >::setDiagonalImpl(), lama::SparseAssemblyStorage< T >::setDiagonalImpl(), lama::MatrixStorage< T >::setRawDenseData(), lama::DenseVector< T >::setValues(), lama::_MatrixStorage::sizes2offsets(), lama::StorageMethods< T >::splitCSR(), lama::MatrixStorage< T >::splitHalo(), lama::CSRStorage< T >::swap(), lama::StorageIO< T >::writeCSRToBinaryFile(), lama::StorageIO< T >::writeCSRToFile(), lama::StorageIO< T >::writeCSRToFormattedFile(), lama::StorageIO< T >::writeCSRToMMFile(), and lama::StorageIO< T >::writeCSRToXDRFile().

template<typename ValueType >
void lama::LAMAArray< ValueType >::swap ( LAMAArray< ValueType > &  other)
template<typename ValueType >
void lama::LAMAArray< ValueType >::wait ( ) const

waits for potentially running prefetch

Referenced by lama::LAMAArray< T >::assign(), and lama::LAMAArray< T >::operator=().

template<typename ValueType >
void lama::LAMAArray< ValueType >::writeAt ( std::ostream &  stream) const [virtual]

writes the current status of this to the passed stream

Parameters:
[out]streamthe stream to write to

Reimplemented from Printable.

References lama::Context::ContextData::context, lama::Context::ContextData::lock, lama::Context::ContextData::size, and lama::Context::ContextData::valid.


Friends And Related Function Documentation

template<typename T>
friend class LAMAArrayConstView< T > [friend]
template<typename T>
friend class LAMAArrayView< T > [friend]

Field Documentation

template<typename T>
boost::recursive_mutex lama::LAMAArray< T >::access_mutex [mutable, protected]
bool lama::_LAMAArray::constFlag [protected, inherited]

if true the array cannot be written

Referenced by lama::LAMAArrayRef< T >::LAMAArrayRef(), and lama::LAMAArrayView< T >::LAMAArrayView().

template<typename T>
std::auto_ptr<SyncToken> lama::LAMAArray< T >::mSyncToken [mutable, protected]

outstanding transfers

Referenced by lama::LAMAArray< T >::swap().

template<typename T>
size_t lama::LAMAArray< ValueType >::nContextIndex = std::numeric_limits<std::size_t>::max() [static, protected]

Reimplemented from lama::_LAMAArray.


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