LAMA
|
The Template WriteAccess is used to enforce the consistency of the template LAMAArray. More...
#include <WriteAccess.hpp>
Public Types | |
typedef T | ValueType |
ValueType is the type stored in the wrapped container. | |
Public Member Functions | |
WriteAccess (LAMAArray< ValueType > &array, ContextPtr context) | |
acquire a WriteAccess to the passed LAMAArray for the passed location | |
WriteAccess (LAMAArray< ValueType > &array, ContextPtr context, const IndexType size, const bool keep) | |
acquire a WriteAccess to the passed LAMAArray for the passed location with resize | |
WriteAccess (LAMAArray< ValueType > &array) | |
acquire a WriteAccess to the passed LAMAArray for a valid context. | |
WriteAccess (LAMAArrayView< ValueType > &view, ContextPtr context, const bool keep=true) | |
WriteAccess (LAMAArrayView< ValueType > &view, ContextPtr context, const IndexType size, const bool keep=true) | |
virtual | ~WriteAccess () |
Releases the WriteAccess on the associated LAMAArray. | |
ValueType * | get () |
returns a pointer to the data of the wrapped LAMAArray | |
void | clear () |
Set the size of the LAMAArray to 0. | |
void | resize (const IndexType newSize) |
resizes the wrapped LAMAArray | |
void | reserve (const IndexType capacity) |
reserve storage for wth wrapped LAMAArray at the associated location | |
IndexType | capacity () const |
query the capacity of the array on the reserved context | |
virtual void | release () |
Releases the WriteAccess on the associated LAMAArray. | |
virtual void | writeAt (std::ostream &stream) const |
Writes some Information about this to the passed stream. | |
IndexType | size () const |
Returns the size of the wrapped LAMAArray. | |
Protected Member Functions | |
LAMA_LOG_DECL_STATIC_LOGGER (logger) | |
Protected Attributes | |
ValueType * | mData |
LAMAArrayView< ValueType > * | mArrayView |
size_t | mIndex |
The Template WriteAccess is used to enforce the consistency of the template LAMAArray.
WriteAccess enforces the consistency of the template LAMAArray by following the RAII Idiom. This is done by acquiring a write lock on a LAMAArray in the constructor and releasing this write lock in the destructor. There for a WriteAccess should be only used as a stack object.
typedef T lama::WriteAccess< T >::ValueType |
ValueType is the type stored in the wrapped container.
Reimplemented in lama::WriteOnlyAccess< T >, lama::HostWriteOnlyAccess< T >, and lama::HostWriteAccess< T >.
lama::WriteAccess< T >::WriteAccess | ( | LAMAArray< ValueType > & | array, |
ContextPtr | context | ||
) |
acquire a WriteAccess to the passed LAMAArray for the passed location
[in] | array | the LAMAArray to acquire a WriteAccess for |
[in] | context | the context to acquire a WriteAccess for |
Exception | if the WriteAccess can not be acquired, e.g. because another WriteAccess exists. |
This constructor acquires a WriteAccess to the passed LAMAArray for the passed location. Depending on the flag keep the LAMAArray is updated on location or not. This flag can be used to acquire write only access, e.g. if one want to write only to the passed wrapped LAMAArray. If the passed LAMAArray is not valid at location and keep is true the LAMAArray will be made valid at location before this constructor returns.
References lama::LAMAArrayView< T >::acquireWriteAccess(), lama::LAMAArrayView< T >::get(), lama::WriteAccess< T >::mArrayView, lama::WriteAccess< T >::mData, and lama::WriteAccess< T >::mIndex.
lama::WriteAccess< T >::WriteAccess | ( | LAMAArray< ValueType > & | array, |
ContextPtr | context, | ||
const IndexType | size, | ||
const bool | keep | ||
) |
acquire a WriteAccess to the passed LAMAArray for the passed location with resize
[in] | array | the LAMAArray to acquire a WriteAccess for |
[in] | context | the context to acquire a WriteAccess for |
[in] | size | the new size of the LAMA array |
[in] | keep | if false, implicit clear, old values of the array are no more needed |
Exception | if the WriteAccess can not be acquired, e.g. because another WriteAccess exists. |
If the keep flag is set to false, no valid data must be transferred between different devices and it is no memory copy needed in case of a reallocation.
WriteAccess wData( context, data, 100, false ); // same as data.clear(); WriteAccess wData( context, data ); wData.resize( size ); // better than this solution that might still have transfers WriteAccess wData( context, data ); wData.clear(); wData.resize( size );
Attention: this kind of write access assumes that the array is completely new written.
References lama::LAMAArrayView< T >::acquireWriteAccess(), lama::LAMAArrayView< T >::clear(), lama::LAMAArrayView< T >::get(), lama::WriteAccess< T >::mArrayView, lama::WriteAccess< T >::mData, lama::WriteAccess< T >::mIndex, and lama::LAMAArrayView< T >::resize().
lama::WriteAccess< T >::WriteAccess | ( | LAMAArray< ValueType > & | array | ) | [explicit] |
acquire a WriteAccess to the passed LAMAArray for a valid context.
[in] | array | the LAMAArray to acquire a WriteAccess for |
Exception | if the WriteAccess can not be acquired, e.g. because another WriteAccess exists. |
This constructor acquires a WriteAccess to the passed LAMAArray for a valid location. The chosen Location will be the first valid location. This Access can be used to call, e.g. resize. If it does not matter where the data currently resides.
References lama::LAMAArrayView< T >::acquireWriteAccess(), lama::LAMAArrayView< T >::get(), lama::WriteAccess< T >::mArrayView, lama::WriteAccess< T >::mData, and lama::WriteAccess< T >::mIndex.
lama::WriteAccess< T >::WriteAccess | ( | LAMAArrayView< ValueType > & | view, |
ContextPtr | context, | ||
const bool | keep = true |
||
) |
lama::WriteAccess< T >::WriteAccess | ( | LAMAArrayView< ValueType > & | view, |
ContextPtr | context, | ||
const IndexType | size, | ||
const bool | keep = true |
||
) |
lama::WriteAccess< T >::~WriteAccess | ( | ) | [virtual] |
Releases the WriteAccess on the associated LAMAArray.
IndexType lama::WriteAccess< T >::capacity | ( | ) | const |
query the capacity of the array on the reserved context
References LAMA_ASSERT_ERROR.
Referenced by lama::Communicator::shift().
void lama::WriteAccess< T >::clear | ( | ) |
Set the size of the LAMAArray to 0.
This operation only sets the size but does not free any reserved memory.
This operation should always be called when an array is completely rewritten. to avoid that data will be transfered from other locations or copying of old values during the resize.
LAMAArray& arr = ... arr.clear(); HostWriteAccess writeArr( arr ); writeArr.resize( 100 ); for ( int i = 0; i < 100; i++) { writeArr[i] = 0.0; }
References LAMA_ASSERT_ERROR.
Referenced by lama::Communicator::exchangeByPlan(), and lama::_MatrixStorage::offsets2sizes().
T * lama::WriteAccess< T >::get | ( | ) |
returns a pointer to the data of the wrapped LAMAArray
References LAMA_THROWEXCEPTION.
Referenced by lama::JDSStorage< T >::allocate(), lama::CSRStorage< T >::allocate(), lama::CommunicationPlan::allocateTranspose(), lama::DenseStorageView< T >::assignDenseStorageImpl(), lama::LAMAArrayUtils::assignImpl2(), lama::HaloBuilder::build(), lama::COOStorage< T >::buildCSR(), lama::ELLStorage< T >::buildCSR(), lama::JDSStorage< T >::buildCSR(), lama::DIAStorage< T >::buildCSR(), lama::DenseStorageView< T >::buildCSR(), lama::SparseAssemblyStorage< T >::buildCSR(), lama::CSRStorage< T >::buildCSR(), lama::ELLStorage< T >::buildRowIndexes(), lama::CSRStorage< T >::buildRowIndexes(), lama::ELLStorage< T >::compress(), lama::LUSolver::computeLUFactorization(), lama::Communicator::computeOwners(), lama::MatrixStorage< T >::convertCSR2CSC(), lama::DenseStorage< T >::DenseStorage(), lama::ELLStorage< T >::ELLStorage(), lama::Communicator::exchangeByPlan(), lama::StorageMethods< T >::exchangeHaloCSR(), lama::LAMAArrayUtils::gather(), lama::COOStorage< T >::getDiagonalImpl(), lama::ELLStorage< T >::getDiagonalImpl(), lama::CSRStorage< T >::getDiagonalImpl(), lama::DenseStorageView< T >::getDiagonalImpl(), lama::DIAStorage< T >::getDiagonalImpl(), lama::JDSStorage< T >::getDiagonalImpl(), lama::ELLStorage< T >::getRowImpl(), lama::JDSStorage< T >::getRowImpl(), lama::DenseVector< T >::invert(), lama::DenseMatrixOps::invertCyclic(), lama::DenseMatrix< T >::invertCyclic(), lama::DenseStorageView< T >::invertDense(), lama::JDSStorage< T >::jacobiIterate(), lama::DIAStorage< T >::jacobiIterate(), lama::COOStorage< T >::jacobiIterate(), lama::ELLStorage< T >::jacobiIterate(), lama::CSRStorage< T >::jacobiIterate(), lama::JDSStorage< T >::jacobiIterateHalo(), lama::ELLStorage< T >::jacobiIterateHalo(), lama::CSRStorage< T >::jacobiIterateHalo(), lama::JDSStorage< T >::JDSStorage(), lama::MatrixStorage< T >::joinRows(), lama::StorageMethods< T >::localizeCSR(), lama::CSRStorage< T >::matrixAddMatrixCSR(), lama::ELLStorage< T >::matrixAddMatrixELL(), lama::CSRStorage< T >::matrixTimesMatrixCSR(), lama::DenseStorageView< T >::matrixTimesMatrixDense(), lama::ELLStorage< T >::matrixTimesMatrixELL(), lama::JDSStorage< T >::matrixTimesVector(), lama::DIAStorage< T >::matrixTimesVector(), lama::DenseStorageView< T >::matrixTimesVector(), lama::COOStorage< T >::matrixTimesVector(), lama::ELLStorage< T >::matrixTimesVector(), lama::CSRStorage< T >::matrixTimesVector(), lama::CSRStorage< T >::matrixTimesVectorN(), lama::LUSolver::plaswp(), lama::LUSolver::ptrsm(), lama::StorageIO< T >::readCSRFromBinaryFile(), lama::StorageIO< T >::readCSRFromMMFile(), lama::StorageIO< T >::readCSRFromXDRFile(), lama::DenseVector< T >::readVectorDataFromBinaryFile(), lama::DenseVector< T >::redistribute(), lama::StorageMethods< T >::redistributeCSR(), lama::StorageMethods< T >::replicateCSR(), lama::ELLStorage< T >::scaleImpl(), lama::CSRStorage< T >::scaleImpl(), lama::JDSStorage< T >::scaleImpl(), lama::DenseStorageView< T >::scaleImpl(), lama::DenseStorageView< T >::setCSRDataImpl(), lama::CSRStorage< T >::setCSRDataImpl(), lama::COOStorage< T >::setCSRDataImpl(), lama::JDSStorage< T >::setCSRDataImpl(), lama::ELLStorage< T >::setCSRDataImpl(), lama::COOStorage< T >::setDiagonalImpl(), lama::ELLStorage< T >::setDiagonalImpl(), lama::CSRStorage< T >::setDiagonalImpl(), lama::JDSStorage< T >::setDiagonalImpl(), lama::DenseStorageView< T >::setDiagonalImpl(), lama::DIAStorage< T >::setDiagonalImpl(), lama::DenseStorageView< T >::setIdentity(), lama::COOStorage< T >::setIdentity(), lama::ELLStorage< T >::setIdentity(), lama::CSRStorage< T >::setIdentity(), lama::JDSStorage< T >::setIdentity(), lama::DIAStorage< T >::setIdentity(), lama::JDSStorage< T >::setupData(), lama::DenseStorageView< T >::setZero(), lama::Communicator::shift(), lama::JDSStorage< T >::sortRows(), lama::StorageMethods< T >::splitCSR(), and lama::DenseVector< T >::vectorPlusVector().
lama::WriteAccess< T >::LAMA_LOG_DECL_STATIC_LOGGER | ( | logger | ) | [protected] |
void lama::WriteAccess< T >::release | ( | ) | [virtual] |
Releases the WriteAccess on the associated LAMAArray.
Implements lama::BaseAccess.
References lama::max().
Referenced by lama::CommunicationPlan::allocateTranspose(), lama::HaloBuilder::build(), lama::CSRStorage< T >::compress(), lama::LUSolver::computeLUFactorization(), lama::Communicator::computeOwners(), lama::LUSolver::pgetf2(), lama::CSRStorage< T >::setCSRDataImpl(), lama::DenseVector< T >::updateHalo(), and lama::DenseVector< T >::updateHaloAsync().
void lama::WriteAccess< T >::reserve | ( | const IndexType | capacity | ) |
reserve storage for wth wrapped LAMAArray at the associated location
[in] | capacity | the number of elements that should fit into the new storage |
References LAMA_ASSERT_ERROR.
Referenced by lama::SparseMatrix< T >::setComputeKind(), lama::DenseVector< T >::updateHalo(), and lama::DenseVector< T >::updateHaloAsync().
void lama::WriteAccess< T >::resize | ( | const IndexType | newSize | ) |
resizes the wrapped LAMAArray
[in] | newSize | the new size of the wrapped LAMAArray |
If a reallocation is necessary it is only done at the associated location for all other locations this is done lazy.
References LAMA_ASSERT_ERROR.
Referenced by lama::DenseVector< T >::assign(), lama::HaloBuilder::build(), lama::COOStorage< T >::buildCSR(), lama::ELLStorage< T >::buildCSR(), lama::JDSStorage< T >::buildCSR(), lama::DIAStorage< T >::buildCSR(), lama::DenseStorageView< T >::buildCSR(), lama::SparseAssemblyStorage< T >::buildCSR(), lama::MatrixCreator< T >::buildPoisson(), lama::Communicator::exchangeByPlan(), lama::StorageMethods< T >::exchangeHaloCSR(), lama::MatrixStorage< T >::joinRows(), lama::DenseMatrix< T >::matrixTimesVectorImpl(), lama::SparseMatrix< T >::matrixTimesVectorImpl(), lama::_MatrixStorage::offsets2sizes(), lama::DenseVector< T >::readVectorFromXDRFile(), lama::StorageMethods< T >::redistributeCSR(), lama::Redistributor::Redistributor(), lama::DenseVector< T >::resizeImpl(), lama::ELLStorage< T >::setCSRDataImpl(), lama::Communicator::shift(), lama::_MatrixStorage::sizes2offsets(), and lama::LUSolver::solve().
IndexType lama::WriteAccess< T >::size | ( | ) | const [inline] |
Returns the size of the wrapped LAMAArray.
References LAMA_THROWEXCEPTION.
Referenced by lama::LUSolver::computeLUFactorization(), lama::MatrixStorage< T >::joinRows(), lama::Redistributor::Redistributor(), lama::ELLStorage< T >::setCSRDataImpl(), and lama::DIAStorage< T >::setOffsets().
void lama::WriteAccess< T >::writeAt | ( | std::ostream & | stream | ) | const [virtual] |
Writes some Information about this to the passed stream.
If a deriving class does not overrides writeAt, typeid(this).name() is written to stream.
[out] | stream | the stream to write to. |
Reimplemented from lama::BaseAccess.
LAMAArrayView<ValueType>* lama::WriteAccess< T >::mArrayView [protected] |
Referenced by lama::WriteAccess< T >::WriteAccess().
ValueType* lama::WriteAccess< T >::mData [protected] |
Referenced by lama::WriteAccess< T >::WriteAccess().
size_t lama::WriteAccess< T >::mIndex [protected] |
Referenced by lama::WriteAccess< T >::WriteAccess().