ENH: bundle Pstream:: AllGather methods

- bundles frequently used 'gather/scatter' patterns more consistently.

  - combineAllGather     -> combineGather + broadcast
  - listCombineAllGather -> listCombineGather + broadcast
  - mapCombineAllGather  -> mapCombineGather + broadcast
  - allGatherList        -> gatherList + scatterList
  - reduce               -> gather + broadcast (ie, allreduce)

- The allGatherList currently wraps gatherList/scatterList, but may be
  replaced with a different algorithm in the future.

STYLE: PstreamCombineReduceOps.H is mostly unneeded now
This commit is contained in:
Mark Olesen
2022-03-28 16:30:51 +02:00
parent e98acdc4fc
commit d38de84d21
105 changed files with 935 additions and 605 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -661,11 +661,8 @@ void countExtrudePatches
}
// Synchronise decision. Actual numbers are not important, just make
// sure that they're > 0 on all processors.
Pstream::listCombineGather(zoneSidePatch, plusEqOp<label>());
Pstream::listCombineGather(zoneZonePatch, plusEqOp<label>());
Pstream::broadcast(zoneSidePatch);
Pstream::broadcast(zoneZonePatch);
Pstream::listCombineAllGather(zoneSidePatch, plusEqOp<label>());
Pstream::listCombineAllGather(zoneZonePatch, plusEqOp<label>());
}
@ -1465,8 +1462,7 @@ int main(int argc, char *argv[])
{
List<wordList> allNames(Pstream::nProcs());
allNames[Pstream::myProcNo()] = mesh.boundaryMesh().names();
Pstream::gatherList(allNames);
Pstream::scatterList(allNames);
Pstream::allGatherList(allNames);
FatalErrorInFunction
<< "Patches are not synchronised on all processors."
@ -1858,8 +1854,7 @@ int main(int argc, char *argv[])
const primitiveFacePatch extrudePatch(std::move(zoneFaces), mesh.points());
Pstream::listCombineGather(isInternal, orEqOp<bool>());
Pstream::broadcast(isInternal);
Pstream::listCombineAllGather(isInternal, orEqOp<bool>());
// Check zone either all internal or all external faces
checkZoneInside(mesh, zoneNames, zoneID, extrudeMeshFaces, isInternal);
@ -2320,8 +2315,7 @@ int main(int argc, char *argv[])
}
// Reduce
Pstream::mapCombineGather(globalSum, plusEqOp<point>());
Pstream::broadcast(globalSum);
Pstream::mapCombineAllGather(globalSum, plusEqOp<point>());
forAll(localToGlobalRegion, localRegionI)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -157,8 +157,7 @@ bool Foam::DistributedDelaunayMesh<Triangulation>::distributeBoundBoxes
// Give the bounds of every processor to every other processor
allBackgroundMeshBounds_()[Pstream::myProcNo()] = bb;
Pstream::gatherList(allBackgroundMeshBounds_());
Pstream::scatterList(allBackgroundMeshBounds_());
Pstream::allGatherList(allBackgroundMeshBounds_());
return true;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -713,8 +713,7 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree()
// Give the bounds of every processor to every other processor
allBackgroundMeshBounds_[Pstream::myProcNo()] = overallBb;
Pstream::gatherList(allBackgroundMeshBounds_);
Pstream::scatterList(allBackgroundMeshBounds_);
Pstream::allGatherList(allBackgroundMeshBounds_);
// find global bounding box
globalBackgroundBounds_ = treeBoundBox(boundBox::invertedBox);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -1564,8 +1564,7 @@ Foam::label Foam::conformalVoronoiMesh::createPatchInfo
}
// Because the previous test was insufficient, combine the lists.
Pstream::gatherList(procUsedList);
Pstream::scatterList(procUsedList);
Pstream::allGatherList(procUsedList);
forAll(procUsedList, proci)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -692,11 +692,8 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseSurfaceTrees
);
List<pointIndexHitAndFeatureDynList> procSurfLocations(Pstream::nProcs());
procSurfLocations[Pstream::myProcNo()] = surfaceHits;
Pstream::gatherList(procSurfLocations);
Pstream::scatterList(procSurfLocations);
Pstream::allGatherList(procSurfLocations);
List<labelHashSet> hits(Pstream::nProcs());
@ -732,8 +729,7 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseSurfaceTrees
}
}
Pstream::listCombineGather(hits, plusEqOp<labelHashSet>());
Pstream::broadcast(hits);
Pstream::listCombineAllGather(hits, plusEqOp<labelHashSet>());
forAll(surfaceHits, eI)
{
@ -780,11 +776,8 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseEdgeTrees
);
List<pointIndexHitAndFeatureDynList> procEdgeLocations(Pstream::nProcs());
procEdgeLocations[Pstream::myProcNo()] = featureEdgeHits;
Pstream::gatherList(procEdgeLocations);
Pstream::scatterList(procEdgeLocations);
Pstream::allGatherList(procEdgeLocations);
List<labelHashSet> hits(Pstream::nProcs());
@ -823,8 +816,7 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseEdgeTrees
}
}
Pstream::listCombineGather(hits, plusEqOp<labelHashSet>());
Pstream::broadcast(hits);
Pstream::listCombineAllGather(hits, plusEqOp<labelHashSet>());
forAll(featureEdgeHits, eI)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -142,10 +142,7 @@ Foam::List<Vb::Point> Foam::pointFile::initialPoints() const
List<boolList> allProcPt(Pstream::nProcs());
allProcPt[Pstream::myProcNo()] = procPt;
Pstream::gatherList(allProcPt);
Pstream::scatterList(allProcPt);
Pstream::allGatherList(allProcPt);
forAll(procPt, ptI)
{

View File

@ -474,8 +474,11 @@ Foam::label Foam::checkTopology
}
}
Pstream::listCombineGather(regionDisconnected, andEqOp<bool>());
Pstream::broadcast(regionDisconnected);
Pstream::listCombineAllGather
(
regionDisconnected,
andEqOp<bool>()
);
}

View File

@ -713,9 +713,8 @@ void syncPoints
sharedPts[pd.sharedPointAddr()[i]] = points[meshPointi];
}
// Combine on master.
Pstream::listCombineGather(sharedPts, cop);
Pstream::broadcast(sharedPts);
// Combine - globally consistent
Pstream::listCombineAllGather(sharedPts, cop);
// Now we will all have the same information. Merge it back with
// my local information.

View File

@ -1111,8 +1111,7 @@ label findCorrespondingRegion
}
}
Pstream::listCombineGather(cellsInZone, plusEqOp<label>());
Pstream::broadcast(cellsInZone);
Pstream::listCombineAllGather(cellsInZone, plusEqOp<label>());
// Pick region with largest overlap of zoneI
label regionI = findMax(cellsInZone);

View File

@ -223,7 +223,7 @@ bool writeOptionalMeshObject
// Make sure all know if there is a valid class name
wordList classNames(1, io.headerClassName());
combineReduce(classNames, uniqueEqOp<word>());
Pstream::combineAllGather(classNames, uniqueEqOp<word>());
// Check for correct type
if (classNames[0] == T::typeName)
@ -422,7 +422,7 @@ int main(int argc, char *argv[])
)
);
combineReduce(lagrangianDirs, uniqueEqOp<fileName>());
Pstream::combineAllGather(lagrangianDirs, uniqueEqOp<fileName>());
if (!lagrangianDirs.empty())
{
@ -459,7 +459,7 @@ int main(int argc, char *argv[])
)
);
combineReduce(cloudDirs, uniqueEqOp<fileName>());
Pstream::combineAllGather(cloudDirs, uniqueEqOp<fileName>());
forAll(cloudDirs, i)
{
@ -485,7 +485,7 @@ int main(int argc, char *argv[])
);
// Combine with all other cloud objects
combineReduce(cloudFields, uniqueEqOp<word>());
Pstream::combineAllGather(cloudFields, uniqueEqOp<word>());
for (const word& name : cloudFields)
{

View File

@ -286,7 +286,7 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
nsTransPs[sendProcI] = subMap[sendProcI].size();
}
// Send sizes across. Note: blocks.
combineReduce(sizes, Pstream::listEq());
Pstream::combineAllGather(sizes, Pstream::listEq());
labelListList constructMap(Pstream::nProcs());
label constructSize = 0;

View File

@ -2649,7 +2649,7 @@ int main(int argc, char *argv[])
bool nfs = true;
{
List<fileName> roots(1, args.rootPath());
combineReduce(roots, ListOps::uniqueEqOp<fileName>());
Pstream::combineAllGather(roots, ListOps::uniqueEqOp<fileName>());
nfs = (roots.size() == 1);
}
@ -3280,8 +3280,7 @@ int main(int argc, char *argv[])
)
);
meshDir[Pstream::myProcNo()] = fName.path();
Pstream::gatherList(meshDir);
Pstream::scatterList(meshDir);
Pstream::allGatherList(meshDir);
//Info<< "Per processor faces dirs:" << nl
// << " " << meshDir << nl << endl;
}

View File

@ -104,12 +104,11 @@ if (timeDirs.size() && doLagrangian)
{
for (auto& cloudFields : regionCloudFields)
{
Pstream::mapCombineGather
Pstream::mapCombineAllGather
(
cloudFields,
HashTableOps::plusEqOp<word>()
);
Pstream::broadcast(cloudFields);
}
}
}

View File

@ -122,7 +122,7 @@ Usage
#include "IOobjectList.H"
#include "IOmanip.H"
#include "OFstream.H"
#include "PstreamCombineReduceOps.H"
#include "Pstream.H"
#include "HashOps.H"
#include "regionProperties.H"

View File

@ -187,8 +187,7 @@ int main(int argc, char *argv[])
const label maxNProcs = returnReduce(maxIds.size(), maxOp<label>());
maxIds.resize(maxNProcs, -1);
Pstream::listCombineGather(maxIds, maxEqOp<label>());
Pstream::broadcast(maxIds);
Pstream::listCombineAllGather(maxIds, maxEqOp<label>());
// From ids to count
const labelList numIds = maxIds + 1;

View File

@ -40,8 +40,7 @@ Foam::Field<T> Foam::channelIndex::regionSum(const Field<T>& cellField) const
}
// Global sum
Pstream::listCombineGather(regionField, plusEqOp<T>());
Pstream::broadcast(regionField);
Pstream::listCombineAllGather(regionField, plusEqOp<T>());
return regionField;
}

View File

@ -287,8 +287,7 @@ bool setFaceFieldType
}
}
Pstream::listCombineGather(nChanged, plusEqOp<label>());
Pstream::broadcast(nChanged);
Pstream::listCombineAllGather(nChanged, plusEqOp<label>());
auto& fieldBf = field.boundaryFieldRef();

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -456,12 +456,9 @@ int main(int argc, char *argv[])
remoteCoarseSf[Pstream::myProcNo()] = localCoarseSf;
remoteCoarseAgg[Pstream::myProcNo()] = localAgg;
Pstream::gatherList(remoteCoarseCf);
Pstream::scatterList(remoteCoarseCf);
Pstream::gatherList(remoteCoarseSf);
Pstream::scatterList(remoteCoarseSf);
Pstream::gatherList(remoteCoarseAgg);
Pstream::scatterList(remoteCoarseAgg);
Pstream::allGatherList(remoteCoarseCf);
Pstream::allGatherList(remoteCoarseSf);
Pstream::allGatherList(remoteCoarseAgg);
globalIndex globalNumbering(nCoarseFaces);

View File

@ -198,8 +198,7 @@ int main(int argc, char *argv[])
boundBox(mesh.points(), false)
).extend(rndGen, 1e-3)
);
Pstream::gatherList(meshBb);
Pstream::scatterList(meshBb);
Pstream::allGatherList(meshBb);
}
IOobject io