OOFEM 3.0
Loading...
Searching...
No Matches
oofem::CommunicationBuffer Class Referenceabstract

#include <combuff.h>

Inheritance diagram for oofem::CommunicationBuffer:
Collaboration diagram for oofem::CommunicationBuffer:

Public Member Functions

 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.
virtual int resize (std::size_t newSize)=0
virtual void init ()=0
virtual void initForPacking ()=0
 Initialize for packing.
virtual void initForUnpacking ()=0
 Initialize for Unpacking (data already received).
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
virtual int read (int *data, std::size_t count)=0
 Reads count integer values into array pointed by data.
int read (int &data)
virtual int read (unsigned long *data, std::size_t count)=0
 Reads count unsigned long values into array pointed by data.
int read (unsigned long &data)
virtual int read (long *data, std::size_t count)=0
 Reads count long values into array pointed by data.
int read (long &data)
virtual int read (double *data, std::size_t count)=0
 Reads count double values into array pointed by data.
int read (double &data)
virtual int read (char *data, std::size_t count)=0
 Reads count char values into array pointed by data.
int read (char &data)
int read (std ::string &data)
 Reads a string (stored as an int for the length followed by char*).
virtual int write (const int *data, std::size_t count)=0
 Writes count integer values from array pointed by data.
int write (int data)
virtual int write (const unsigned long *data, std::size_t count)=0
 Writes count unsigned long values from array pointed by data.
int write (unsigned long data)
virtual int write (const long *data, std::size_t count)=0
 Writes count long values from array pointed by data.
int write (long data)
virtual int write (const double *data, std::size_t count)=0
 Writes count double values from array pointed by data.
int write (double data)
virtual int write (const char *data, std::size_t count)=0
 Writes count char values from array pointed by 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 ).
Services for buffer sending/receiving
virtual int iSend (int dest, int tag)=0
virtual int iRecv (int source, int tag, std::size_t count=0)=0
virtual int testCompletion ()=0
virtual int waitCompletion ()=0
virtual int bcast (int root)=0
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 ).

Protected Attributes

MPI_Comm communicator

Detailed Description

Class CommunicationBuffer provides abstraction for communication buffer. buffer is used as input or output buffer to various communication services provided by message parsing libraries. It provides methods for buffer initialization and resizing, methods for packing and/or unpacking data to/from buffer. Multiple messages can be packed/unpacked into/from buffer. The services for packing/unpacking take care about multiple messages stored, they maintain proper current buffer position for data inserting/retrieval. Interface to low level message parsing function is provided, allowing to send and receive buffer to selected destination.

Definition at line 227 of file combuff.h.

Constructor & Destructor Documentation

◆ CommunicationBuffer() [1/2]

◆ CommunicationBuffer() [2/2]

oofem::CommunicationBuffer::CommunicationBuffer ( MPI_Comm comm,
bool dynamic = 0 )
inline

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

Definition at line 234 of file combuff.h.

References communicator.

◆ ~CommunicationBuffer()

virtual oofem::CommunicationBuffer::~CommunicationBuffer ( )
inlinevirtual

Destructor.

Definition at line 236 of file combuff.h.

Member Function Documentation

◆ bcast()

virtual int oofem::CommunicationBuffer::bcast ( int root)
pure virtual

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.

Implemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ givePackSizeOfBool()

int oofem::CommunicationBuffer::givePackSizeOfBool ( std::size_t count)
overridevirtual

Implements oofem::DataStream.

Definition at line 300 of file combuff.C.

References communicator.

Referenced by initForUnpacking().

◆ givePackSizeOfChar()

int oofem::CommunicationBuffer::givePackSizeOfChar ( std::size_t count)
overridevirtual

Implements oofem::DataStream.

Definition at line 293 of file combuff.C.

References communicator.

Referenced by initForUnpacking().

◆ givePackSizeOfDouble()

int oofem::CommunicationBuffer::givePackSizeOfDouble ( std::size_t count)
overridevirtual

Implements oofem::DataStream.

Definition at line 286 of file combuff.C.

References communicator.

Referenced by initForUnpacking().

◆ givePackSizeOfInt()

int oofem::CommunicationBuffer::givePackSizeOfInt ( std::size_t count)
overridevirtual

◆ givePackSizeOfLong()

int oofem::CommunicationBuffer::givePackSizeOfLong ( std::size_t count)
overridevirtual

Implements oofem::DataStream.

Definition at line 307 of file combuff.C.

References communicator.

Referenced by initForUnpacking().

◆ givePackSizeOfSizet()

int oofem::CommunicationBuffer::givePackSizeOfSizet ( std::size_t count)
overridevirtual

Implements oofem::DataStream.

Definition at line 314 of file combuff.C.

References communicator, and my_MPI_SIZE_T.

Referenced by initForUnpacking().

◆ init()

virtual void oofem::CommunicationBuffer::init ( )
pure virtual

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

Implemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ initForPacking()

virtual void oofem::CommunicationBuffer::initForPacking ( )
pure virtual

Initialize for packing.

Implemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ initForUnpacking()

virtual void oofem::CommunicationBuffer::initForUnpacking ( )
pure virtual

◆ iRecv()

virtual int oofem::CommunicationBuffer::iRecv ( int source,
int tag,
std::size_t count = 0 )
pure virtual

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.

Implemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

Referenced by oofem::Natural2GlobalOrdering::init().

◆ iSend()

virtual int oofem::CommunicationBuffer::iSend ( int dest,
int tag )
pure virtual

Starts standard mode, nonblocking send.

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

Implemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

Referenced by oofem::Natural2GlobalOrdering::init().

◆ read() [1/12]

◆ read() [2/12]

int oofem::DataStream::read ( char & data)
inline

Definition at line 85 of file datastream.h.

◆ read() [3/12]

virtual int oofem::DataStream::read ( char * data,
std::size_t count )
virtual

Reads count char values into array pointed by data.

Implements oofem::DataStream.

Reimplemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ read() [4/12]

int oofem::DataStream::read ( double & data)
inline

Definition at line 82 of file datastream.h.

◆ read() [5/12]

virtual int oofem::DataStream::read ( double * data,
std::size_t count )
virtual

Reads count double values into array pointed by data.

Implements oofem::DataStream.

Reimplemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ read() [6/12]

int oofem::DataStream::read ( int & data)
inline

Definition at line 68 of file datastream.h.

◆ read() [7/12]

virtual int oofem::DataStream::read ( int * data,
std::size_t count )
virtual

Reads count integer values into array pointed by data.

Implements oofem::DataStream.

Reimplemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ read() [8/12]

int oofem::DataStream::read ( long & data)
inline

Definition at line 79 of file datastream.h.

◆ read() [9/12]

virtual int oofem::DataStream::read ( long * data,
std::size_t count )
virtual

Reads count long values into array pointed by data.

Implements oofem::DataStream.

Reimplemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ read() [10/12]

int oofem::DataStream::read ( std ::string & data)

Reads a string (stored as an int for the length followed by char*).

Definition at line 89 of file datastream.C.

◆ read() [11/12]

int oofem::DataStream::read ( unsigned long & data)
inline

Definition at line 71 of file datastream.h.

◆ read() [12/12]

virtual int oofem::DataStream::read ( unsigned long * data,
std::size_t count )
virtual

Reads count unsigned long values into array pointed by data.

Implements oofem::DataStream.

Reimplemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ resize()

virtual int oofem::CommunicationBuffer::resize ( std::size_t newSize)
pure virtual

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.

Implemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

Referenced by oofem::Natural2GlobalOrdering::init().

◆ testCompletion()

virtual int oofem::CommunicationBuffer::testCompletion ( )
pure virtual

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
Nonzero if operation complete, zero otherwise.

Implemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ waitCompletion()

virtual int oofem::CommunicationBuffer::waitCompletion ( )
pure virtual

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
Nonzero if ...

Implemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ write() [1/13]

◆ write() [2/13]

int oofem::DataStream::write ( char data)
inline

Definition at line 117 of file datastream.h.

◆ write() [3/13]

int oofem::DataStream::write ( const char * data)
inline

Writes a string (wrapper needed, otherwise write(bool) is called ).

Definition at line 123 of file datastream.h.

◆ write() [4/13]

virtual int oofem::DataStream::write ( const char * data,
std::size_t count )
virtual

Writes count char values from array pointed by data.

Implements oofem::DataStream.

Reimplemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ write() [5/13]

virtual int oofem::DataStream::write ( const double * data,
std::size_t count )
virtual

Writes count double values from array pointed by data.

Implements oofem::DataStream.

Reimplemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ write() [6/13]

virtual int oofem::DataStream::write ( const int * data,
std::size_t count )
virtual

Writes count integer values from array pointed by data.

Implements oofem::DataStream.

Reimplemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ write() [7/13]

virtual int oofem::DataStream::write ( const long * data,
std::size_t count )
virtual

Writes count long values from array pointed by data.

Implements oofem::DataStream.

Reimplemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ write() [8/13]

int oofem::DataStream::write ( const std ::string & data)

Reads a string (stored as an int for the length followed by char*).

Definition at line 121 of file datastream.C.

◆ write() [9/13]

virtual int oofem::DataStream::write ( const unsigned long * data,
std::size_t count )
virtual

Writes count unsigned long values from array pointed by data.

Implements oofem::DataStream.

Reimplemented in oofem::DynamicCommunicationBuffer, and oofem::StaticCommunicationBuffer.

◆ write() [10/13]

int oofem::DataStream::write ( double data)
inline

Definition at line 114 of file datastream.h.

◆ write() [11/13]

int oofem::DataStream::write ( int data)
inline

Definition at line 100 of file datastream.h.

◆ write() [12/13]

int oofem::DataStream::write ( long data)
inline

Definition at line 111 of file datastream.h.

◆ write() [13/13]

int oofem::DataStream::write ( unsigned long data)
inline

Definition at line 103 of file datastream.h.

Member Data Documentation

◆ communicator


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