LAMA
|
LAMAArray is the base array containter for all compute relevant data within LAMA. More...
#include <LAMAArray.hpp>
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< _LAMAArray > | create (const Scalar::ScalarType) |
Protected Member Functions | |
ValueType * | get (size_t index) |
const ValueType * | get (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< SyncToken > | fetchAsync (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< SyncToken > | mSyncToken |
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 > |
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.
typedef T lama::LAMAArray< T >::ValueType |
ValueType is the type stored in this container.
lama::LAMAArray< ValueType >::LAMAArray | ( | ) |
LAMAArray() creates an empty LAMAArray with size 0.
References lama::LAMAArray< T >::setHostContext().
lama::LAMAArray< ValueType >::LAMAArray | ( | const IndexType | n | ) | [explicit] |
LAMAArray( const IndexType n ) creates a LAMAArray of size n.
[in] | n | the 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().
lama::LAMAArray< ValueType >::LAMAArray | ( | const IndexType | n, |
const ValueType & | value | ||
) |
creates a LAMAArray of size n
[in] | n | the size of the LAMAArray to create |
[in] | value | the 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.
lama::LAMAArray< ValueType >::LAMAArray | ( | const IndexType | n, |
const OtherValueType *const | values | ||
) |
creates a LAMAArray of size n
[in] | n | the size of the LAMAArray to create |
[in] | values | the 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.
lama::LAMAArray< ValueType >::LAMAArray | ( | const LAMAArray< ValueType > & | other | ) |
creates a copy of the passed LAMAArray
[in] | other | the 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().
lama::LAMAArray< ValueType >::~LAMAArray | ( | ) | [virtual] |
Releases all used resources.
int lama::LAMAArray< ValueType >::acquireReadAccess | ( | ContextPtr | context | ) | const [protected] |
Complete handling to get read access for a certain context.
References lama::Context::ContextData::context, LAMA_ASSERT_DEBUG, lama::Context::ContextData::lock, and lama::Context::ContextData::valid.
int lama::LAMAArray< ValueType >::acquireWriteAccess | ( | ContextPtr | context, |
bool | keepFlag | ||
) | [protected] |
Complete handling to get write access for a certain context.
References lama::Context::ContextData::context, LAMA_ASSERT_DEBUG, lama::Context::ContextData::lock, and lama::Context::ContextData::valid.
int lama::LAMAArray< ValueType >::acquireWriteAccess | ( | ) | [protected] |
References lama::Context::ContextData::context, lama::max(), and lama::Context::ContextData::valid.
void lama::LAMAArray< ValueType >::assign | ( | const LAMAArray< ValueType > & | other, |
ContextPtr | context | ||
) |
Copies the passed LAMAArray into this.
[in] | other | the LAMAArray to copy |
[in] | context | the 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().
IndexType lama::LAMAArray< ValueType >::capacity | ( | const size_t | index | ) | const [protected] |
References LAMA_ASSERT_DEBUG.
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().
void lama::LAMAArray< ValueType >::clear | ( | const size_t | index | ) | [protected] |
References LAMA_ASSERT_DEBUG, and LAMA_ASSERT_ERROR.
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] |
References lama::Scalar::DOUBLE, lama::Scalar::FLOAT, and LAMA_THROWEXCEPTION.
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.
std::auto_ptr< SyncToken > lama::LAMAArray< ValueType >::fetchAsync | ( | Context::ContextData & | target, |
const Context::ContextData & | source | ||
) | const [protected] |
Asynchronous copy data from a valid source context to an invalid target context.
References lama::Context::ContextData::context, LAMA_ASSERT_DEBUG, LAMA_THROWEXCEPTION, lama::Context::ContextData::pointer, lama::Context::ContextData::size, and lama::Context::ContextData::valid.
ValueType * lama::LAMAArray< ValueType >::get | ( | size_t | index | ) | [protected] |
References LAMA_ASSERT_DEBUG.
const ValueType * lama::LAMAArray< ValueType >::get | ( | const size_t | index | ) | const [protected] |
References LAMA_ASSERT_DEBUG.
void lama::LAMAArray< ValueType >::getAccess | ( | size_t & | contextIndex, |
size_t & | validIndex, | ||
ContextPtr | context, | ||
Context::ContextData::AccessKind | kind | ||
) | const [protected] |
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.
[in] | preferredType | the preferred type for the valid context. |
References lama::Context::ContextData::context, LAMA_ASSERT_DEBUG, lama::Context::ContextData::lock, and lama::Context::ContextData::valid.
Referenced by lama::LAMAArrayUtils::gather().
Scalar::ScalarType lama::LAMAArray< ValueType >::getValueType | ( | ) | const [virtual] |
Implementation of pure method.
Implements lama::_LAMAArray.
Referenced by lama::LAMAArrayUtils::assignImpl1().
bool lama::LAMAArray< ValueType >::isAvailableAt | ( | ContextPtr | context | ) | const |
Checks if the data of this LAMAArray is available at the passed context.
[in] | context | the context to check for availability of data. |
References LAMA_ASSERT_ERROR.
lama::LAMAArray< T >::LAMA_LOG_DECL_STATIC_LOGGER | ( | logger | ) | [protected] |
LAMAArray< ValueType > & lama::LAMAArray< ValueType >::operator= | ( | const LAMAArray< ValueType > & | other | ) |
Copies the passed LAMAArray into this.
[in] | other | the 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().
void lama::LAMAArray< ValueType >::prefetch | ( | ContextPtr | context | ) | const |
prefetches the contents of the container to the passed context
[in] | context | the 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().
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.
void lama::LAMAArray< ValueType >::releaseReadAccess | ( | const size_t | index | ) | const [protected] |
References LAMA_ASSERT, and LAMA_ASSERT_DEBUG.
void lama::LAMAArray< ValueType >::releaseWriteAccess | ( | const size_t | index | ) | [protected] |
References LAMA_ASSERT, and LAMA_ASSERT_DEBUG.
void lama::LAMAArray< ValueType >::reserve | ( | const size_t | index, |
const IndexType | capacity, | ||
const bool | copy | ||
) | const [protected] |
References LAMA_ASSERT_DEBUG, and LAMA_ASSERT_ERROR.
void lama::LAMAArray< ValueType >::resize | ( | const size_t | index, |
const IndexType | newSize | ||
) | [protected] |
References LAMA_ASSERT_DEBUG, and LAMA_ASSERT_ERROR.
void lama::LAMAArray< ValueType >::setHostContext | ( | ) | [protected] |
References LAMA_ASSERT_DEBUG, LAMA_MAX_CONTEXTS, and lama::Context::ContextData::valid.
Referenced by lama::LAMAArray< T >::LAMAArray().
IndexType lama::_LAMAArray::size | ( | ) | const [inline, inherited] |
Query the current size of the LAMA array, i.e.
number of entries.
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().
void lama::LAMAArray< ValueType >::swap | ( | LAMAArray< ValueType > & | other | ) |
swaps the contens of this with other
[in] | other | the LAMAArray to swap the contens with. |
References LAMA_ASSERT_ERROR, lama::LAMAArray< T >::mContextData, lama::_LAMAArray::mSize, and lama::LAMAArray< T >::mSyncToken.
Referenced by lama::Communicator::computeOwners(), lama::DenseVector< T >::redistribute(), and lama::_MatrixStorage::swap().
void lama::LAMAArray< ValueType >::wait | ( | ) | const |
waits for potentially running prefetch
Referenced by lama::LAMAArray< T >::assign(), and lama::LAMAArray< T >::operator=().
void lama::LAMAArray< ValueType >::writeAt | ( | std::ostream & | stream | ) | const [virtual] |
writes the current status of this to the passed stream
[out] | stream | the 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.
friend class LAMAArrayConstView< T > [friend] |
friend class LAMAArrayView< T > [friend] |
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().
std::vector<Context::ContextData*> lama::LAMAArray< T >::mContextData [mutable, protected] |
IndexType lama::_LAMAArray::mSize [protected, inherited] |
number of entries for the context array, common for all contexts
Referenced by lama::LAMAArray< T >::assign(), lama::LAMAArray< T >::LAMAArray(), lama::LAMAArrayRef< T >::LAMAArrayRef(), lama::LAMAArray< T >::operator=(), lama::_LAMAArray::size(), and lama::LAMAArray< T >::swap().
std::auto_ptr<SyncToken> lama::LAMAArray< T >::mSyncToken [mutable, protected] |
outstanding transfers
Referenced by lama::LAMAArray< T >::swap().
size_t lama::LAMAArray< ValueType >::nContextIndex = std::numeric_limits<std::size_t>::max() [static, protected] |
Reimplemented from lama::_LAMAArray.