iterative-solver 0.0
molpro::linalg::array::util::BufferManager< T > Class Template Reference

BufferManager provides single-buffered or asynchronous double-buffered read access to the data in a collection of DistrArray objects. At construction, an amount of memory is allocated as a buffer, and the buffer is divided into one or more chunks that are independent windows on the data. Sequential access to the data is provided through iterators. More...

#include <BufferManager.h>

Detailed Description

template<class T>
class molpro::linalg::array::util::BufferManager< T >

BufferManager provides single-buffered or asynchronous double-buffered read access to the data in a collection of DistrArray objects. At construction, an amount of memory is allocated as a buffer, and the buffer is divided into one or more chunks that are independent windows on the data. Sequential access to the data is provided through iterators.

Template Parameters
Ta class that inherits from DistrArray

Classes

struct  Iterator
 Custom iterator for the BufferManager. This iterator is responsible for loading data into the buffers and providing access to that data. More...
 

Public Member Functions

 BufferManager (const CVecRef &arrays, size_t buffer_size=8192, int number_of_buffers=2)
 Construct a new Buffer Manager object and allocate memory for the chunks. More...
 
 BufferManager (const std::vector< T > &arrays, size_t buffer_size=8192, int number_of_buffers=2)
 
 BufferManager (const T &array, size_t buffer_size=8192, int number_of_buffers=2)
 
size_t buffer_size () const
 
size_t buffer_stride () const
 
size_t buffer_offset () const
 
Iterator begin ()
 
Iterator end ()
 

Protected Types

using value_type = typename T::value_type
 

Protected Member Functions

Span< value_typenext (bool initial=false)
 Move to the next segment of the arrays and complete loading of the buffer. More...
 

Protected Attributes

const CVecRef & m_arrays
 
const size_t m_buffer_size = 8192
 
const int m_number_of_buffers = 2
 
size_t m_current_buffer_size
 
size_t m_current_segment = 0
 
const std::pair< size_t, size_t > m_range
 
std::vector< typename T::value_type > m_buffer
 
std::future< void > m_read_future
 

Member Typedef Documentation

◆ value_type

template<class T >
using molpro::linalg::array::util::BufferManager< T >::value_type = typename T::value_type
protected

Constructor & Destructor Documentation

◆ BufferManager() [1/3]

template<class T >
molpro::linalg::array::util::BufferManager< T >::BufferManager ( const CVecRef &  arrays,
size_t  buffer_size = 8192,
int  number_of_buffers = 2 
)
inline

Construct a new Buffer Manager object and allocate memory for the chunks.

Parameters
arraysthe DistrArray objects that this BufferManager will access data from. They must have the same distribution.
buffer_sizenumber of array elements in each chunk.
number_of_buffershow many buffers.

◆ BufferManager() [2/3]

template<class T >
molpro::linalg::array::util::BufferManager< T >::BufferManager ( const std::vector< T > &  arrays,
size_t  buffer_size = 8192,
int  number_of_buffers = 2 
)
inline

◆ BufferManager() [3/3]

template<class T >
molpro::linalg::array::util::BufferManager< T >::BufferManager ( const T &  array,
size_t  buffer_size = 8192,
int  number_of_buffers = 2 
)
inline

Member Function Documentation

◆ begin()

template<class T >
Iterator molpro::linalg::array::util::BufferManager< T >::begin ( )
inline

◆ buffer_offset()

template<class T >
size_t molpro::linalg::array::util::BufferManager< T >::buffer_offset ( ) const
inline

Offset of the current buffer

Returns

◆ buffer_size()

template<class T >
size_t molpro::linalg::array::util::BufferManager< T >::buffer_size ( ) const
inline

The current buffer size

Returns

◆ buffer_stride()

template<class T >
size_t molpro::linalg::array::util::BufferManager< T >::buffer_stride ( ) const
inline

The distance between buffers

Returns

◆ end()

template<class T >
Iterator molpro::linalg::array::util::BufferManager< T >::end ( )
inline

◆ next()

template<class T >
Span< value_type > molpro::linalg::array::util::BufferManager< T >::next ( bool  initial = false)
inlineprotected

Move to the next segment of the arrays and complete loading of the buffer.

Parameters
initialwhether this is the first iteration
Returns
the buffer contents for the new segment

Member Data Documentation

◆ m_arrays

template<class T >
const CVecRef& molpro::linalg::array::util::BufferManager< T >::m_arrays
protected

◆ m_buffer

template<class T >
std::vector<typename T::value_type> molpro::linalg::array::util::BufferManager< T >::m_buffer
protected

◆ m_buffer_size

template<class T >
const size_t molpro::linalg::array::util::BufferManager< T >::m_buffer_size = 8192
protected

◆ m_current_buffer_size

template<class T >
size_t molpro::linalg::array::util::BufferManager< T >::m_current_buffer_size
protected

◆ m_current_segment

template<class T >
size_t molpro::linalg::array::util::BufferManager< T >::m_current_segment = 0
protected

◆ m_number_of_buffers

template<class T >
const int molpro::linalg::array::util::BufferManager< T >::m_number_of_buffers = 2
protected

◆ m_range

template<class T >
const std::pair<size_t, size_t> molpro::linalg::array::util::BufferManager< T >::m_range
protected

◆ m_read_future

template<class T >
std::future<void> molpro::linalg::array::util::BufferManager< T >::m_read_future
protected