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

#include <combuff.h>

Inheritance diagram for oofem::MPIBuffer:

Public Member Functions

 MPIBuffer (std::size_t size, bool dynamic=0)
 Constructor. Creates buffer of given size, using given communicator for packing.
 MPIBuffer (bool dynamic=0)
 Constructor. Creates empty buffer, using given communicator for packing.
virtual ~MPIBuffer ()
 Destructor.
int resize (std::size_t newSize)
virtual void init ()
std::size_t giveSize ()
std::size_t giveAvailableSpace ()
MPI_Request giveRequest ()
int packArray (MPI_Comm communicator, const void *src, std::size_t n, MPI_Datatype type)
int unpackArray (MPI_Comm communicator, void *dest, std::size_t n, MPI_Datatype type)
Methods for determining pack size of datatype to pack/unpack to/from buffer
int givePackSize (MPI_Comm communicator, MPI_Datatype type, std::size_t size)

Protected Attributes

std::size_t size
 Size and current position in buffer in bytes (sizeof(char)).
std::size_t curr_pos
bool isDynamic
 Dynamic flag (if true, buffer can grow, but reallocation is needed).
ComBuff_BYTE_TYPEbuff
 Buffer. Dynamically allocated.
MPI_Request request

Services for buffer sending/receiving

virtual int iSend (MPI_Comm communicator, int dest, int tag)
virtual int iRecv (MPI_Comm communicator, int source, int tag, std::size_t count=0)
int testCompletion ()
int testCompletion (int &source, int &tag)
virtual int waitCompletion ()
int bcast (MPI_Comm communicator, int root)
void dump ()
std::size_t givePosition ()

Detailed Description

Definition at line 70 of file combuff.h.

Constructor & Destructor Documentation

◆ MPIBuffer() [1/2]

oofem::MPIBuffer::MPIBuffer ( std::size_t size,
bool dynamic = 0 )

◆ MPIBuffer() [2/2]

oofem::MPIBuffer::MPIBuffer ( bool dynamic = 0)

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

Definition at line 58 of file combuff.C.

References buff, curr_pos, isDynamic, request, and size.

◆ ~MPIBuffer()

oofem::MPIBuffer::~MPIBuffer ( )
virtual

Destructor.

Definition at line 69 of file combuff.C.

References buff.

Member Function Documentation

◆ bcast()

int oofem::MPIBuffer::bcast ( MPI_Comm communicator,
int root )

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

Parameters
communicatorCommunicator (handle).
rootRank of broadcast root.
Returns
MPI_SUCCESS if ok.

Definition at line 219 of file combuff.C.

References buff, and size.

◆ dump()

void oofem::MPIBuffer::dump ( )

Definition at line 235 of file combuff.C.

References buff.

◆ giveAvailableSpace()

std::size_t oofem::MPIBuffer::giveAvailableSpace ( )
inline
Returns
Remaining space.

Definition at line 111 of file combuff.h.

References curr_pos, and size.

◆ givePackSize()

int oofem::MPIBuffer::givePackSize ( MPI_Comm communicator,
MPI_Datatype type,
std::size_t size )

Returns pack size required to pack array of given type and size (c-style).

Parameters
communicatorCommunicator handle.
typeType id.
sizeSize of array to pack.
Returns
Pack size required.

Definition at line 226 of file combuff.C.

References size.

Referenced by oofem::CommunicationPacket::CommunicationPacket(), oofem::CommunicationPacket::CommunicationPacket(), oofem::CommunicationPacket::init(), and packArray().

◆ givePosition()

std::size_t oofem::MPIBuffer::givePosition ( )
inlineprivate
Returns
Current buffer position.

Definition at line 211 of file combuff.h.

References curr_pos.

◆ giveRequest()

MPI_Request oofem::MPIBuffer::giveRequest ( )
inline

Returns associated MPI request handle

Definition at line 115 of file combuff.h.

◆ giveSize()

std::size_t oofem::MPIBuffer::giveSize ( )
inline
Returns
Current buffer size.

Definition at line 109 of file combuff.h.

References size.

◆ init()

void oofem::MPIBuffer::init ( )
virtual

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

Reimplemented in oofem::StaticCommunicationBuffer.

Definition at line 114 of file combuff.C.

References curr_pos, and request.

◆ iRecv()

int oofem::MPIBuffer::iRecv ( MPI_Comm communicator,
int source,
int tag,
std::size_t count = 0 )
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.
communicatorRequest communicator (handle).
Returns
MPI_SUCCESS if ok.

Reimplemented in oofem::CommunicationPacket.

Definition at line 170 of file combuff.C.

References buff, request, resize(), and size.

◆ iSend()

int oofem::MPIBuffer::iSend ( MPI_Comm communicator,
int dest,
int tag )
virtual

Starts standard mode, nonblocking send.

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

Reimplemented in oofem::CommunicationPacket.

Definition at line 162 of file combuff.C.

References buff, curr_pos, and request.

◆ packArray()

int oofem::MPIBuffer::packArray ( MPI_Comm communicator,
const void * src,
std::size_t n,
MPI_Datatype type )

Packs array of a values of given type into buffer. Buffer is enlarged if isDynamic flag is set, but it requires memory allocation and deallocation.

Parameters
communicatorCommunicator handle.
srcAddress of first value in memory.
nNumber of packed integers.
typeDetermines type of array values.
Returns
Nonzero if successful.

Definition at line 123 of file combuff.C.

References __CommunicationBuffer_ALLOC_CHUNK, buff, curr_pos, givePackSize(), isDynamic, OOFEM_WARNING, resize(), and size.

◆ resize()

int oofem::MPIBuffer::resize ( std::size_t newSize)

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.

Definition at line 78 of file combuff.C.

References buff, curr_pos, OOFEM_ERROR, and size.

Referenced by oofem::CommunicationPacket::iRecv(), iRecv(), MPIBuffer(), and packArray().

◆ testCompletion() [1/2]

int oofem::MPIBuffer::testCompletion ( )

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.

Definition at line 186 of file combuff.C.

References request.

◆ testCompletion() [2/2]

int oofem::MPIBuffer::testCompletion ( int & source,
int & tag )

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.

Parameters
sourceSource tag.
tagTag of received message.
Returns
Nonzero if operation complete, zero otherwise.

Definition at line 196 of file combuff.C.

References request.

◆ unpackArray()

int oofem::MPIBuffer::unpackArray ( MPI_Comm communicator,
void * dest,
std::size_t n,
MPI_Datatype type )

Unpacks array of values of given type from buffer.

Parameters
communicatorCommunicator handle.
destAddress of first value in memory, where to store values
nNumber of unpacked integers.
typeDetermines type of array values.
Returns
Nonzero if successful.

Definition at line 151 of file combuff.C.

References buff, curr_pos, and size.

◆ waitCompletion()

int oofem::MPIBuffer::waitCompletion ( )
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

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

Definition at line 210 of file combuff.C.

References request.

Member Data Documentation

◆ buff

◆ curr_pos

◆ isDynamic

bool oofem::MPIBuffer::isDynamic
protected

Dynamic flag (if true, buffer can grow, but reallocation is needed).

Definition at line 76 of file combuff.h.

Referenced by MPIBuffer(), MPIBuffer(), and packArray().

◆ request

MPI_Request oofem::MPIBuffer::request
protected

MPI request handle. This value is used by some message parsing functions. EngngCommunicator also assembles array of commbuff handles and wait for some completion (when receiving data for example).

Definition at line 84 of file combuff.h.

Referenced by init(), oofem::CommunicationPacket::iRecv(), iRecv(), oofem::CommunicationPacket::iSend(), iSend(), MPIBuffer(), MPIBuffer(), oofem::CommunicationPacket::testCompletion(), testCompletion(), testCompletion(), oofem::CommunicationPacket::waitCompletion(), and waitCompletion().

◆ size


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