PstreamBuffers Class Reference

Buffers for inter-processor communications streams (UOPstream, UIPstream). More...

Public Member Functions

 PstreamBuffers (const UPstream::commsTypes commsType, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
 Construct given comms type, message tag, communicator, IO format. More...
 
 PstreamBuffers (const label comm, const UPstream::commsTypes commsType, const int tag=UPstream::msgType(), IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
 Construct given communicator, comms type, message tag, IO format. More...
 
 ~PstreamBuffers ()
 Destructor - checks that all data have been consumed. More...
 
IOstreamOption::streamFormat format () const noexcept
 The associated buffer format (ascii | binary) More...
 
UPstream::commsTypes commsType () const noexcept
 The communications type of the stream. More...
 
int tag () const noexcept
 The transfer message type. More...
 
label comm () const noexcept
 Communicator. More...
 
label nProcs () const noexcept
 Number of ranks associated with PstreamBuffers. More...
 
UPstream::rangeType allProcs () const noexcept
 Range of ranks indices associated with PstreamBuffers. More...
 
UPstream::rangeType subProcs () const noexcept
 Range of sub-processes indices associated with PstreamBuffers. More...
 
bool finished () const noexcept
 True if finishedSends() or finishedNeighbourSends() has been called. More...
 
bool allowClearRecv () const noexcept
 
bool hasSendData () const
 True if any (local) send buffers have data. More...
 
bool hasRecvData () const
 
label sendDataCount (const label proci) const
 Number of send bytes for the specified processor. More...
 
label recvDataCount (const label proci) const
 
labelList recvDataCounts () const
 
const UList< char > peekRecvData (const label proci) const
 
void clear ()
 Clear individual buffers and reset states. More...
 
void clearRecv (const label proci)
 Clear an individual receive buffer (eg, data not required) More...
 
void clearStorage ()
 Clear individual buffer storage and reset states. More...
 
bool allowClearRecv (bool on) noexcept
 Change allowClearRecv, return previous value. More...
 
void finishedSends (const bool wait=true)
 Mark sends as done. More...
 
void finishedSends (labelList &recvSizes, const bool wait=true)
 
void finishedSends (const labelUList &sendProcs, const labelUList &recvProcs, const bool wait=true)
 
void finishedSends (const labelUList &sendProcs, const labelUList &recvProcs, labelList &recvSizes, const bool wait=true)
 
bool finishedSends (bitSet &sendConnections, DynamicList< label > &sendProcs, DynamicList< label > &recvProcs, const bool wait=true)
 A caching version that uses a limited send/recv connectivity. More...
 
void finishedNeighbourSends (const labelUList &neighProcs, const bool wait=true)
 
void finishedNeighbourSends (const labelUList &neighProcs, labelList &recvSizes, const bool wait=true)
 
void finishedGathers (const bool wait=true)
 Mark all sends to master as done. More...
 
void finishedGathers (labelList &recvSizes, const bool wait=true)
 
void finishedScatters (const bool wait=true)
 Mark all sends to sub-procs as done. More...
 
void finishedScatters (labelList &recvSizes, const bool wait=true)
 

Friends

class UOPstreamBase
 
class UIPstreamBase
 

Detailed Description

Buffers for inter-processor communications streams (UOPstream, UIPstream).

Use UOPstream to stream data into buffers, call finishedSends() to notify that data is in buffers and then use IUPstream to get data out of received buffers. Works with both blocking and nonBlocking. Does not make much sense with scheduled since there you would not need these explicit buffers.

Example usage:

for (const int proci : Pstream::allProcs())
{
if (proci != Pstream::myProcNo())
{
someObject vals;
UOPstream send(proci, pBufs);
send << vals;
}
}
pBufs.finishedSends(); // no-op for blocking
for (const int proci : Pstream::allProcs())
{
if (proci != Pstream::myProcNo())
{
UIPstream recv(proci, pBufs);
someObject vals(recv);
}
}
Buffers for inter-processor communications streams (UOPstream, UIPstream).
UPstream::rangeType allProcs() const noexcept
Range of ranks indices associated with PstreamBuffers.
@ nonBlocking
"nonBlocking"
int myProcNo() const noexcept
Return processor number.

There are additional special versions of finishedSends() for restricted neighbour communication as well as for special one-to-all and all-to-one communication patterns. For example,

{
someObject vals;
for (const int proci : Pstream::subProcs())
{
UOPstream send(proci, pBufs);
send << vals;
}
}
pBufs.finishedScatters();
{
UIPstream recv(Pstream::masterNo(), pBufs);
someObject vals(recv);
}
UPstream::rangeType subProcs() const noexcept
Range of sub-processes indices associated with PstreamBuffers.
static constexpr int masterNo() noexcept
Process index of the master (always 0)
Definition: UPstream.H:451
splitCell * master() const
Definition: splitCell.H:113
Source files

Definition at line 117 of file PstreamBuffers.H.

Constructor & Destructor Documentation

◆ PstreamBuffers() [1/2]

PstreamBuffers ( const UPstream::commsTypes  commsType,
const int  tag = UPstream::msgType(),
const label  comm = UPstream::worldComm,
IOstreamOption::streamFormat  fmt = IOstreamOption::BINARY 
)
explicit

Construct given comms type, message tag, communicator, IO format.

Definition at line 161 of file PstreamBuffers.C.

◆ PstreamBuffers() [2/2]

PstreamBuffers ( const label  comm,
const UPstream::commsTypes  commsType,
const int  tag = UPstream::msgType(),
IOstreamOption::streamFormat  fmt = IOstreamOption::BINARY 
)
explicit

Construct given communicator, comms type, message tag, IO format.

Definition at line 181 of file PstreamBuffers.C.

◆ ~PstreamBuffers()

Destructor - checks that all data have been consumed.

Definition at line 203 of file PstreamBuffers.C.

References Foam::abort(), Foam::FatalError, FatalErrorInFunction, forAll, and Foam::nl.

Here is the call graph for this function:

Member Function Documentation

◆ format()

IOstreamOption::streamFormat format ( ) const
inlinenoexcept

The associated buffer format (ascii | binary)

Definition at line 207 of file PstreamBuffers.H.

◆ commsType()

UPstream::commsTypes commsType ( ) const
inlinenoexcept

The communications type of the stream.

Definition at line 213 of file PstreamBuffers.H.

Referenced by faBoundaryMesh::calcGeometry(), faBoundaryMesh::movePoints(), pointBoundaryMesh::movePoints(), polyBoundaryMesh::movePoints(), faBoundaryMesh::updateMesh(), pointBoundaryMesh::updateMesh(), and polyBoundaryMesh::updateMesh().

Here is the caller graph for this function:

◆ tag()

int tag ( ) const
inlinenoexcept

The transfer message type.

Definition at line 219 of file PstreamBuffers.H.

◆ comm()

label comm ( ) const
inlinenoexcept

Communicator.

Definition at line 225 of file PstreamBuffers.H.

Referenced by processorFaPatch::initGeometry(), processorPolyPatch::initGeometry(), processorFaPatch::initUpdateMesh(), and processorPolyPatch::initUpdateMesh().

Here is the caller graph for this function:

◆ nProcs()

label nProcs ( ) const
inlinenoexcept

Number of ranks associated with PstreamBuffers.

Definition at line 234 of file PstreamBuffers.H.

References UList< T >::size().

Referenced by fvMeshPrimitiveLduAddressing::addAddressing(), surfaceZonesInfo::addCellZonesToMesh(), surfaceZonesInfo::addFaceZonesToMesh(), eagerGAMGProcAgglomeration::agglomerate(), manualGAMGProcAgglomeration::agglomerate(), masterCoarsestGAMGProcAgglomeration::agglomerate(), procFacesGAMGProcAgglomeration::agglomerate(), AMIInterpolation::agglomerate(), Pstream::allGatherList(), PstreamBuffers::allProcs(), sensitivitySurfacePoints::assembleSensitivities(), meshRefinement::balanceAndRefine(), faMesh::boundaryProcs(), faPatch::boundaryProcs(), faMesh::boundaryProcSizes(), faPatch::boundaryProcSizes(), Pstream::broadcast(), Pstream::broadcasts(), mapDistributeBase::calcCompactAddressing(), fieldMinMax::calcMinMaxFieldType(), decomposedBlockData::calcNumProcs(), surfaceNoise::calculate(), meshRefinement::checkCoupledFaceZones(), mappedPatchBase::collectSamples(), Pstream::combineAllGather(), fieldValue::combineFields(), sizeDistribution::combineFields(), Pstream::combineGather(), Pstream::combineScatter(), GAMGAgglomeration::continueAgglomerating(), fvMeshDistribute::countCells(), box::createLODMap(), box::createMap(), Foam::createReconstructMap(), meshRefinement::directionalRefineCandidates(), faMeshDistributor::distribute(), fvMeshDistribute::distribute(), distributedTriSurfaceMesh::distribute(), mapDistributeBase::distribute(), box::doRefineBoxes(), Pstream::exchange(), mapDistributeBase::exchangeAddressing(), mapDistributeBase::exchangeMasks(), Pstream::exchangeSizes(), extendedCentredCellToCellStencil::extendedCentredCellToCellStencil(), extendedCentredCellToFaceStencil::extendedCentredCellToFaceStencil(), extendedCentredFaceToCellStencil::extendedCentredFaceToCellStencil(), extendedUpwindCellToFaceStencil::extendedUpwindCellToFaceStencil(), distributedTriSurfaceMesh::findNearest(), mappedPatchBase::findSamples(), decomposedBlockData::gather(), Pstream::gather(), externalCoupled::gatherAndCombine(), Pstream::gatherList(), decomposedBlockData::gatherSlaveData(), globalIndex::get(), distributedTriSurfaceMesh::getVolumeType(), processorFaPatch::initGeometry(), processorPolyPatch::initGeometry(), viewFactor::initialise(), processorFaPatch::initUpdateMesh(), processorPolyPatch::initUpdateMesh(), Pstream::listCombineAllGather(), Pstream::listCombineGather(), Pstream::listCombineScatter(), UPstream::listGatherValues(), UPstream::listScatterValues(), distributedTriSurfaceMesh::localQueries(), LUscalarMatrix::LUscalarMatrix(), Pstream::mapCombineAllGather(), Pstream::mapCombineGather(), Pstream::mapCombineScatter(), mapDistributeBase::mapDistributeBase(), inverseDistance::markDonors(), trackingInverseDistance::markDonors(), masterUncollatedFileOperation::masterOp(), processorTopology::New(), masterUncollatedFileOperation::NewIFstream(), InflationInjection< CloudType >::parcelsToInject(), argList::parse(), ParticleZoneInfo< CloudType >::ParticleZoneInfo(), pointHistory::pointHistory(), RecycleInteraction< CloudType >::postEvolve(), powerLawLopesdaCostaZone::powerLawLopesdaCostaZone(), collatedFileOperation::printBanner(), mapDistributeBase::printLayout(), collatedFileOperation::processorsDir(), masterUncollatedFileOperation::read(), masterUncollatedFileOperation::readHeader(), masterUncollatedFileOperation::readStream(), meshRefinement::refineAndBalance(), meshRefinement::refineCandidates(), Foam::regionSum(), meshRefinement::removeGapCells(), parProfiling::report(), fvMeshSubset::reset(), faMeshBoundaryHalo::reset(), globalIndex::reset(), Pstream::scatter(), Pstream::scatterList(), mapDistributeBase::schedule(), Time::setControls(), zoneDistribute::setUpCommforZone(), ParSortableList< Type >::sort(), PstreamBuffers::subProcs(), inverseDistance::update(), trackingInverseDistance::update(), dynamicOversetFvMesh::updateAddressing(), turbulentDFSEMInletFvPatchVectorField::updateCoeffs(), globalMeshData::updateMesh(), ParticleZoneInfo< CloudType >::write(), decomposedBlockData::writeBlocks(), externalCoupled::writeGeometry(), isoAdvection::writeIsoFaces(), and streamLineBase::writeToFile().

Here is the call graph for this function:

◆ allProcs()

◆ subProcs()

UPstream::rangeType subProcs ( ) const
inlinenoexcept

Range of sub-processes indices associated with PstreamBuffers.

Definition at line 247 of file PstreamBuffers.H.

References PstreamBuffers::nProcs().

Referenced by LUscalarMatrix::LUscalarMatrix(), masterUncollatedFileOperation::NewIFstream(), argList::parse(), masterUncollatedFileOperation::read(), decomposedBlockData::readBlocks(), fieldsDistributor::readFields(), masterUncollatedFileOperation::readHeader(), masterUncollatedFileOperation::scatterList(), mapDistributeBase::schedule(), globalMeshData::sharedPoints(), LUscalarMatrix::solve(), surfaceNoise::surfaceAverage(), syncTools::syncEdgeMap(), syncTools::syncPointMap(), patchWriter::write(), patchMeshWriter::writeNeighIDs(), patchMeshWriter::writePatchIDs(), patchMeshWriter::writePoints(), and surfaceNoise::writeSurfaceData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finished()

bool finished ( ) const
inlinenoexcept

True if finishedSends() or finishedNeighbourSends() has been called.

Definition at line 257 of file PstreamBuffers.H.

Referenced by UIPstreamBase::UIPstreamBase().

Here is the caller graph for this function:

◆ allowClearRecv() [1/2]

bool allowClearRecv ( ) const
inlinenoexcept

Is clearStorage of individual receive buffer by external hooks allowed? (default: true)

Definition at line 264 of file PstreamBuffers.H.

Referenced by Cloud< ParticleType >::move().

Here is the caller graph for this function:

◆ hasSendData()

bool hasSendData ( ) const

True if any (local) send buffers have data.

Definition at line 263 of file PstreamBuffers.C.

◆ hasRecvData()

bool hasRecvData ( ) const

True if any (local) recv buffers have unconsumed data. Must call finishedSends() or other finished.. method first!

Definition at line 276 of file PstreamBuffers.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, and forAll.

Referenced by RecycleInteraction< CloudType >::postEvolve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendDataCount()

Foam::label sendDataCount ( const label  proci) const

Number of send bytes for the specified processor.

Definition at line 300 of file PstreamBuffers.C.

◆ recvDataCount()

Foam::label recvDataCount ( const label  proci) const

Number of unconsumed receive bytes for the specified processor. Must call finishedSends() or other finished.. method first!

Definition at line 306 of file PstreamBuffers.C.

References Foam::exit(), Foam::FatalError, and FatalErrorInFunction.

Referenced by globalIndex::get(), zoneDistribute::getDatafromOtherProc(), RecycleInteraction< CloudType >::postEvolve(), and zoneDistribute::setUpCommforZone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ recvDataCounts()

Foam::labelList recvDataCounts ( ) const

Number of unconsumed receive bytes for all processors. Must call finishedSends() or other finished.. method first!

Definition at line 329 of file PstreamBuffers.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, forAll, and Foam::Zero.

Here is the call graph for this function:

◆ peekRecvData()

const Foam::UList< char > peekRecvData ( const label  proci) const

Number of unconsumed receive bytes for the specified processor. Must call finishedSends() or other finished.. method first!

The method is only useful in limited situations, such as when PstreamBuffers has been used to fill contiguous data (eg, using OPstream::write).

Definition at line 358 of file PstreamBuffers.C.

References Foam::exit(), Foam::FatalError, and FatalErrorInFunction.

Here is the call graph for this function:

◆ clear()

void clear ( )

Clear individual buffers and reset states.

Does not remove the buffer storage.

Definition at line 222 of file PstreamBuffers.C.

Referenced by fvMeshDistribute::distribute(), inverseDistance::markDonors(), trackingInverseDistance::markDonors(), trackingInverseDistance::markPatchesAsHoles(), inverseDistance::markPatchesAsHoles(), and surfaceNoise::readSurfaceData().

Here is the caller graph for this function:

◆ clearRecv()

void clearRecv ( const label  proci)

Clear an individual receive buffer (eg, data not required)

Does not remove the buffer storage.

Definition at line 238 of file PstreamBuffers.C.

◆ clearStorage()

void clearStorage ( )

Clear individual buffer storage and reset states.

Definition at line 245 of file PstreamBuffers.C.

◆ allowClearRecv() [2/2]

bool allowClearRecv ( bool  on)
noexcept

Change allowClearRecv, return previous value.

Definition at line 385 of file PstreamBuffers.C.

◆ finishedSends() [1/5]

◆ finishedSends() [2/5]

void finishedSends ( labelList recvSizes,
const bool  wait = true 
)

Mark sends as done. Recovers the sizes (bytes) received.

Non-blocking mode: populates receive buffers (all-to-all).

Parameters
[out]recvSizesthe sizes (bytes) received
waitwait for requests to complete (in nonBlocking mode)
Warning
currently only valid for nonBlocking comms.

Definition at line 400 of file PstreamBuffers.C.

References UPstream::commsTypeNames, Foam::endl(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, and UPstream::nonBlocking.

Here is the call graph for this function:

◆ finishedSends() [3/5]

void finishedSends ( const labelUList sendProcs,
const labelUList recvProcs,
const bool  wait = true 
)

Mark sends as done using subset of send/recv ranks to exchange data on.

Non-blocking mode: populates receive buffers.

Parameters
sendProcsranks used for sends
recvProcsranks used for recvs
waitwait for requests to complete (in nonBlocking mode)
Warning
currently only valid for nonBlocking comms.

Definition at line 422 of file PstreamBuffers.C.

◆ finishedSends() [4/5]

void finishedSends ( const labelUList sendProcs,
const labelUList recvProcs,
labelList recvSizes,
const bool  wait = true 
)

Mark sends as done using subset of send/recv ranks to exchange data on. Recovers the sizes (bytes) received.

Non-blocking mode: populates receive buffers.

Parameters
sendProcsranks used for sends
recvProcsranks used for recvs
[out]recvSizesthe sizes (bytes) received
waitwait for requests to complete (in nonBlocking mode)
Warning
currently only valid for nonBlocking comms.

Definition at line 434 of file PstreamBuffers.C.

References UPstream::commsTypeNames, Foam::endl(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, and UPstream::nonBlocking.

Here is the call graph for this function:

◆ finishedSends() [5/5]

bool finishedSends ( bitSet sendConnections,
DynamicList< label > &  sendProcs,
DynamicList< label > &  recvProcs,
const bool  wait = true 
)

A caching version that uses a limited send/recv connectivity.

Non-blocking mode: populates receive buffers.

Parameters
sendConnectionson/off for sending ranks
sendProcsranks used for sends
recvProcsranks used for recvs
waitwait for requests to complete (in nonBlocking mode)
Returns
True if the send/recv connectivity changed
Warning
currently only valid for nonBlocking comms.

Definition at line 458 of file PstreamBuffers.C.

References DynamicList< T, SizeMin >::append(), DynamicList< T, SizeMin >::clear(), forAll, Foam::reduce(), PackedList< Width >::resize(), bitSet::set(), and PackedList< Width >::size().

Here is the call graph for this function:

◆ finishedNeighbourSends() [1/2]

void finishedNeighbourSends ( const labelUList neighProcs,
const bool  wait = true 
)
inline

Mark sends as done using subset of send/recv ranks and recover the sizes (bytes) received.

Non-blocking mode: populates receive buffers.

Parameters
neighProcsranks used for sends/recvs
waitwait for requests to complete (in nonBlocking mode)
Warning
currently only valid for nonBlocking comms.
Note
Same as finishedSends with identical sendProcs/recvProcs

Definition at line 397 of file PstreamBuffers.H.

Referenced by syncTools::syncBoundaryFaceList(), syncTools::syncEdgeMap(), and syncTools::syncPointMap().

Here is the caller graph for this function:

◆ finishedNeighbourSends() [2/2]

void finishedNeighbourSends ( const labelUList neighProcs,
labelList recvSizes,
const bool  wait = true 
)
inline

Mark sends as done using subset of send/recv ranks and recover the sizes (bytes) received.

Non-blocking mode: it will populate receive buffers.

Parameters
neighProcsranks used for sends/recvs
[out]recvSizesthe sizes (bytes) received
waitwait for requests to complete (in nonBlocking mode)
Warning
currently only valid for nonBlocking mode.

Definition at line 416 of file PstreamBuffers.H.

◆ finishedGathers() [1/2]

void finishedGathers ( const bool  wait = true)

Mark all sends to master as done.

Non-blocking mode: populates receive buffers. Can use recvDataCounts() method to recover sizes received.

Parameters
waitwait for requests to complete (in nonBlocking mode)
Warning
currently only valid for nonBlocking comms.

Definition at line 526 of file PstreamBuffers.C.

Referenced by surfaceNoise::surfaceAverage(), energySpectrum::write(), and surfaceNoise::writeSurfaceData().

Here is the caller graph for this function:

◆ finishedGathers() [2/2]

void finishedGathers ( labelList recvSizes,
const bool  wait = true 
)

Mark all sends to master as done. Recovers the sizes (bytes) received.

Non-blocking mode: populates receive buffers (all-to-one).

Parameters
[out]recvSizesthe sizes (bytes) received
waitwait for requests to complete (in nonBlocking mode)
Warning
currently only valid for nonBlocking comms.

Definition at line 538 of file PstreamBuffers.C.

References UPstream::commsTypeNames, Foam::endl(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, and UPstream::nonBlocking.

Here is the call graph for this function:

◆ finishedScatters() [1/2]

void finishedScatters ( const bool  wait = true)

Mark all sends to sub-procs as done.

Non-blocking mode: populates receive buffers. Can use recvDataCounts() method to recover sizes received.

Parameters
waitwait for requests to complete (in nonBlocking mode)
Warning
currently only valid for nonBlocking comms.

Definition at line 532 of file PstreamBuffers.C.

Referenced by decomposedBlockData::readBlocks(), masterUncollatedFileOperation::readHeader(), surfaceNoise::readSurfaceData(), and masterUncollatedFileOperation::scatterList().

Here is the caller graph for this function:

◆ finishedScatters() [2/2]

void finishedScatters ( labelList recvSizes,
const bool  wait = true 
)

Mark all sends to sub-procs as done. Recovers the sizes (bytes) received.

Non-blocking mode: populates receive buffers (all-to-one).

Parameters
[out]recvSizesthe sizes (bytes) received
waitwait for requests to complete (in nonBlocking mode)
Warning
currently only valid for nonBlocking comms.

Definition at line 565 of file PstreamBuffers.C.

References UPstream::commsTypeNames, Foam::endl(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, and UPstream::nonBlocking.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ UOPstreamBase

friend class UOPstreamBase
friend

Definition at line 120 of file PstreamBuffers.H.

◆ UIPstreamBase

friend class UIPstreamBase
friend

Definition at line 121 of file PstreamBuffers.H.


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