COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
Public Types | Public Member Functions | Private Attributes | List of all members
Buffer Class Reference

Buffer that can hold multiple data types, useful for MPI communication. More...

#include <Buffer.hpp>

Public Types

typedef char * iterator
 

Public Member Functions

const char * buffer () const
 access to the internal buffer More...
 
void * buffer ()
 
int capacity () const
 Allocated memory. More...
 
int size () const
 Size of valid parts of buffer. More...
 
int unpacked_idx () const
 Unpacked memory. More...
 
int & unpacked_idx ()
 Unpacked memory. More...
 
bool more_to_unpack () const
 Tell if everything is unpacked. More...
 
void reserve (const Uint size)
 reserve the buffer to fit memory "size". The buffer gets allocated bigger than necessary in order to reduce future resizes. More...
 
void resize (const Uint size)
 resize the buffer to fit memory "size". The buffer gets resized bigger than necessary in order to reduce future resizes. More...
 
void reset ()
 reset the buffer, without resizing More...
 
int mark_pid_start ()
 Create a separation, defining different parts of the buffer This is useful for parallel communication, so that you can avoid the use of std::vector<PE::Buffer> in e.g. all_to_all communication. More...
 
std::vector< int > & strides ()
 
std::vector< int > & displs ()
 
const std::vector< int > & strides () const
 
const std::vector< int > & displs () const
 
const iterator begin () const
 begin iterator More...
 
const iterator end () const
 end iterator More...
 
template<>
void pack (const bool *data, const Uint data_size)
 pack specialization for bool More...
 
template<>
void unpack (bool *data, const Uint data_size)
 unpack specialization for bool More...
 
Constructor/Destructor
 Buffer (const Uint size=0u)
 Constructor. More...
 
virtual ~Buffer ()
 Destructor, deallocates internal buffer. More...
 
Pack/Unpackfunctions for POD arrays
template<typename T >
void pack (const T *data, const Uint data_size)
 Pack data in the buffer. The data must be POD (plain old data). More...
 
template<class T >
void unpack (T *data, const Uint data_size)
 Unpack data in the buffer. The data must be POD (plain old data). More...
 
Pack/Unpack functions for POD
void pack (const bool &data)
 
void pack (const char &data)
 
void pack (const unsigned char &data)
 
void pack (const short &data)
 
void pack (const unsigned short &data)
 
void pack (const int &data)
 
void pack (const unsigned int &data)
 
void pack (const long &data)
 
void pack (const unsigned long &data)
 
void pack (const long long &data)
 
void pack (const unsigned long long &data)
 
void pack (const float &data)
 
void pack (const double &data)
 
void pack (const long double &data)
 
void pack (const std::string &data)
 
void pack (const bool *data)
 
void pack (const char *data)
 
void pack (const unsigned char *data)
 
void pack (const short *data)
 
void pack (const unsigned short *data)
 
void pack (const int *data)
 
void pack (const unsigned int *data)
 
void pack (const long *data)
 
void pack (const unsigned long *data)
 
void pack (const long long *data)
 
void pack (const unsigned long long *data)
 
void pack (const float *data)
 
void pack (const double *data)
 
void pack (const long double *data)
 
void pack (const std::string *data)
 
void unpack (bool &data)
 
void unpack (char &data)
 
void unpack (unsigned char &data)
 
void unpack (short &data)
 
void unpack (unsigned short &data)
 
void unpack (int &data)
 
void unpack (unsigned int &data)
 
void unpack (long &data)
 
void unpack (unsigned long &data)
 
void unpack (long long &data)
 
void unpack (unsigned long long &data)
 
void unpack (float &data)
 
void unpack (double &data)
 
void unpack (long double &data)
 
void unpack (std::string &data)
 
void unpack (bool *data)
 
void unpack (char *data)
 
void unpack (unsigned char *data)
 
void unpack (short *data)
 
void unpack (unsigned short *data)
 
void unpack (int *data)
 
void unpack (unsigned int *data)
 
void unpack (long *data)
 
void unpack (unsigned long *data)
 
void unpack (long long *data)
 
void unpack (unsigned long long *data)
 
void unpack (float *data)
 
void unpack (double *data)
 
void unpack (long double *data)
 
void unpack (std::string *data)
 
Pack/Unpack of some container types
template<typename T >
void pack (const std::vector< T > &data)
 
template<class T >
void unpack (std::vector< T > &data)
 
template<typename T >
void pack (boost::detail::multi_array::sub_array< T, 1 > data)
 
template<typename T >
void pack (const boost::detail::multi_array::const_sub_array< T, 1, T const * > &data)
 
template<typename T >
void unpack (boost::detail::multi_array::sub_array< T, 1 > data)
 
MPI collective operations
void broadcast (const Uint root)
 Broadcast the buffer from the root process. More...
 
void all_gather (Buffer &recv)
 All Gather collective operation for buffers. More...
 
void all_to_all (Buffer &recv)
 All To All collective operation for buffers. More...
 

Private Attributes

char * m_buffer
 internal buffer More...
 
int m_capacity
 allocated memory in buffer More...
 
int m_size
 packed memory in buffer More...
 
int m_unpacked_idx
 unpacked memory in buffer More...
 
std::vector< int > m_displs
 markers for separation More...
 
std::vector< int > m_strides
 

Detailed Description

Buffer that can hold multiple data types, useful for MPI communication.

Buffer can be packed repetitively, with different data types. The size of the buffer grows automatically The buffer can be unpacked repetitively. Knowledge of every unpacked type must be known.

Author
Willem Deconinck

Definition at line 34 of file Buffer.hpp.

Member Typedef Documentation

typedef char* iterator

Definition at line 37 of file Buffer.hpp.

Constructor & Destructor Documentation

Buffer ( const Uint  size = 0u)
inline

Constructor.

Definition at line 42 of file Buffer.hpp.

virtual ~Buffer ( )
inlinevirtual

Destructor, deallocates internal buffer.

Definition at line 52 of file Buffer.hpp.

Member Function Documentation

void all_gather ( Buffer recv)
inline

All Gather collective operation for buffers.

The received buffer contains all sent buffers from all ranks

Parameters
[out]recvoutput buffer

Definition at line 483 of file Buffer.hpp.

void all_to_all ( PE::Buffer recv)
inline

All To All collective operation for buffers.

Precondition
This buffer needs to have separations inserted for each pid, to mark chunks that need to be sent to each pid.

The received buffer contains those chunks from the sent buffer, that were marked for the receiving pid.

Parameters
[out]recvoutput buffer

Definition at line 509 of file Buffer.hpp.

const iterator begin ( ) const
inline

begin iterator

Definition at line 107 of file Buffer.hpp.

void broadcast ( const Uint  root)
inline

Broadcast the buffer from the root process.

The buffer on all receiving ranks gets resized and overwritten with the buffer from the broadcasting rank.

Parameters
[in]rootThe broadcasting rank

Definition at line 464 of file Buffer.hpp.

const char* buffer ( ) const
inline

access to the internal buffer

Definition at line 59 of file Buffer.hpp.

void* buffer ( )
inline

Definition at line 61 of file Buffer.hpp.

int capacity ( ) const
inline

Allocated memory.

Definition at line 64 of file Buffer.hpp.

std::vector<int>& displs ( )
inline

Definition at line 102 of file Buffer.hpp.

const std::vector<int>& displs ( ) const
inline

Definition at line 104 of file Buffer.hpp.

const iterator end ( ) const
inline

end iterator

Definition at line 110 of file Buffer.hpp.

int mark_pid_start ( )
inline

Create a separation, defining different parts of the buffer This is useful for parallel communication, so that you can avoid the use of std::vector<PE::Buffer> in e.g. all_to_all communication.

Definition at line 301 of file Buffer.hpp.

bool more_to_unpack ( ) const
inline

Tell if everything is unpacked.

Definition at line 80 of file Buffer.hpp.

void pack ( const T *  data,
const Uint  data_size 
)
inline

Pack data in the buffer. The data must be POD (plain old data).

Parameters
[in]datadata array
[in]data_sizenumber of elements in the array. (data_size=1 in case the data is not an array)

Definition at line 311 of file Buffer.hpp.

void pack ( const bool &  data)
inline

Definition at line 405 of file Buffer.hpp.

void pack ( const char &  data)
inline

Definition at line 130 of file Buffer.hpp.

void pack ( const unsigned char &  data)
inline

Definition at line 131 of file Buffer.hpp.

void pack ( const short &  data)
inline

Definition at line 132 of file Buffer.hpp.

void pack ( const unsigned short &  data)
inline

Definition at line 133 of file Buffer.hpp.

void pack ( const int &  data)
inline

Definition at line 134 of file Buffer.hpp.

void pack ( const unsigned int &  data)
inline

Definition at line 135 of file Buffer.hpp.

void pack ( const long &  data)
inline

Definition at line 136 of file Buffer.hpp.

void pack ( const unsigned long &  data)
inline

Definition at line 137 of file Buffer.hpp.

void pack ( const long long &  data)
inline

Definition at line 138 of file Buffer.hpp.

void pack ( const unsigned long long &  data)
inline

Definition at line 139 of file Buffer.hpp.

void pack ( const float &  data)
inline

Definition at line 140 of file Buffer.hpp.

void pack ( const double &  data)
inline

Definition at line 141 of file Buffer.hpp.

void pack ( const long double &  data)
inline

Definition at line 142 of file Buffer.hpp.

void pack ( const std::string &  data)
inline

Definition at line 440 of file Buffer.hpp.

void pack ( const bool *  data)
inline

Definition at line 406 of file Buffer.hpp.

void pack ( const char *  data)
inline

Definition at line 146 of file Buffer.hpp.

void pack ( const unsigned char *  data)
inline

Definition at line 147 of file Buffer.hpp.

void pack ( const short *  data)
inline

Definition at line 148 of file Buffer.hpp.

void pack ( const unsigned short *  data)
inline

Definition at line 149 of file Buffer.hpp.

void pack ( const int *  data)
inline

Definition at line 150 of file Buffer.hpp.

void pack ( const unsigned int *  data)
inline

Definition at line 151 of file Buffer.hpp.

void pack ( const long *  data)
inline

Definition at line 152 of file Buffer.hpp.

void pack ( const unsigned long *  data)
inline

Definition at line 153 of file Buffer.hpp.

void pack ( const long long *  data)
inline

Definition at line 154 of file Buffer.hpp.

void pack ( const unsigned long long *  data)
inline

Definition at line 155 of file Buffer.hpp.

void pack ( const float *  data)
inline

Definition at line 156 of file Buffer.hpp.

void pack ( const double *  data)
inline

Definition at line 157 of file Buffer.hpp.

void pack ( const long double *  data)
inline

Definition at line 158 of file Buffer.hpp.

void pack ( const std::string *  data)
inline

Definition at line 441 of file Buffer.hpp.

void pack ( const std::vector< T > &  data)
inline

Definition at line 350 of file Buffer.hpp.

void pack ( boost::detail::multi_array::sub_array< T, 1 >  data)
inline

Definition at line 370 of file Buffer.hpp.

void pack ( const boost::detail::multi_array::const_sub_array< T, 1, T const * > &  data)
inline

Definition at line 387 of file Buffer.hpp.

void pack ( const bool *  data,
const Uint  data_size 
)
inline

pack specialization for bool

Definition at line 397 of file Buffer.hpp.

void reserve ( const Uint  size)
inline

reserve the buffer to fit memory "size". The buffer gets allocated bigger than necessary in order to reduce future resizes.

Definition at line 266 of file Buffer.hpp.

void reset ( )
inline

reset the buffer, without resizing

This is useful to reuse an already allocated buffer.

Definition at line 291 of file Buffer.hpp.

void resize ( const Uint  size)
inline

resize the buffer to fit memory "size". The buffer gets resized bigger than necessary in order to reduce future resizes.

Postcondition
Calling pack() afterwards, will grow the buffer and push_back

Definition at line 283 of file Buffer.hpp.

int size ( ) const
inline

Size of valid parts of buffer.

Definition at line 67 of file Buffer.hpp.

std::vector<int>& strides ( )
inline

Definition at line 101 of file Buffer.hpp.

const std::vector<int>& strides ( ) const
inline

Definition at line 103 of file Buffer.hpp.

void unpack ( T *  data,
const Uint  data_size 
)
inline

Unpack data in the buffer. The data must be POD (plain old data).

Parameters
[out]datadata array
[in]data_sizenumber of elements in the array. (data_size=1 in case the data is not an array)

Definition at line 335 of file Buffer.hpp.

void unpack ( bool &  data)
inline

Definition at line 422 of file Buffer.hpp.

void unpack ( char &  data)
inline

Definition at line 162 of file Buffer.hpp.

void unpack ( unsigned char &  data)
inline

Definition at line 163 of file Buffer.hpp.

void unpack ( short &  data)
inline

Definition at line 164 of file Buffer.hpp.

void unpack ( unsigned short &  data)
inline

Definition at line 165 of file Buffer.hpp.

void unpack ( int &  data)
inline

Definition at line 166 of file Buffer.hpp.

void unpack ( unsigned int &  data)
inline

Definition at line 167 of file Buffer.hpp.

void unpack ( long &  data)
inline

Definition at line 168 of file Buffer.hpp.

void unpack ( unsigned long &  data)
inline

Definition at line 169 of file Buffer.hpp.

void unpack ( long long &  data)
inline

Definition at line 170 of file Buffer.hpp.

void unpack ( unsigned long long &  data)
inline

Definition at line 171 of file Buffer.hpp.

void unpack ( float &  data)
inline

Definition at line 172 of file Buffer.hpp.

void unpack ( double &  data)
inline

Definition at line 173 of file Buffer.hpp.

void unpack ( long double &  data)
inline

Definition at line 174 of file Buffer.hpp.

void unpack ( std::string &  data)
inline

Definition at line 459 of file Buffer.hpp.

void unpack ( bool *  data)
inline

Definition at line 423 of file Buffer.hpp.

void unpack ( char *  data)
inline

Definition at line 178 of file Buffer.hpp.

void unpack ( unsigned char *  data)
inline

Definition at line 179 of file Buffer.hpp.

void unpack ( short *  data)
inline

Definition at line 180 of file Buffer.hpp.

void unpack ( unsigned short *  data)
inline

Definition at line 181 of file Buffer.hpp.

void unpack ( int *  data)
inline

Definition at line 182 of file Buffer.hpp.

void unpack ( unsigned int *  data)
inline

Definition at line 183 of file Buffer.hpp.

void unpack ( long *  data)
inline

Definition at line 184 of file Buffer.hpp.

void unpack ( unsigned long *  data)
inline

Definition at line 185 of file Buffer.hpp.

void unpack ( long long *  data)
inline

Definition at line 186 of file Buffer.hpp.

void unpack ( unsigned long long *  data)
inline

Definition at line 187 of file Buffer.hpp.

void unpack ( float *  data)
inline

Definition at line 188 of file Buffer.hpp.

void unpack ( double *  data)
inline

Definition at line 189 of file Buffer.hpp.

void unpack ( long double *  data)
inline

Definition at line 190 of file Buffer.hpp.

void unpack ( std::string *  data)
inline

Definition at line 460 of file Buffer.hpp.

void unpack ( std::vector< T > &  data)
inline

Definition at line 359 of file Buffer.hpp.

void unpack ( boost::detail::multi_array::sub_array< T, 1 >  data)
inline

Definition at line 377 of file Buffer.hpp.

void unpack ( bool *  data,
const Uint  data_size 
)
inline

unpack specialization for bool

Definition at line 412 of file Buffer.hpp.

int unpacked_idx ( ) const
inline

Unpacked memory.

Remains to unpack = packed - unpacked

Definition at line 72 of file Buffer.hpp.

int& unpacked_idx ( )
inline

Unpacked memory.

Remains to unpack = packed - unpacked

Definition at line 77 of file Buffer.hpp.

Member Data Documentation

char* m_buffer
private

internal buffer

Definition at line 247 of file Buffer.hpp.

int m_capacity
private

allocated memory in buffer

Definition at line 250 of file Buffer.hpp.

std::vector<int> m_displs
private

markers for separation

Definition at line 259 of file Buffer.hpp.

int m_size
private

packed memory in buffer

Definition at line 253 of file Buffer.hpp.

std::vector<int> m_strides
private

Definition at line 260 of file Buffer.hpp.

int m_unpacked_idx
private

unpacked memory in buffer

Definition at line 256 of file Buffer.hpp.


The documentation for this class was generated from the following file:
Send comments to:
COOLFluiD Web Admin