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:
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 | |
using | ElementType = T |
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 | |
GenericRecvBuffer & | operator= (const GenericRecvBuffer &sb) |
Copy assignment operator for RecvBuffer. More... | |
template<typename G > | |
GenericRecvBuffer & | operator= (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... | |
using walberla::mpi::GenericRecvBuffer< T >::ElementType = T |
Type of the receive buffer elements.
|
inlineexplicit |
Standard constructor for RecvBuffer.
|
inline |
Copy constructor for RecvBuffer.
rb | The receive buffer to be copied. |
|
inlineexplicit |
Constructor for RecvBuffer.
sb | The send buffer whose content is transfered to this receive buffer. |
|
inline |
Destructor for RecvBuffer.
|
inline |
Returns the capacity of the receive buffer.
|
inline |
Clearing the receive buffer.
This function performs a complete reset of the receive buffer.
|
private |
Implements operator>> without debugging system.
|
inline |
Returns true if the receive buffer is empty.
|
inline |
Returns the maximum possible size of the receive buffer.
GenericRecvBuffer< T > & walberla::mpi::GenericRecvBuffer< T >::operator= | ( | const GenericRecvBuffer< T > & | rb | ) |
Copy assignment operator for RecvBuffer.
rb | The receive buffer to be copied. |
GenericRecvBuffer& walberla::mpi::GenericRecvBuffer< T >::operator= | ( | const GenericSendBuffer< T, G > & | sb | ) |
GenericRecvBuffer<T>& walberla::mpi::GenericRecvBuffer< T >::operator= | ( | const GenericSendBuffer< T, G > & | sb | ) |
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.
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!
|
inline |
Reads a built-in data value from the receive buffer without extracting it.
This function reads the next built-in data value of type V from the receive buffer without extracting/removing it from the buffer.
|
inline |
Returns a 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).
|
inline |
Reads debug marker and raises assert when marker does not match.
|
inline |
Setting the minimum capacity of the receive buffer.
newCapacity | The new minimum capacity of the receive buffer. |
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!
|
inline |
Clearing the receive buffer.
This function performs a complete reset of the receive buffer - including the deletion of allocated memory!
|
inline |
Changing the size of the receive buffer.
newSize | The new size of the receive buffer. |
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!
|
inline |
Returns the current size of the receive buffer.
|
inline |
Skipping the given number of elements.
elements | The number of elements to be skipped. |
This function skips element receive buffer elements of type T.
|
private |
Pointer to the first element of the receive buffer.
|
private |
The current size of the receive buffer.
|
private |
Pointer to the current element of the receive buffer.
|
private |
Pointer to the last element of the receive buffer.