OOFEM 3.0
Loading...
Searching...
No Matches
oofem::DynamicCommunicationBuffer Class Reference

#include <dyncombuff.h>

Inheritance diagram for oofem::DynamicCommunicationBuffer:
Collaboration diagram for oofem::DynamicCommunicationBuffer:

Public Member Functions

 DynamicCommunicationBuffer (MPI_Comm comm, std::size_t size, bool dynamic=0)
 Constructor. Creates buffer of given size, using given communicator for packing.
 DynamicCommunicationBuffer (MPI_Comm comm, bool dynamic=0)
 Constructor. Creates empty buffer, using given communicator for packing.
virtual ~DynamicCommunicationBuffer ()
 Destructor.
int resize (std::size_t newSize) override
void init () override
void initForPacking () override
 Initialize for packing.
void initForUnpacking () override
 Initialize for Unpacking (data already received).
int write (const int *src, std::size_t n) override
 Writes count integer values from array pointed by data.
int write (const long *src, std::size_t n) override
 Writes count long values from array pointed by data.
int write (const unsigned long *src, std::size_t n) override
 Writes count unsigned long values from array pointed by data.
int write (const double *src, std::size_t n) override
 Writes count double values from array pointed by data.
int write (const char *src, std::size_t n) override
 Writes count char values from array pointed by data.
int read (int *dest, std::size_t n) override
 Reads count integer values into array pointed by data.
int read (long *dest, std::size_t n) override
 Reads count long values into array pointed by data.
int read (unsigned long *dest, std::size_t n) override
 Reads count unsigned long values into array pointed by data.
int read (double *dest, std::size_t n) override
 Reads count double values into array pointed by data.
int read (char *dest, std::size_t n) override
 Reads count char values into array pointed by data.
int iSend (int dest, int tag) override
int iRecv (int source, int tag, std::size_t count=0) override
int bcast (int root) override
int testCompletion () override
int waitCompletion () override
Public Member Functions inherited from oofem::CommunicationBuffer
 CommunicationBuffer (MPI_Comm comm, std::size_t size, bool dynamic=0)
 CommunicationBuffer (MPI_Comm comm, bool dynamic=0)
 Constructor. Creates empty buffer, using given communicator for packing.
virtual ~CommunicationBuffer ()
 Destructor.
int read (bool &data) override
 Reads a bool value from data.
int write (bool data) override
 Writes a bool value.
int givePackSizeOfInt (std::size_t count) override
int givePackSizeOfDouble (std::size_t count) override
int givePackSizeOfChar (std::size_t count) override
int givePackSizeOfBool (std::size_t count) override
int givePackSizeOfLong (std::size_t count) override
int givePackSizeOfSizet (std::size_t count) override
int read (int &data)
int read (unsigned long &data)
int read (long &data)
int read (double &data)
int read (char &data)
int read (std ::string &data)
 Reads a string (stored as an int for the length followed by char*).
int write (int data)
int write (unsigned long data)
int write (long data)
int write (double data)
int write (char data)
int write (const std ::string &data)
 Reads a string (stored as an int for the length followed by char*).
int write (const char *data)
 Writes a string (wrapper needed, otherwise write(bool) is called ).
Public Member Functions inherited from oofem::DataStream
virtual ~DataStream ()
 Destructor.
int read (int &data)
int read (unsigned long &data)
int read (long &data)
int read (double &data)
int read (char &data)
int read (std ::string &data)
 Reads a string (stored as an int for the length followed by char*).
int write (int data)
int write (unsigned long data)
int write (long data)
int write (double data)
int write (char data)
int write (const std ::string &data)
 Reads a string (stored as an int for the length followed by char*).
int write (const char *data)
 Writes a string (wrapper needed, otherwise write(bool) is called ).

Static Public Member Functions

static void printInfo ()

Protected Types

enum  DCB_Mode { DCB_null , DCB_send , DCB_receive }
 Receiver mode. More...

Protected Member Functions

CommunicationPacketallocateNewPacket (int)
void freePacket (CommunicationPacket *)
int receiveCompleted ()
int sendCompleted ()
void popNewRecvPacket ()
void pushNewRecvPacket (CommunicationPacket *)
void clear ()
int giveFitSize (MPI_Datatype type, int availableSpace, int arrySize)
template<class T>
int __write (T *src, int n, MPI_Datatype type)
template<class T>
int __read (T *dest, int n, MPI_Datatype type)

Protected Attributes

std ::list< CommunicationPacket * > packet_list
std::list< CommunicationPacket * >::iterator recvIt
 Iterator to iterate over received packets.
CommunicationPacketactive_packet
 Active packet.
int active_tag
 Active rank and tag (send by initSend,initReceive, and initExchange).
int active_rank
int number_of_packets
enum oofem::DynamicCommunicationBuffer::DCB_Mode mode
bool completed
 Communication completion flag.
Protected Attributes inherited from oofem::CommunicationBuffer
MPI_Comm communicator

Static Protected Attributes

static CommunicationPacketPool packetPool
 Static packet pool.

Detailed Description

Definition at line 158 of file dyncombuff.h.

Member Enumeration Documentation

◆ DCB_Mode

Receiver mode.

Enumerator
DCB_null 
DCB_send 
DCB_receive 

Definition at line 171 of file dyncombuff.h.

Constructor & Destructor Documentation

◆ DynamicCommunicationBuffer() [1/2]

oofem::DynamicCommunicationBuffer::DynamicCommunicationBuffer ( MPI_Comm comm,
std::size_t size,
bool dynamic = 0 )

Constructor. Creates buffer of given size, using given communicator for packing.

Definition at line 151 of file dyncombuff.C.

References oofem::CommunicationBuffer::CommunicationBuffer(), completed, DCB_null, mode, number_of_packets, and packet_list.

◆ DynamicCommunicationBuffer() [2/2]

oofem::DynamicCommunicationBuffer::DynamicCommunicationBuffer ( MPI_Comm comm,
bool dynamic = 0 )

Constructor. Creates empty buffer, using given communicator for packing.

Definition at line 165 of file dyncombuff.C.

References oofem::CommunicationBuffer::CommunicationBuffer(), completed, DCB_null, mode, number_of_packets, and packet_list.

◆ ~DynamicCommunicationBuffer()

oofem::DynamicCommunicationBuffer::~DynamicCommunicationBuffer ( )
virtual

Destructor.

Definition at line 179 of file dyncombuff.C.

References clear().

Member Function Documentation

◆ __read()

template<class T>
int oofem::DynamicCommunicationBuffer::__read ( T * dest,
int n,
MPI_Datatype type )
inlineprotected

Templated low-level array unpacking method. Templated version used since implementation is similar for different types but type info is needed since implementation is relying on pointer arithmetic.

Definition at line 290 of file dyncombuff.h.

References active_packet, oofem::CommunicationBuffer::communicator, giveFitSize(), and popNewRecvPacket().

Referenced by read(), read(), read(), read(), and read().

◆ __write()

template<class T>
int oofem::DynamicCommunicationBuffer::__write ( T * src,
int n,
MPI_Datatype type )
inlineprotected

Templated low-level array packing method. Templated version used since implementation is similar for different types but type info is needed since implementation is relying on pointer arithmetic.

Definition at line 258 of file dyncombuff.h.

References active_packet, allocateNewPacket(), oofem::CommunicationBuffer::communicator, giveFitSize(), number_of_packets, and packet_list.

Referenced by write(), write(), write(), write(), and write().

◆ allocateNewPacket()

CommunicationPacket * oofem::DynamicCommunicationBuffer::allocateNewPacket ( int n)
protected

◆ bcast()

int oofem::DynamicCommunicationBuffer::bcast ( int root)
overridevirtual

Initializes broadcast over collaborating processes. The whole buffer size is broadcasted. All buffers participating in broadcast should have the same size.

Parameters
rootRank of broadcast root.
Returns
MPI_SUCCESS if ok.

Implements oofem::CommunicationBuffer.

Definition at line 446 of file dyncombuff.C.

References OOFEM_ERROR.

◆ clear()

void oofem::DynamicCommunicationBuffer::clear ( )
protected

◆ freePacket()

void oofem::DynamicCommunicationBuffer::freePacket ( CommunicationPacket * p)
protected

Definition at line 408 of file dyncombuff.C.

References packetPool.

Referenced by clear().

◆ giveFitSize()

int oofem::DynamicCommunicationBuffer::giveFitSize ( MPI_Datatype type,
int availableSpace,
int arrySize )
protected

Definition at line 381 of file dyncombuff.C.

References oofem::CommunicationBuffer::communicator.

Referenced by __read(), and __write().

◆ init()

void oofem::DynamicCommunicationBuffer::init ( )
overridevirtual

Initializes buffer to empty state. All packed data are lost.

Implements oofem::CommunicationBuffer.

Definition at line 185 of file dyncombuff.C.

References clear(), and completed.

Referenced by iRecv().

◆ initForPacking()

void oofem::DynamicCommunicationBuffer::initForPacking ( )
overridevirtual

Initialize for packing.

Implements oofem::CommunicationBuffer.

Definition at line 192 of file dyncombuff.C.

References active_packet, allocateNewPacket(), clear(), number_of_packets, and packet_list.

◆ initForUnpacking()

void oofem::DynamicCommunicationBuffer::initForUnpacking ( )
overridevirtual

Initialize for Unpacking (data already received).

Implements oofem::CommunicationBuffer.

Definition at line 203 of file dyncombuff.C.

References packet_list, popNewRecvPacket(), and recvIt.

Referenced by receiveCompleted().

◆ iRecv()

int oofem::DynamicCommunicationBuffer::iRecv ( int source,
int tag,
std::size_t count = 0 )
overridevirtual

Starts standard mode, nonblocking receive. The buffer must be large enough to receive all data.

Parameters
sourceRank of source.
tagMessage tag.
countNumber of elements to receive (bytes). Causes receive buffer to resize to count elements. If zero (default value) buffer is not resized.
Returns
MPI_SUCCESS if ok.

Implements oofem::CommunicationBuffer.

Definition at line 281 of file dyncombuff.C.

References active_packet, active_rank, active_tag, allocateNewPacket(), oofem::CommunicationBuffer::communicator, completed, DCB_receive, init(), mode, and number_of_packets.

◆ iSend()

int oofem::DynamicCommunicationBuffer::iSend ( int dest,
int tag )
overridevirtual

Starts standard mode, nonblocking send.

Parameters
destRank of destination.
tagMessage tag.
Returns
MPI_SUCCESS if ok.

set last (active) send packet as eof

Implements oofem::CommunicationBuffer.

Definition at line 254 of file dyncombuff.C.

References active_packet, active_rank, active_tag, oofem::CommunicationBuffer::communicator, completed, DCB_send, mode, and packet_list.

◆ popNewRecvPacket()

void oofem::DynamicCommunicationBuffer::popNewRecvPacket ( )
protected

Definition at line 427 of file dyncombuff.C.

References active_packet, OOFEM_ERROR, and recvIt.

Referenced by __read(), and initForUnpacking().

◆ printInfo()

void oofem::DynamicCommunicationBuffer::printInfo ( )
inlinestatic

Definition at line 238 of file dyncombuff.h.

References packetPool.

◆ pushNewRecvPacket()

void oofem::DynamicCommunicationBuffer::pushNewRecvPacket ( CommunicationPacket * p)
protected

Definition at line 439 of file dyncombuff.C.

References packet_list.

Referenced by receiveCompleted().

◆ read() [1/5]

int oofem::DynamicCommunicationBuffer::read ( char * data,
std::size_t count )
inlineoverridevirtual

Reads count char values into array pointed by data.

Reimplemented from oofem::CommunicationBuffer.

Definition at line 211 of file dyncombuff.h.

References __read().

◆ read() [2/5]

int oofem::DynamicCommunicationBuffer::read ( double * data,
std::size_t count )
inlineoverridevirtual

Reads count double values into array pointed by data.

Reimplemented from oofem::CommunicationBuffer.

Definition at line 209 of file dyncombuff.h.

References __read().

◆ read() [3/5]

int oofem::DynamicCommunicationBuffer::read ( int * data,
std::size_t count )
inlineoverridevirtual

Reads count integer values into array pointed by data.

Reimplemented from oofem::CommunicationBuffer.

Definition at line 203 of file dyncombuff.h.

References __read().

◆ read() [4/5]

int oofem::DynamicCommunicationBuffer::read ( long * data,
std::size_t count )
inlineoverridevirtual

Reads count long values into array pointed by data.

Reimplemented from oofem::CommunicationBuffer.

Definition at line 205 of file dyncombuff.h.

References __read().

◆ read() [5/5]

int oofem::DynamicCommunicationBuffer::read ( unsigned long * data,
std::size_t count )
inlineoverridevirtual

Reads count unsigned long values into array pointed by data.

Reimplemented from oofem::CommunicationBuffer.

Definition at line 207 of file dyncombuff.h.

References __read().

◆ receiveCompleted()

int oofem::DynamicCommunicationBuffer::receiveCompleted ( )
protected

◆ resize()

int oofem::DynamicCommunicationBuffer::resize ( std::size_t newSize)
inlineoverridevirtual

Resizes buffer to given size. If buffer size is to be enlarged, then previously packed data are kept in new buffer. Otherwise buffer is cleared using init service. Current implementation only performs buffer growing, request for size decrease is ignored to avoid reallocation if further request for growing is encountered.

Parameters
newSizeNew buffer size in bytes.
Returns
Nonzero if successful.

Implements oofem::CommunicationBuffer.

Definition at line 184 of file dyncombuff.h.

◆ sendCompleted()

int oofem::DynamicCommunicationBuffer::sendCompleted ( )
protected

Definition at line 333 of file dyncombuff.C.

References completed, and packet_list.

Referenced by testCompletion(), and waitCompletion().

◆ testCompletion()

int oofem::DynamicCommunicationBuffer::testCompletion ( )
overridevirtual

Tests if the operation identified by this->request is complete. In such case, true is returned and if communication was initiated by nonblocking send/receive, then request handle is set to MPI_REQUEST_NULL. Otherwise call returns flag=false.

Returns
True if operation complete, false otherwise.

Implements oofem::CommunicationBuffer.

Definition at line 350 of file dyncombuff.C.

References DCB_receive, DCB_send, mode, receiveCompleted(), and sendCompleted().

◆ waitCompletion()

int oofem::DynamicCommunicationBuffer::waitCompletion ( )
overridevirtual

Waits until a completion of a nonblocking communication. The completion of a send operation indicates that the sender is now free to update the locations in the send buffer, the completion of a receive operation indicates that the receive buffer contains the received message, the receiver is now free to access it, and that the status object is set. If the communication object associated with this request was created (nonblocking send or receive call), then the object is deallocated by the call to MPI_WAIT and the request handle is set to MPI_REQUEST_NULL.

Returns
True if request is successful.

Implements oofem::CommunicationBuffer.

Definition at line 362 of file dyncombuff.C.

References DCB_receive, DCB_send, mode, receiveCompleted(), and sendCompleted().

◆ write() [1/5]

int oofem::DynamicCommunicationBuffer::write ( const char * data,
std::size_t count )
inlineoverridevirtual

Writes count char values from array pointed by data.

Reimplemented from oofem::CommunicationBuffer.

Definition at line 200 of file dyncombuff.h.

References __write().

◆ write() [2/5]

int oofem::DynamicCommunicationBuffer::write ( const double * data,
std::size_t count )
inlineoverridevirtual

Writes count double values from array pointed by data.

Reimplemented from oofem::CommunicationBuffer.

Definition at line 198 of file dyncombuff.h.

References __write().

◆ write() [3/5]

int oofem::DynamicCommunicationBuffer::write ( const int * data,
std::size_t count )
inlineoverridevirtual

Writes count integer values from array pointed by data.

Reimplemented from oofem::CommunicationBuffer.

Definition at line 192 of file dyncombuff.h.

References __write().

◆ write() [4/5]

int oofem::DynamicCommunicationBuffer::write ( const long * data,
std::size_t count )
inlineoverridevirtual

Writes count long values from array pointed by data.

Reimplemented from oofem::CommunicationBuffer.

Definition at line 194 of file dyncombuff.h.

References __write().

◆ write() [5/5]

int oofem::DynamicCommunicationBuffer::write ( const unsigned long * data,
std::size_t count )
inlineoverridevirtual

Writes count unsigned long values from array pointed by data.

Reimplemented from oofem::CommunicationBuffer.

Definition at line 196 of file dyncombuff.h.

References __write().

Member Data Documentation

◆ active_packet

CommunicationPacket* oofem::DynamicCommunicationBuffer::active_packet
protected

Active packet.

Definition at line 165 of file dyncombuff.h.

Referenced by __read(), __write(), clear(), initForPacking(), iRecv(), iSend(), popNewRecvPacket(), and receiveCompleted().

◆ active_rank

int oofem::DynamicCommunicationBuffer::active_rank
protected

Definition at line 167 of file dyncombuff.h.

Referenced by iRecv(), iSend(), and receiveCompleted().

◆ active_tag

int oofem::DynamicCommunicationBuffer::active_tag
protected

Active rank and tag (send by initSend,initReceive, and initExchange).

Definition at line 167 of file dyncombuff.h.

Referenced by iRecv(), iSend(), and receiveCompleted().

◆ completed

bool oofem::DynamicCommunicationBuffer::completed
protected

Communication completion flag.

Definition at line 175 of file dyncombuff.h.

Referenced by DynamicCommunicationBuffer(), DynamicCommunicationBuffer(), init(), iRecv(), iSend(), receiveCompleted(), and sendCompleted().

◆ mode

◆ number_of_packets

int oofem::DynamicCommunicationBuffer::number_of_packets
protected

◆ packet_list

std :: list< CommunicationPacket * > oofem::DynamicCommunicationBuffer::packet_list
protected

◆ packetPool

CommunicationPacketPool oofem::DynamicCommunicationBuffer::packetPool
staticprotected

Static packet pool.

Definition at line 173 of file dyncombuff.h.

Referenced by allocateNewPacket(), freePacket(), and printInfo().

◆ recvIt

std::list<CommunicationPacket*>::iterator oofem::DynamicCommunicationBuffer::recvIt
protected

Iterator to iterate over received packets.

Definition at line 163 of file dyncombuff.h.

Referenced by initForUnpacking(), and popNewRecvPacket().


The documentation for this class was generated from the following files:

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011