walberla::mpi::GenericRecvBuffer< T > Class Template Reference

Detailed Description

template<typename T = unsigned char>
class walberla::mpi::GenericRecvBuffer< T >

Implementation of a MPI receive buffer.

The RecvBuffer class is a special purpose implementation for the MPI communication functionality. It offers a convenient and safe access to the received data values even for mixed-type communication. The following example gives an impression of the usage of the RecvBuffer class:

using namespace mpi;
// Preparing a receive buffer for an incoming message of 32 bytes
RecvBuffer buffer;
buffer.resize( 32 );
// Receiving a MPI message from process 0 in a blocking MPI_Recv() function
MPI_Status status;
MPI_Recv( buffer.ptr(), 32, MPI_BYTE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, status );
// Extracting a double and an integer from the buffer
double d;
int i;
buffer >> d >> i;

For another example see also the Buffer Unit Test in File BufferTest.cpp

Note that the order of data values in the receive buffer is depending on the message sent via MPI. See also the SendBuffer class description for the sender side of the MPI communication.

#include <RecvBuffer.h>

Public Types

typedef T ElementType
 Type of the receive buffer elements. More...
 

Public Member Functions

template<typename G >
GenericRecvBuffer< T > & operator= (const GenericSendBuffer< T, G > &sb)
 
Constructors
 GenericRecvBuffer ()
 Standard constructor for RecvBuffer. More...
 
 GenericRecvBuffer (const GenericRecvBuffer &rb)
 Copy constructor for RecvBuffer. More...
 
template<typename G >
 GenericRecvBuffer (GenericSendBuffer< T, G > &sb)
 Constructor for RecvBuffer. More...
 
Destructor
 ~GenericRecvBuffer ()
 Destructor for RecvBuffer. More...
 
Assignment operator
GenericRecvBufferoperator= (const GenericRecvBuffer &sb)
 Copy assignment operator for RecvBuffer. More...
 
template<typename G >
GenericRecvBufferoperator= (const GenericSendBuffer< T, G > &sb)
 
Get functions
size_t maxSize () const
 Returns the maximum possible size of the receive buffer. More...
 
size_t size () const
 Returns the current size of the receive buffer. More...
 
size_t capacity () const
 Returns the capacity of the receive buffer. More...
 
bool isEmpty () const
 Returns true if the receive buffer is empty. More...
 
Operators
template<typename V >
std::enable_if< std::is_arithmetic< V >::value||std::is_enum< V >::value, GenericRecvBuffer & >::type operator>> (V &value)
 Reads a built-in data value from the receive buffer. More...
 

Private Attributes

Member variables
size_t capacity_
 The current size of the receive buffer. More...
 
T * begin_
 Pointer to the first element of the receive buffer. More...
 
T * cur_
 Pointer to the current element of the receive buffer. More...
 
T * end_
 Pointer to the last element of the receive buffer. More...
 

Utility functions

T * ptr () const
 Returns a pointer to the first element of the receive buffer. More...
 
void reserve (size_t newCapacity)
 Setting the minimum capacity of the receive buffer. More...
 
void resize (size_t newSize)
 Changing the size of the receive buffer. More...
 
template<typename V >
void peek (V &value) const
 Reads a built-in data value from the receive buffer without extracting it. More...
 
T * skip (size_t elements)
 Skipping the given number of elements. More...
 
void clear ()
 Clearing the receive buffer. More...
 
void reset ()
 Clearing the receive buffer. More...
 
void readDebugMarker (const char *marker)
 Reads debug marker and raises assert when marker does not match. More...
 
template<typename V >
std::enable_if< std::is_arithmetic< V >::value||std::is_enum< V >::value, GenericRecvBuffer & >::type get (V &value)
 Implements operator>> without debugging system. More...
 

Member Typedef Documentation

◆ ElementType

template<typename T = unsigned char>
typedef T walberla::mpi::GenericRecvBuffer< T >::ElementType

Type of the receive buffer elements.

Constructor & Destructor Documentation

◆ GenericRecvBuffer() [1/3]

template<typename T >
walberla::mpi::GenericRecvBuffer< T >::GenericRecvBuffer
inlineexplicit

Standard constructor for RecvBuffer.

◆ GenericRecvBuffer() [2/3]

template<typename T >
walberla::mpi::GenericRecvBuffer< T >::GenericRecvBuffer ( const GenericRecvBuffer< T > &  rb)
inline

Copy constructor for RecvBuffer.

Parameters
rbThe receive buffer to be copied.

◆ GenericRecvBuffer() [3/3]

template<typename T >
template<typename G >
walberla::mpi::GenericRecvBuffer< T >::GenericRecvBuffer ( GenericSendBuffer< T, G > &  sb)
inlineexplicit

Constructor for RecvBuffer.

Parameters
sbThe send buffer whose content is transfered to this receive buffer.

◆ ~GenericRecvBuffer()

template<typename T >
walberla::mpi::GenericRecvBuffer< T >::~GenericRecvBuffer
inline

Destructor for RecvBuffer.

Member Function Documentation

◆ capacity()

template<typename T >
size_t walberla::mpi::GenericRecvBuffer< T >::capacity
inline

Returns the capacity of the receive buffer.

Returns
The capacity.

◆ clear()

template<typename T >
void walberla::mpi::GenericRecvBuffer< T >::clear
inline

Clearing the receive buffer.

Returns
void

This function performs a complete reset of the receive buffer.

◆ get()

template<typename T >
template<typename V >
std::enable_if< std::is_arithmetic< V >::value||std::is_enum< V >::value, GenericRecvBuffer< T > & >::type walberla::mpi::GenericRecvBuffer< T >::get ( V &  value)
private

Implements operator>> without debugging system.

Returns
Reference to the receive buffer.

◆ isEmpty()

template<typename T >
bool walberla::mpi::GenericRecvBuffer< T >::isEmpty
inline

Returns true if the receive buffer is empty.

Returns
true if the receive buffer is empty, false if it is not.

◆ maxSize()

template<typename T >
size_t walberla::mpi::GenericRecvBuffer< T >::maxSize
inline

Returns the maximum possible size of the receive buffer.

Returns
The maximum possible size.

◆ operator=() [1/3]

template<typename T >
GenericRecvBuffer< T > & walberla::mpi::GenericRecvBuffer< T >::operator= ( const GenericRecvBuffer< T > &  rb)

Copy assignment operator for RecvBuffer.

Parameters
rbThe receive buffer to be copied.
Returns
Reference to the assigned receive buffer.

◆ operator=() [2/3]

template<typename T = unsigned char>
template<typename G >
GenericRecvBuffer& walberla::mpi::GenericRecvBuffer< T >::operator= ( const GenericSendBuffer< T, G > &  sb)

◆ operator=() [3/3]

template<typename T = unsigned char>
template<typename G >
GenericRecvBuffer<T>& walberla::mpi::GenericRecvBuffer< T >::operator= ( const GenericSendBuffer< T, G > &  sb)

◆ operator>>()

template<typename T >
template<typename V >
std::enable_if< std::is_arithmetic< V >::value||std::is_enum< V >::value, GenericRecvBuffer< T > & >::type walberla::mpi::GenericRecvBuffer< T >::operator>> ( V &  value)

Reads a built-in data value from the receive buffer.

Returns
Reference to the receive buffer.

This function extracts one data value of built-in data type from the receive buffer.

Note: This operator may only be used for built-in data types. The attempt to use a user-defined data type results in a compile time error!

◆ peek()

template<typename T >
template<typename V >
void walberla::mpi::GenericRecvBuffer< T >::peek ( V &  value) const
inline

Reads a built-in data value from the receive buffer without extracting it.

Returns
void

This function reads the next built-in data value of type V from the receive buffer without extracting/removing it from the buffer.

◆ ptr()

template<typename T >
T * walberla::mpi::GenericRecvBuffer< T >::ptr
inline

Returns a pointer to the first element of the receive buffer.

Returns
Pointer to the first element of the receive buffer.

This utility function enables the RecvBuffer to be used directly as receive buffer in MPI receive functions. Note however, that this operation is only allowed for a reinitialized receive buffer (for instance via the resize() function).

using namespace pe;
// Preparing a receive buffer for a message of 50 bytes
RecvBuffer<byte> buffer;
buffer.resize( 50 );
// Receiving an MPI message from process 0 in a blocking MPI_Recv() function
MPI_Status status;
MPI_Recv( buffer.ptr(), buffer.size(), MPI_BYTE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, status );

◆ readDebugMarker()

template<typename T >
void walberla::mpi::GenericRecvBuffer< T >::readDebugMarker ( const char *  marker)
inline

Reads debug marker and raises assert when marker does not match.

◆ reserve()

template<typename T >
void walberla::mpi::GenericRecvBuffer< T >::reserve ( size_t  newCapacity)
inline

Setting the minimum capacity of the receive buffer.

Parameters
newCapacityThe new minimum capacity of the receive buffer.
Returns
void

This function reserves at least newCapacity elements of data type T for the receive buffer. Note that this operation involves a complete reset of the receive buffer!

◆ reset()

template<typename T >
void walberla::mpi::GenericRecvBuffer< T >::reset
inline

Clearing the receive buffer.

Returns
void

This function performs a complete reset of the receive buffer - including the deletion of allocated memory!

◆ resize()

template<typename T >
void walberla::mpi::GenericRecvBuffer< T >::resize ( size_t  newSize)
inline

Changing the size of the receive buffer.

Parameters
newSizeThe new size of the receive buffer.
Returns
void

This function resizes the receive buffer to the given size newSize. Note that this operation does not preserve the current contents of the receive buffer!

◆ size()

template<typename T >
size_t walberla::mpi::GenericRecvBuffer< T >::size
inline

Returns the current size of the receive buffer.

Returns
The current size.

◆ skip()

template<typename T >
T * walberla::mpi::GenericRecvBuffer< T >::skip ( size_t  elements)
inline

Skipping the given number of elements.

Parameters
elementsThe number of elements to be skipped.
Returns
void

This function skips element receive buffer elements of type T.

Member Data Documentation

◆ begin_

template<typename T = unsigned char>
T* walberla::mpi::GenericRecvBuffer< T >::begin_
private

Pointer to the first element of the receive buffer.

◆ capacity_

template<typename T = unsigned char>
size_t walberla::mpi::GenericRecvBuffer< T >::capacity_
private

The current size of the receive buffer.

◆ cur_

template<typename T = unsigned char>
T* walberla::mpi::GenericRecvBuffer< T >::cur_
private

Pointer to the current element of the receive buffer.

◆ end_

template<typename T = unsigned char>
T* walberla::mpi::GenericRecvBuffer< T >::end_
private

Pointer to the last element of the receive buffer.


The documentation for this class was generated from the following file:
GenericRecvBuffer RecvBuffer
Definition: RecvBuffer.h:176
void resize(size_t newSize)
Changing the size of the receive buffer.
Definition: RecvBuffer.h:520