LAMA
lama::WriteAccess< T > Class Template Reference

The Template WriteAccess is used to enforce the consistency of the template LAMAArray. More...

#include <WriteAccess.hpp>

Inheritance diagram for lama::WriteAccess< T >:

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

ValueTypemData
LAMAArrayView< ValueType > * mArrayView
size_t mIndex

Detailed Description

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

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.


Member Typedef Documentation

template<typename T>
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 >.


Constructor & Destructor Documentation

template<typename T >
lama::WriteAccess< T >::WriteAccess ( LAMAArray< ValueType > &  array,
ContextPtr  context 
)

acquire a WriteAccess to the passed LAMAArray for the passed location

Parameters:
[in]arraythe LAMAArray to acquire a WriteAccess for
[in]contextthe context to acquire a WriteAccess for
Exceptions:
Exceptionif 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.

template<typename T >
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

Parameters:
[in]arraythe LAMAArray to acquire a WriteAccess for
[in]contextthe context to acquire a WriteAccess for
[in]sizethe new size of the LAMA array
[in]keepif false, implicit clear, old values of the array are no more needed
Exceptions:
Exceptionif 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().

template<typename T >
lama::WriteAccess< T >::WriteAccess ( LAMAArray< ValueType > &  array) [explicit]

acquire a WriteAccess to the passed LAMAArray for a valid context.

Parameters:
[in]arraythe LAMAArray to acquire a WriteAccess for
Exceptions:
Exceptionif 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.

template<typename T >
lama::WriteAccess< T >::~WriteAccess ( ) [virtual]

Releases the WriteAccess on the associated LAMAArray.


Member Function Documentation

template<typename T >
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().

template<typename T >
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().

template<typename T >
T * lama::WriteAccess< T >::get ( )

returns a pointer to the data of the wrapped LAMAArray

Returns:
a pointer to 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().

template<typename T>
lama::WriteAccess< T >::LAMA_LOG_DECL_STATIC_LOGGER ( logger  ) [protected]
template<typename T >
void lama::WriteAccess< T >::reserve ( const IndexType  capacity)

reserve storage for wth wrapped LAMAArray at the associated location

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

template<typename T >
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.

Parameters:
[out]streamthe stream to write to.

Reimplemented from lama::BaseAccess.


Field Documentation

template<typename T>
LAMAArrayView<ValueType>* lama::WriteAccess< T >::mArrayView [protected]
template<typename T>
ValueType* lama::WriteAccess< T >::mData [protected]
template<typename T>
size_t lama::WriteAccess< T >::mIndex [protected]

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