ESyS-Particle  2.3.2
CVarMPIBuffer Class Reference

MPI send/recv buffer with automagically adjusted size. More...

#include <mpivbuf.h>

Inheritance diagram for CVarMPIBuffer:
Collaboration diagram for CVarMPIBuffer:

Public Member Functions

 CVarMPIBuffer (MPI_Comm, int size=16)
virtual ~CVarMPIBuffer ()
virtual void clear ()
virtual void sendTo (int, int)
virtual void NBsendTo (int, int)
virtual void initSendTo (int, int)
virtual void wait ()
virtual void receiveFrom (int src=MPI_ANY_SOURCE, int tag=MPI_ANY_TAG)
virtual void append (int)
virtual void append (double)
virtual void append (const char *)
virtual void append (const Vec3 &V)
virtual int pop_int ()
virtual double pop_double ()
virtual void pop_doubles (double *, int)
virtual std::string pop_string ()
virtual void broadcast (int)
virtual void receiveBroadcast (int)
- Public Member Functions inherited from AMPIBufferPP
 AMPIBufferPP (MPI_Comm comm)
virtual ~AMPIBufferPP ()
- Public Member Functions inherited from AMPIBuffer
 AMPIBuffer (MPI_Comm comm)
virtual ~AMPIBuffer ()
virtual Vec3 pop_vector ()
const MPI_Status & status ()

Protected Member Functions

void grow ()
void growTo (int)

Private Attributes

char * m_buffer
int m_buffersize
 the size of the buffer
int m_position
 the current end of the content
int m_int_increment
int m_dbl_increment
 the "packing size" of int/double
bool m_lock
MPI_Request m_req [2]
MPI_Status m_stat [2]
 for the ISendTo/Wait stuff

Additional Inherited Members

- Protected Attributes inherited from AMPIBuffer
MPI_Comm m_comm
 the MPI Communicator used for the send/recv operations
MPI_Status m_status

Detailed Description

MPI send/recv buffer with automagically adjusted size.

CVarMPIBuffer implements a send/receive buffer with variable size. The buffer grows automatically if neccesary with each append operation and when the a message is received. It is never automatically shrunk. Both append and send/recv operations slower than a constant size buffer (CMPIBuffer)

Author
Steffen Abe $Revision$ $Date$
Todo:

implement checks for locking

use exeption handling for error checking

Constructor & Destructor Documentation

CVarMPIBuffer::CVarMPIBuffer ( MPI_Comm  comm,
int  size = 16 
)

Constructor. Allocates the buffer and sets the MPI communicator to be used for send/receive operations. If the initial buffer size is not given a buffer of initial size 16 is allocated.

Parameters
commthe MPI communicator
sthe initial size of the buffer, defaults to 16

References m_buffer, m_buffersize, AMPIBuffer::m_comm, m_dbl_increment, m_int_increment, m_lock, and m_position.

CVarMPIBuffer::~CVarMPIBuffer ( )
virtual

References m_buffer.

Member Function Documentation

void CVarMPIBuffer::append ( int  i)
virtual

Append an integer to the buffer. If necessary, the buffer is enlarged.

Warning
currently does not check if there is enough free space to allocate larger buffer

Implements AMPIBuffer.

References grow(), m_buffer, m_buffersize, AMPIBuffer::m_comm, m_int_increment, and m_position.

Referenced by CLatticeMaster::addBondedIG(), CLatticeMaster::addCappedBondedIG(), CLatticeMaster::addExIG(), CLatticeMaster::addMesh2D(), CLatticeMaster::addRotBondedIG(), CLatticeMaster::addRotThermBondedIG(), CLatticeMaster::addShortBondedIG(), BroadcastCommand::append(), append(), BroadcastCommand::appendTypeAndName(), CLatticeMaster::applyForceToWall(), CLatticeMaster::createTriMesh(), CLatticeMaster::do2dCalculations(), CLatticeMaster::findParticleNearestTo(), CLatticeMaster::getParticlePosn(), CLatticeMaster::moveParticleTo(), CLatticeMaster::moveSingleNodeBy(), CLatticeMaster::moveSingleParticleTo(), CLatticeMaster::moveSphereBodyBy(), CLatticeMaster::moveTaggedNodesBy(), CLatticeMaster::moveTaggedParticlesBy(), CLatticeMaster::moveWallBy(), ABCDampingIGP::packInto(), CRotElasticIGP::packInto(), CElasticIGP::packInto(), AIGParam::packInto(), CRotThermElasticIGP::packInto(), CSoftBWallIGP::packInto(), CEWallIGP::packInto(), CESphereBodyIGP::packInto(), esys::lsm::BodyForceIGP::packInto(), CVWallIGP::packInto(), CLocalDampingIGP::packInto(), CBWallIGP::packInto(), CDampingIGP::packInto(), esys::lsm::BuoyancyIGP::packInto(), CLatticeMaster::saveTimingDataToFile(), CLatticeMaster::setParticleAngVel(), CLatticeMaster::setParticleDensity(), CLatticeMaster::setParticleNonDynamic(), CLatticeMaster::setParticleNonRot(), CLatticeMaster::setParticleNonTrans(), CLatticeMaster::setParticleVel(), CLatticeMaster::setTaggedParticleVel(), CLatticeMaster::setVelocityOfWall(), CLatticeMaster::setWallNormal(), and CLatticeMaster::tagParticleNearestTo().

Here is the call graph for this function:

Here is the caller graph for this function:

void CVarMPIBuffer::append ( double  d)
virtual

Append a double to the buffer. If necessary, the buffer is enlarged.

Warning
currently does not check if there is enough free space to allocate larger buffer
See Also
grow()

Implements AMPIBuffer.

References grow(), m_buffer, m_buffersize, AMPIBuffer::m_comm, m_dbl_increment, and m_position.

Here is the call graph for this function:

void CVarMPIBuffer::append ( const char *  str)
virtual

Append a string to the buffer. If necessary, the buffer is enlarged.

Warning
currently does not check if there is enough free space to allocate larger buffer
See Also
grow()

Implements AMPIBuffer.

References grow(), esys::lsm::bpu::len(), m_buffer, m_buffersize, AMPIBuffer::m_comm, m_int_increment, and m_position.

Here is the call graph for this function:

virtual void CVarMPIBuffer::append ( const Vec3 V)
inlinevirtual

Reimplemented from AMPIBuffer.

References append().

Here is the call graph for this function:

void CVarMPIBuffer::broadcast ( int  root)
virtual

Broadcast a message to all members of the communicator.

Parameters
rootthe root of the broadcast

References m_buffer, AMPIBuffer::m_comm, and m_position.

Referenced by CLatticeMaster::addBondedIG(), CLatticeMaster::addCappedBondedIG(), CLatticeMaster::addExIG(), CLatticeMaster::addMesh2D(), CLatticeMaster::addRotBondedIG(), CLatticeMaster::addRotThermBondedIG(), CLatticeMaster::addShortBondedIG(), CLatticeMaster::applyForceToWall(), BroadcastCommand::broadcastBuffer(), CLatticeMaster::createTriMesh(), CLatticeMaster::do2dCalculations(), CLatticeMaster::findParticleNearestTo(), CLatticeMaster::getParticlePosn(), CheckPointController::issueCheckPointCmd(), CheckPointController::issueCheckPointCmdWTM(), CheckPointController::issueCheckPointLoadingCmd(), CheckPointController::issueSnapShotCmd(), CLatticeMaster::makeLattice(), CLatticeMaster::moveParticleTo(), CLatticeMaster::moveSingleNodeBy(), CLatticeMaster::moveSingleParticleTo(), CLatticeMaster::moveSphereBodyBy(), CLatticeMaster::moveTaggedNodesBy(), CLatticeMaster::moveTaggedParticlesBy(), CLatticeMaster::moveWallBy(), CLatticeMaster::saveTimingDataToFile(), CLatticeMaster::setParticleAngVel(), CLatticeMaster::setParticleDensity(), CLatticeMaster::setParticleNonDynamic(), CLatticeMaster::setParticleNonRot(), CLatticeMaster::setParticleNonTrans(), CLatticeMaster::setParticleVel(), CLatticeMaster::setTaggedParticleVel(), CLatticeMaster::setVelocityOfWall(), CLatticeMaster::setWallNormal(), and CLatticeMaster::tagParticleNearestTo().

Here is the caller graph for this function:

void CVarMPIBuffer::grow ( )
protected

Grows the buffer to twice its current size, thus guaranteeing that append works in amortized constant time.

References growTo(), and m_buffersize.

Referenced by append().

Here is the call graph for this function:

Here is the caller graph for this function:

void CVarMPIBuffer::growTo ( int  size)
protected

Grows the buffer to a given size. If the buffer is already larger that the given size, nothing is done. Used by receiveFrom.

Parameters
sizesize to which the buffer is grown

References m_buffer, m_buffersize, and m_position.

Referenced by grow(), receiveBroadcast(), and receiveFrom().

Here is the caller graph for this function:

void CVarMPIBuffer::initSendTo ( int  dest,
int  tag 
)
virtual

Initate send,lock buffer and immediately return (equivalent to MPI_Isend)

Parameters
destthe rank of the destination process in the current communicator
tagthe message tag

References console, Console::Critical(), m_buffer, AMPIBuffer::m_comm, m_lock, m_position, and m_req.

Here is the call graph for this function:

void CVarMPIBuffer::NBsendTo ( int  dest,
int  tag 
)
virtual

Nonblocking version of CVarMPIBuffer::sendTo. Uses MPI_Isend and is (should be) thus deadlock-safe.

Parameters
destthe rank of the destination process in the current communicator
tagthe message tag
Warning
It is not checked if the destination actually exists.

References m_buffer, AMPIBuffer::m_comm, and m_position.

void CVarMPIBuffer::pop_doubles ( double *  dbl,
int  ndb 
)
virtual

pop an array of doubles from a buffer

Implements AMPIBuffer.

References m_buffer, m_buffersize, AMPIBuffer::m_comm, and m_position.

std::string CVarMPIBuffer::pop_string ( )
virtual

Pops a string from the buffer. The first for bytes are interpreted as int, giving the length of the string (without terminating '\0'), the rest as the characters.

Warning
no consistency check, i.e. it is not checked if the length is smaller than the buffersize.
Returns
the double.
See Also
CVarMPISingle::pop_int()

Implements AMPIBuffer.

References esys::lsm::bpu::len(), m_buffer, m_buffersize, AMPIBuffer::m_comm, and m_position.

Referenced by TSubLattice< T >::addBondedIG(), TSubLattice< T >::addBondedMesh2DIG(), TSubLattice< T >::addBondedTriMeshIG(), TSubLattice< T >::addCappedBondedIG(), TSubLattice< T >::addDamping(), TSubLattice< T >::addMesh2D(), TSubLattice< T >::addMesh2DIG(), TSubLattice< T >::addPairIG(), TRotSubLattice< T >::addRotBondedIG(), TRotSubLattice< T >::addRotThermBondedIG(), TSubLattice< T >::addShortBondedIG(), TSubLattice< T >::addSingleIG(), TSubLattice< T >::addSphereBody(), TSubLattice< T >::addTaggedPairIG(), TSubLattice< T >::addTriMesh(), TSubLattice< T >::addTriMeshIG(), TSubLattice< T >::addWall(), TSubLattice< T >::applyForceToWall(), esys::lsm::BodyForceIGP::extract(), esys::lsm::BuoyancyIGP::extract(), TSubLattice< T >::getMesh2DStress(), TSubLattice< T >::getMeshFaceRef(), TSubLattice< T >::getMeshNodeRef(), TSubLattice< T >::getSphereBodyForce(), TSubLattice< T >::getSphereBodyPos(), TSubLattice< T >::getTriMeshForce(), TSubLattice< T >::getWallForce(), TSubLattice< T >::getWallPos(), CSubLatticeControler::initializeConsole(), TSubLattice< T >::moveSingleNode(), TSubLattice< T >::moveSphereBodyBy(), TSubLattice< T >::moveTaggedNodes(), TSubLattice< T >::moveWallBy(), CSubLatticeControler::performTiming(), TSubLattice< T >::removeIG(), CSubLatticeControler::setConsoleFilename(), TSubLattice< T >::setExIG(), TSubLattice< T >::setVelocityOfWall(), TSubLattice< T >::setWallNormal(), and CSubLatticeControler::translateMeshBy().

Here is the call graph for this function:

Here is the caller graph for this function:

void CVarMPIBuffer::receiveBroadcast ( int  root)
virtual

receive broadcast

Parameters
rootthe root of the broadcast

References growTo(), m_buffer, m_buffersize, and AMPIBuffer::m_comm.

Referenced by TSubLattice< T >::addBondedIG(), TSubLattice< T >::addBondedMesh2DIG(), TSubLattice< T >::addBondedTriMeshIG(), TSubLattice< T >::addBondedWIG(), TSubLattice< T >::addCappedBondedIG(), TSubLattice< T >::addDamping(), TSubLattice< T >::addDirBondedWIG(), TSubLattice< T >::addElasticWIG(), TSubLattice< T >::addESphereBodyIG(), TSubLattice< T >::addMesh2D(), TSubLattice< T >::addMesh2DIG(), TSubLattice< T >::addPairIG(), TRotSubLattice< T >::addRotBondedIG(), TRotSubLattice< T >::addRotThermBondedIG(), TSubLattice< T >::addShortBondedIG(), TSubLattice< T >::addSingleIG(), TSubLattice< T >::addSphereBody(), TSubLattice< T >::addTaggedElasticWIG(), TSubLattice< T >::addTaggedPairIG(), TSubLattice< T >::addTriMesh(), TSubLattice< T >::addTriMeshIG(), TSubLattice< T >::addViscWIG(), TSubLattice< T >::addWall(), TSubLattice< T >::applyForceToWall(), CSubLatticeControler::do2dCalculations(), CSubLatticeControler::findParticleNearestToPoint(), TSubLattice< T >::getMesh2DStress(), TSubLattice< T >::getMeshFaceRef(), TSubLattice< T >::getMeshNodeRef(), CSubLatticeControler::getParticlePosn(), TSubLattice< T >::getSphereBodyForce(), TSubLattice< T >::getSphereBodyPos(), TSubLattice< T >::getTriMeshForce(), TSubLattice< T >::getWallForce(), TSubLattice< T >::getWallPos(), ASubLattice::initComplex(), CSubLatticeControler::initializeConsole(), CheckPointer::loadCheckPoint(), CSubLatticeControler::makeLattice(), TSubLattice< T >::moveParticleTo(), TSubLattice< T >::moveSingleNode(), CSubLatticeControler::moveSingleParticle(), TSubLattice< T >::moveSphereBodyBy(), TSubLattice< T >::moveTaggedNodes(), TSubLattice< T >::moveTaggedParticlesBy(), TSubLattice< T >::moveWallBy(), CSubLatticeControler::performTiming(), TSubLattice< T >::removeIG(), CheckPointer::saveDump(), CheckPointer::saveRestartable(), CheckPointer::saveThroughMaster(), CSubLatticeControler::setConsoleBuffered(), CSubLatticeControler::setConsoleFilename(), TSubLattice< T >::setExIG(), TRotSubLattice< T >::setParticleAngularVelocity(), TSubLattice< T >::setParticleDensity(), TSubLattice< T >::setParticleNonDynamic(), TSubLattice< T >::setParticleNonRot(), TSubLattice< T >::setParticleNonTrans(), TSubLattice< T >::setParticleVelocity(), TSubLattice< T >::setTaggedParticleVel(), CSubLatticeControler::setTimeStepSize(), TSubLattice< T >::setVelocityOfWall(), CSubLatticeControler::setVerbosity(), TSubLattice< T >::setWallNormal(), TSubLattice< T >::tagParticleNearestTo(), and CSubLatticeControler::translateMeshBy().

Here is the call graph for this function:

void CVarMPIBuffer::receiveFrom ( int  src = MPI_ANY_SOURCE,
int  tag = MPI_ANY_TAG 
)
virtual

Receives a message from a given source and stores it in the buffer.The size of the buffer is automatically adjusted so it will be big enough to fit the message. For this reason 2 messages are received, the first one for the size of the data, the second one for the data. If no source and no tag are given, any message from any source is accepted.

Parameters
srcrank of the sender in the current communicator, defaults to MPI_ANY_SOURCE
tagthe message tag, defaults to MPI_ANY_TAG

Implements AMPIBufferPP.

References growTo(), m_buffer, m_buffersize, AMPIBuffer::m_comm, and AMPIBuffer::m_status.

Here is the call graph for this function:

void CVarMPIBuffer::sendTo ( int  dest,
int  tag 
)
virtual

Sends the contents of the buffer to a given destination. There are actually two messages sent, the first one announces the size of the buffer so the buffer on the receiving end can be grown if necessary, the second one does the transfer of the data. It uses buffered sends (MPI_Bsend) and it thus deadlock-save

Parameters
destthe rank of the destination process in the current communicator
tagthe message tag
Warning
It is not checked if the destination actually exists.
Overlapping requests can deadlock.

Implements AMPIBufferPP.

References m_buffer, AMPIBuffer::m_comm, and m_position.

void CVarMPIBuffer::wait ( )
virtual

Wait for completion of transaction on this buffer. If completed, unlock buffer and return

References m_lock, m_req, and m_stat.

Member Data Documentation

int CVarMPIBuffer::m_buffersize
private
int CVarMPIBuffer::m_dbl_increment
private

the "packing size" of int/double

Referenced by append(), and CVarMPIBuffer().

int CVarMPIBuffer::m_int_increment
private

Referenced by append(), and CVarMPIBuffer().

bool CVarMPIBuffer::m_lock
private

Referenced by CVarMPIBuffer(), initSendTo(), and wait().

int CVarMPIBuffer::m_position
private
MPI_Request CVarMPIBuffer::m_req[2]
private

Referenced by initSendTo(), and wait().

MPI_Status CVarMPIBuffer::m_stat[2]
private

for the ISendTo/Wait stuff

Referenced by wait().


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