ENH: simpler use of broadcast (via Pstream::scatter)
- avoids worrying about forgetting a (Pstream::parRun()) guard and reduces code. The Pstream::scatter does the same thing under the hood.
This commit is contained in:
parent
5368b38b8d
commit
f3674eee36
@ -90,21 +90,8 @@ Foam::autoPtr<Foam::fvMesh> Foam::loadOrCreateMesh
|
||||
Pstream::parRun(oldParRun);
|
||||
}
|
||||
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
if (Pstream::master())
|
||||
{
|
||||
// Broadcast: send patches
|
||||
OPBstream toAll(Pstream::masterNo());
|
||||
toAll << patchEntries;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Broadcast: receive patches
|
||||
IPBstream fromMaster(Pstream::masterNo());
|
||||
fromMaster >> patchEntries;
|
||||
}
|
||||
}
|
||||
// Broadcast: send patches to all
|
||||
Pstream::scatter(patchEntries); // == worldComm;
|
||||
|
||||
|
||||
// Dummy meshes
|
||||
|
@ -430,37 +430,25 @@ void Foam::globalMeshData::calcSharedEdges() const
|
||||
<< " down to " << globalShared.size() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Broadcast: send back to all
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
OPBstream toAll(Pstream::masterNo()); // == worldComm
|
||||
toAll << globalShared;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
// Send local edges to master
|
||||
{
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::blocking,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
toMaster << localShared;
|
||||
}
|
||||
|
||||
// Broadcast: receive merged edges from master
|
||||
{
|
||||
IPBstream fromMaster(Pstream::masterNo()); // == worldComm
|
||||
fromMaster >> globalShared;
|
||||
}
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::blocking,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
toMaster << localShared;
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast: merged edges to all
|
||||
Pstream::scatter(globalShared); // == worldComm;
|
||||
|
||||
|
||||
// Now use the global shared edges list (globalShared) to classify my local
|
||||
// ones (localShared)
|
||||
|
||||
@ -1908,17 +1896,12 @@ Foam::pointField Foam::globalMeshData::sharedPoints() const
|
||||
sharedPoints[sharedPointi] = nbrSharedPoints[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast: send back
|
||||
{
|
||||
OPBstream toAll(Pstream::masterNo()); // == worldComm
|
||||
toAll << sharedPoints;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send address and points
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
// Send address and points
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::blocking,
|
||||
@ -1926,16 +1909,14 @@ Foam::pointField Foam::globalMeshData::sharedPoints() const
|
||||
);
|
||||
toMaster
|
||||
<< pointAddr
|
||||
<< UIndirectList<point>(mesh_.points(), pointLabels)();
|
||||
}
|
||||
|
||||
// Broadcast: receive sharedPoints
|
||||
{
|
||||
IPBstream fromMaster(Pstream::masterNo()); // == worldComm
|
||||
fromMaster >> sharedPoints;
|
||||
<< pointField(mesh_.points(), pointLabels);
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast: sharedPoints to all
|
||||
Pstream::scatter(sharedPoints); // == worldComm
|
||||
|
||||
|
||||
return sharedPoints;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
|
||||
const label nProcs = Pstream::nProcs(comm);
|
||||
|
||||
// Communications: send and receive processor
|
||||
List<labelPair> allComms;
|
||||
DynamicList<labelPair> allComms;
|
||||
|
||||
{
|
||||
labelPairHashSet commsSet(nProcs);
|
||||
@ -80,41 +80,31 @@ Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
|
||||
}
|
||||
|
||||
|
||||
// Reduce
|
||||
// Gather/reduce
|
||||
if (Pstream::master(comm))
|
||||
{
|
||||
// Receive and merge
|
||||
for (const int slave : Pstream::subProcs(comm))
|
||||
for (const int proci : Pstream::subProcs(comm))
|
||||
{
|
||||
IPstream fromSlave
|
||||
IPstream fromProc
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
slave,
|
||||
proci,
|
||||
0,
|
||||
tag,
|
||||
comm
|
||||
);
|
||||
List<labelPair> nbrData(fromSlave);
|
||||
List<labelPair> nbrData(fromProc);
|
||||
|
||||
forAll(nbrData, i)
|
||||
for (const labelPair& connection : nbrData)
|
||||
{
|
||||
if (!allComms.found(nbrData[i]))
|
||||
{
|
||||
label sz = allComms.size();
|
||||
allComms.setSize(sz+1);
|
||||
allComms[sz] = nbrData[i];
|
||||
}
|
||||
allComms.appendUniq(connection);
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast: send merged to all
|
||||
{
|
||||
OPBstream toAll(Pstream::masterNo(), comm);
|
||||
toAll << allComms;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
OPstream toMaster
|
||||
(
|
||||
@ -126,14 +116,11 @@ Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
|
||||
);
|
||||
toMaster << allComms;
|
||||
}
|
||||
|
||||
// Broadcast: receive merged
|
||||
{
|
||||
IPBstream fromMaster(Pstream::masterNo(), comm);
|
||||
fromMaster >> allComms;
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast: send comms information to all
|
||||
Pstream::scatter(allComms, tag, comm);
|
||||
|
||||
|
||||
// Determine my schedule.
|
||||
labelList mySchedule
|
||||
|
@ -309,33 +309,21 @@ void Foam::syncTools::syncPointMap
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast: send merged values to all
|
||||
{
|
||||
OPBstream toAll(Pstream::masterNo()); // == worldComm
|
||||
toAll << sharedPointValues;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send to master
|
||||
{
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
toMaster << sharedPointValues;
|
||||
}
|
||||
|
||||
// Broadcast: receive merged values
|
||||
{
|
||||
IPBstream fromMaster(Pstream::masterNo()); // == worldComm
|
||||
fromMaster >> sharedPointValues;
|
||||
}
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
toMaster << sharedPointValues;
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast: send merged values to all
|
||||
Pstream::scatter(sharedPointValues);
|
||||
}
|
||||
|
||||
// Merge sharedPointValues (keyed on sharedPointAddr) into
|
||||
// pointValues (keyed on mesh points).
|
||||
@ -664,12 +652,6 @@ void Foam::syncTools::syncEdgeMap
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast: send merged values to all
|
||||
{
|
||||
OPBstream toAll(Pstream::masterNo()); // == worldComm
|
||||
toAll << sharedEdgeValues;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -682,13 +664,10 @@ void Foam::syncTools::syncEdgeMap
|
||||
);
|
||||
toMaster << sharedEdgeValues;
|
||||
}
|
||||
|
||||
// Broadcast: receive merged values
|
||||
{
|
||||
IPBstream fromMaster(Pstream::masterNo()); // == worldComm
|
||||
fromMaster >> sharedEdgeValues;
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast: send merged values to all
|
||||
Pstream::scatter(sharedEdgeValues);
|
||||
}
|
||||
|
||||
|
||||
|
@ -480,22 +480,8 @@ Foam::autoPtr<Foam::fvMesh> Foam::fvMeshTools::newMesh
|
||||
Pstream::parRun(oldParRun);
|
||||
}
|
||||
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
if (Pstream::master())
|
||||
{
|
||||
// Broadcast: send patches to all
|
||||
OPBstream toAll(Pstream::masterNo()); // == worldComm
|
||||
toAll << patchEntries;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Broadcast: receive patches
|
||||
IPBstream fromMaster(Pstream::masterNo()); // == worldComm
|
||||
fromMaster >> patchEntries;
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast information to all
|
||||
Pstream::scatter(patchEntries);
|
||||
Pstream::scatter(facesInstance);
|
||||
Pstream::scatter(pointsInstance);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user