OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
oofem::MPIBuffer Class Reference

#include <combuff.h>

+ Inheritance diagram for oofem::MPIBuffer:

Public Member Functions

 MPIBuffer (int size, bool dynamic=0)
 Constructor. Creates buffer of given size, using given communicator for packing. More...
 
 MPIBuffer (bool dynamic=0)
 Constructor. Creates empty buffer, using given communicator for packing. More...
 
virtual ~MPIBuffer ()
 Destructor. More...
 
int resize (int newSize)
 Resizes buffer to given size. More...
 
virtual void init ()
 Initializes buffer to empty state. More...
 
int giveSize ()
 
int giveAvailableSpace ()
 
MPI_Request giveRequest ()
 Returns associated MPI request handle. More...
 
int packArray (MPI_Comm communicator, const void *src, int n, MPI_Datatype type)
 Packs array of a values of given type into buffer. More...
 
int unpackArray (MPI_Comm communicator, void *dest, int n, MPI_Datatype type)
 Unpacks array of values of given type from buffer. More...
 
Methods for determining pack size of datatype to pack/unpack to/from buffer
int givePackSize (MPI_Comm communicator, MPI_Datatype type, int size)
 Returns pack size required to pack array of given type and size (c-style). More...
 

Protected Attributes

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

Services for buffer sending/receiving

virtual int iSend (MPI_Comm communicator, int dest, int tag)
 Starts standard mode, nonblocking send. More...
 
virtual int iRecv (MPI_Comm communicator, int source, int tag, int count=0)
 Starts standard mode, nonblocking receive. More...
 
int testCompletion ()
 Tests if the operation identified by this->request is complete. More...
 
int testCompletion (int &source, int &tag)
 Tests if the operation identified by this->request is complete. More...
 
virtual int waitCompletion ()
 Waits until a completion of a nonblocking communication. More...
 
int bcast (MPI_Comm communicator, int root)
 Initializes broadcast over collaborating processes. More...
 
void dump ()
 
int givePosition ()
 

Detailed Description

Definition at line 51 of file combuff.h.

Constructor & Destructor Documentation

oofem::MPIBuffer::MPIBuffer ( int  size,
bool  dynamic = 0 
)

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

Definition at line 46 of file combuff.C.

References buff, curr_pos, isDynamic, request, and resize().

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.

oofem::MPIBuffer::~MPIBuffer ( )
virtual

Destructor.

Definition at line 69 of file combuff.C.

References buff.

Member Function Documentation

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 211 of file combuff.C.

References buff, and size.

Referenced by oofem::StaticCommunicationBuffer::bcast().

void oofem::MPIBuffer::dump ( )

Definition at line 227 of file combuff.C.

References buff.

int oofem::MPIBuffer::giveAvailableSpace ( )
inline
Returns
Remaining space.

Definition at line 92 of file combuff.h.

Referenced by oofem::DynamicCommunicationBuffer::__read(), and oofem::DynamicCommunicationBuffer::__write().

int oofem::MPIBuffer::givePackSize ( MPI_Comm  communicator,
MPI_Datatype  type,
int  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 218 of file combuff.C.

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

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

Definition at line 192 of file combuff.h.

MPI_Request oofem::MPIBuffer::giveRequest ( )
inline

Returns associated MPI request handle.

Definition at line 96 of file combuff.h.

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

Definition at line 90 of file combuff.h.

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.

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

int oofem::MPIBuffer::iRecv ( MPI_Comm  communicator,
int  source,
int  tag,
int  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 162 of file combuff.C.

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

Referenced by oofem::StaticCommunicationBuffer::iRecv().

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 154 of file combuff.C.

References buff, curr_pos, and request.

Referenced by oofem::StaticCommunicationBuffer::iSend().

int oofem::MPIBuffer::packArray ( MPI_Comm  communicator,
const void *  src,
int  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.

Referenced by oofem::DynamicCommunicationBuffer::__write(), and oofem::StaticCommunicationBuffer::write().

int oofem::MPIBuffer::resize ( int  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(), packArray(), and oofem::StaticCommunicationBuffer::resize().

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 178 of file combuff.C.

References request.

Referenced by oofem::StaticCommunicationBuffer::testCompletion().

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 188 of file combuff.C.

References request.

int oofem::MPIBuffer::unpackArray ( MPI_Comm  communicator,
void *  dest,
int  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 147 of file combuff.C.

References buff, curr_pos, and size.

Referenced by oofem::DynamicCommunicationBuffer::__read(), and oofem::StaticCommunicationBuffer::read().

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::StaticCommunicationBuffer, and oofem::CommunicationPacket.

Definition at line 202 of file combuff.C.

References request.

Referenced by oofem::StaticCommunicationBuffer::waitCompletion().

Member Data Documentation

bool oofem::MPIBuffer::isDynamic
protected

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

Definition at line 57 of file combuff.h.

Referenced by MPIBuffer(), and packArray().

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 65 of file combuff.h.

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

int oofem::MPIBuffer::size
protected

Size and current position in buffer in bytes (sizeof(char)).

Definition at line 55 of file combuff.h.

Referenced by bcast(), oofem::CommunicationPacket::iRecv(), iRecv(), MPIBuffer(), packArray(), oofem::CommunicationPacket::packHeader(), resize(), unpackArray(), and oofem::CommunicationPacket::unpackHeader().


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

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:38 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011