Implementation of a MPI send buffer.
The SendBuffer class is a special purpose implementation for the MPI communication functionality. It offers a convenient and safe setup of MPI messages even for mixed-type communication. The following example gives an impression of the usage of the SendBuffer class:
For another example see also the Buffer Unit Test in File BufferTest.cpp
Note that the order of data values in the send buffer is depending on the order the elements are added to the buffer. This order is not changed during the MPI communication and the same order has to be used during the extraction of the sent data elements. See also the RecvBuffer class description for the receiver side of the MPI communication.
#include <SendBuffer.h>
Classes | |
class | Ptr |
Public Types | |
using | ElementType = T |
Type of the receive buffer elements. More... | |
Public Member Functions | |
Constructors | |
GenericSendBuffer (size_t initCapacity=0) | |
Standard constructor for SendBuffer. More... | |
GenericSendBuffer (const GenericSendBuffer &sb) | |
Copy constructor for SendBuffer. More... | |
Destructor | |
~GenericSendBuffer () | |
Destructor for SendBuffer. More... | |
Assignment operator | |
GenericSendBuffer & | operator= (const GenericSendBuffer &sb) |
Copy assignment operator for SendBuffer. More... | |
Get functions | |
size_t | maxSize () const |
Returns the maximum possible size of the send buffer. More... | |
size_t | size () const |
Returns the current size of the send buffer. More... | |
size_t | capacity () const |
Returns the capacity of the send buffer. More... | |
bool | isEmpty () const |
Returns true if the send buffer is empty. More... | |
Operators | |
template<typename V > | |
std::enable_if< std::is_arithmetic< V >::value||std::is_enum< V >::value, GenericSendBuffer & >::type | operator<< (V value) |
Adds a built-in data value to the send buffer. More... | |
Repositioning | |
T * | forward (uint_t elements) |
Forward the given number of elements. More... | |
void | rewind (const size_t &size) |
Rewinds the stream to a previous position. More... | |
Utility functions | |
template<typename VT > | |
Ptr< VT > | allocate (const size_t length=1, const VT &v=VT()) |
Returns a special pointer class to modify the allocated memory location later. More... | |
T * | ptr () const |
Returns a pointer to the first element of the send buffer. More... | |
void | reserve (size_t newCapacity) |
Setting the minimum capacity of the send buffer. More... | |
void | clear () |
Clearing the send buffer. More... | |
void | reset () |
Clearing the send buffer. More... | |
void | addDebugMarker (const char *marker) |
Adds a debug marker if buffer debugging is enabled. More... | |
void | extendMemory (size_t newCapacity) |
Extending the internal memory of the send buffer. More... | |
template<typename V > | |
std::enable_if< std::is_arithmetic< V >::value||std::is_enum< V >::value, GenericSendBuffer & >::type | put (V value) |
Implements operator<< without debugging system. More... | |
std::ptrdiff_t | getOffset () const |
Returns the offset from the beginning to the current position inside the buffer in bytes. More... | |
T * | getMemoryLocation (const std::ptrdiff_t offset) |
Returns the memory address corresponding to the offset. More... | |
Member variables | |
T * | begin_ |
Pointer to the first element of the send buffer. More... | |
T * | cur_ |
Pointer to the current/last element of the send buffer. More... | |
T * | end_ |
Pointer to the end of the storage of the send buffer. More... | |
template<typename U > | |
class | GenericRecvBuffer |
using walberla::mpi::GenericSendBuffer< T, G >::ElementType = T |
Type of the receive buffer elements.
|
inlineexplicit |
Standard constructor for SendBuffer.
initCapacity | The initial capacity of the send buffer. |
The default initial capacity of the send buffer is specified by the selected growth policy.
|
inline |
Copy constructor for SendBuffer.
sb | The send buffer to be copied. |
|
inline |
Destructor for SendBuffer.
|
inline |
Adds a debug marker if buffer debugging is enabled.
See corresponding function GenericRecvBuffer::readDebugMarker()
|
inline |
|
inline |
Returns the capacity of the send buffer.
|
inline |
Clearing the send buffer.
This function performs a complete reset of the send buffer.
|
private |
Extending the internal memory of the send buffer.
newCapacity | The new minimum capacity of the send buffer. |
|
inline |
Forward the given number of elements.
elements | The number of elements to be advanced. |
This function forwards element send buffer elements of type T and returns the previous buffer position.
|
inlineprivate |
Returns the memory address corresponding to the offset.
Offset is measured in bytes from the beginning of the buffer.
|
inlineprivate |
Returns the offset from the beginning to the current position inside the buffer in bytes.
|
inline |
Returns true if the send buffer is empty.
|
inline |
Returns the maximum possible size of the send buffer.
std::enable_if< std::is_arithmetic< V >::value||std::is_enum< V >::value, GenericSendBuffer< T, G > & >::type walberla::mpi::GenericSendBuffer< T, G >::operator<< | ( | V | value | ) |
Adds a built-in data value to the send buffer.
This function adds one data value of built-in data type to the send 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!
GenericSendBuffer< T, G > & walberla::mpi::GenericSendBuffer< T, G >::operator= | ( | const GenericSendBuffer< T, G > & | sb | ) |
Copy assignment operator for SendBuffer.
sb | The send buffer to be copied. |
|
inline |
Returns a pointer to the first element of the send buffer.
This utility function enables the SendBuffer to be used directly as send buffer in MPI send functions:
|
private |
Implements operator<< without debugging system.
|
inline |
Setting the minimum capacity of the send buffer.
newCapacity | The new minimum capacity of the send buffer. |
This function reserves at least newCapacity elements of data type T for the send buffer.
|
inline |
Clearing the send buffer.
This function performs a complete reset of the send buffer - including the deletion of allocated memory!
|
inline |
Rewinds the stream to a previous position.
|
inline |
Returns the current size of the send buffer.
|
friend |
|
private |
Pointer to the first element of the send buffer.
|
private |
Pointer to the current/last element of the send buffer.
|
private |
Pointer to the end of the storage of the send buffer.