ENH: use mpi gather for list values in a few places

- avoid gatherList/scatterList when value are only need on master
This commit is contained in:
Mark Olesen
2022-02-25 17:42:57 +01:00
committed by Andrew Heather
parent c086f22298
commit af8161925b
9 changed files with 180 additions and 199 deletions

View File

@ -3,12 +3,14 @@ phaseSystem = $(LIB_SRC)/phaseSystemModels/multiphaseInter
EXE_INC = \ EXE_INC = \
-I${phaseSystem}/phasesSystem/lnInclude \ -I${phaseSystem}/phasesSystem/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/radiation/lnInclude -I$(LIB_SRC)/thermophysicalModels/radiation/lnInclude
LIB_LIBS = \ LIB_LIBS = \
-lfiniteVolume \ -lfiniteVolume \
-lfileFormats \
-lmeshTools \ -lmeshTools \
-llagrangian \ -llagrangian \
-lradiationModels \ -lradiationModels \

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -31,11 +31,12 @@ License
#include "absorptionEmissionModel.H" #include "absorptionEmissionModel.H"
#include "scatterModel.H" #include "scatterModel.H"
#include "constants.H" #include "constants.H"
#include "addToRunTimeSelectionTable.H"
#include "unitConversion.H" #include "unitConversion.H"
#include "interpolationCell.H" #include "interpolationCell.H"
#include "interpolationCellPoint.H" #include "interpolationCellPoint.H"
#include "Random.H" #include "Random.H"
#include "OBJstream.H"
#include "addToRunTimeSelectionTable.H"
using namespace Foam::constant; using namespace Foam::constant;
@ -679,44 +680,28 @@ void Foam::radiation::laserDTRM::calculate()
Info<< "Final number of particles..." Info<< "Final number of particles..."
<< returnReduce(DTRMCloud_.size(), sumOp<label>()) << endl; << returnReduce(DTRMCloud_.size(), sumOp<label>()) << endl;
OFstream osRef(type() + ":particlePath.obj"); pointField lines(2*DTRMCloud_.size());
label vertI = 0; {
label i = 0;
List<pointField> positions(Pstream::nProcs());
List<pointField> p0(Pstream::nProcs());
DynamicList<point> positionsMyProc;
DynamicList<point> p0MyProc;
for (const DTRMParticle& p : DTRMCloud_) for (const DTRMParticle& p : DTRMCloud_)
{ {
positionsMyProc.append(p.position()); lines[i] = p.position();
p0MyProc.append(p.p0()); lines[i+1] = p.p0();
i += 2;
}
} }
positions[Pstream::myProcNo()].transfer(positionsMyProc); globalIndex::gatherInplaceOp(lines);
p0[Pstream::myProcNo()].transfer(p0MyProc);
Pstream::gatherList(positions); if (Pstream::master())
Pstream::scatterList(positions);
Pstream::gatherList(p0);
Pstream::scatterList(p0);
for (const int proci : Pstream::allProcs())
{ {
const pointField& pos = positions[proci]; OBJstream os(type() + ":particlePath.obj");
const pointField& pfinal = p0[proci];
forAll(pos, i)
{
meshTools::writeOBJ(osRef, pos[i]);
vertI++;
meshTools::writeOBJ(osRef, pfinal[i]);
vertI++;
osRef << "l " << vertI-1 << ' ' << vertI << nl;
}
}
osRef.flush(); for (label pointi = 0; pointi < lines.size(); pointi += 2)
{
os.write(linePointRef(lines[pointi], lines[pointi+1]));
}
}
scalar totalQ = gSum(Q_.primitiveFieldRef()*mesh_.V()); scalar totalQ = gSum(Q_.primitiveFieldRef()*mesh_.V());
Info << "Total energy absorbed [W]: " << totalQ << endl; Info << "Total energy absorbed [W]: " << totalQ << endl;

View File

@ -261,15 +261,17 @@ boolList haveFacesFile(const fileName& meshPath)
{ {
const fileName facesPath(meshPath/"faces"); const fileName facesPath(meshPath/"faces");
Info<< "Checking for mesh in " << facesPath << nl << endl; Info<< "Checking for mesh in " << facesPath << nl << endl;
boolList haveMesh(Pstream::nProcs(), false); boolList haveMesh
haveMesh[Pstream::myProcNo()] = fileHandler().isFile
( (
fileHandler().filePath(facesPath) UPstream::listGatherValues<bool>
(
fileHandler().isFile(fileHandler().filePath(facesPath))
)
); );
Pstream::gatherList(haveMesh);
Pstream::scatterList(haveMesh);
Info<< "Per processor mesh availability:" << nl Info<< "Per processor mesh availability:" << nl
<< " " << flatOutput(haveMesh) << nl << endl; << " " << flatOutput(haveMesh) << nl << endl;
Pstream::broadcast(haveMesh);
return haveMesh; return haveMesh;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -63,34 +63,30 @@ void writeProcStats
{ {
// Determine surface bounding boxes, faces, points // Determine surface bounding boxes, faces, points
List<treeBoundBox> surfBb(Pstream::nProcs()); List<treeBoundBox> surfBb(Pstream::nProcs());
{
surfBb[Pstream::myProcNo()] = treeBoundBox(s.points()); surfBb[Pstream::myProcNo()] = treeBoundBox(s.points());
Pstream::gatherList(surfBb); Pstream::gatherList(surfBb);
Pstream::scatterList(surfBb);
}
labelList nPoints(Pstream::nProcs()); labelList nPoints(UPstream::listGatherValues<label>(s.points().size()));
nPoints[Pstream::myProcNo()] = s.points().size(); labelList nFaces(UPstream::listGatherValues<label>(s.size()));
Pstream::gatherList(nPoints);
Pstream::scatterList(nPoints);
labelList nFaces(Pstream::nProcs());
nFaces[Pstream::myProcNo()] = s.size();
Pstream::gatherList(nFaces);
Pstream::scatterList(nFaces);
if (Pstream::master())
{
forAll(surfBb, proci) forAll(surfBb, proci)
{ {
Info<< "processor" << proci << nl; Info<< "processor" << proci << nl;
const List<treeBoundBox>& bbs = meshBb[proci]; const List<treeBoundBox>& bbs = meshBb[proci];
if (bbs.size()) forAll(bbs, i)
{ {
Info<< "\tMesh bounds : " << bbs[0] << nl; if (!i)
for (label i = 1; i < bbs.size(); i++)
{ {
Info<< "\t " << bbs[i]<< nl; Info<< "\tMesh bounds : ";
} }
else
{
Info<< "\t ";
}
Info<< bbs[i] << nl;
} }
Info<< "\tSurface bounding box : " << surfBb[proci] << nl Info<< "\tSurface bounding box : " << surfBb[proci] << nl
<< "\tTriangles : " << nFaces[proci] << nl << "\tTriangles : " << nFaces[proci] << nl
@ -99,6 +95,7 @@ void writeProcStats
} }
Info<< endl; Info<< endl;
} }
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd. Copyright (C) 2020-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -115,10 +115,7 @@ void Foam::masterOFstream::commit()
return; return;
} }
boolList valid(Pstream::nProcs()); boolList valid(UPstream::listGatherValues<bool>(valid_));
valid[Pstream::myProcNo()] = valid_;
Pstream::gatherList(valid);
// Different files // Different files
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -79,47 +79,37 @@ Foam::label Foam::AMIInterpolation::calcDistribution
const primitivePatch& tgtPatch const primitivePatch& tgtPatch
) const ) const
{ {
// Either not parallel or no faces on any processor
label proci = 0; label proci = 0;
if (Pstream::parRun()) if (Pstream::parRun())
{ {
labelList facesPresentOnProc(Pstream::nProcs(), Zero); const bitSet hasFaces
if ((srcPatch.size() > 0) || (tgtPatch.size() > 0)) (
{ UPstream::listGatherValues<bool>
facesPresentOnProc[Pstream::myProcNo()] = 1; (
} srcPatch.size() > 0 || tgtPatch.size() > 0
else )
{ );
facesPresentOnProc[Pstream::myProcNo()] = 0;
}
Pstream::gatherList(facesPresentOnProc); const auto nHaveFaces = hasFaces.count();
Pstream::scatterList(facesPresentOnProc);
label nHaveFaces = sum(facesPresentOnProc); if (nHaveFaces == 1)
if (nHaveFaces > 1)
{ {
proci = -1; proci = hasFaces.find_first();
if (debug) DebugInFunction
{
InfoInFunction
<< "AMI split across multiple processors" << endl;
}
}
else if (nHaveFaces == 1)
{
proci = facesPresentOnProc.find(1);
if (debug)
{
InfoInFunction
<< "AMI local to processor" << proci << endl; << "AMI local to processor" << proci << endl;
} }
} else if (nHaveFaces > 1)
{
proci = -1;
DebugInFunction
<< "AMI split across multiple processors" << endl;
} }
Pstream::broadcast(proci);
}
// Either not parallel or no faces on any processor
return proci; return proci;
} }

View File

@ -241,15 +241,17 @@ void Foam::mappedPatchBase::collectSamples
} }
{ {
labelList procToWorldIndex(nProcs); labelList procToWorldIndex
procToWorldIndex[myRank] = mySampleWorld; (
Pstream::gatherList(procToWorldIndex, Pstream::msgType(), myComm); UPstream::listGatherValues<label>(mySampleWorld, myComm)
Pstream::scatterList(procToWorldIndex, Pstream::msgType(), myComm); );
Pstream::broadcast(procToWorldIndex, myComm);
labelList nPerProc(nProcs); labelList nPerProc
nPerProc[myRank] = patch_.size(); (
Pstream::gatherList(nPerProc, Pstream::msgType(), myComm); UPstream::listGatherValues<label>(patch_.size(), myComm)
Pstream::scatterList(nPerProc, Pstream::msgType(), myComm); );
Pstream::broadcast(nPerProc, myComm);
patchFaceWorlds.setSize(patchFaces.size()); patchFaceWorlds.setSize(patchFaces.size());
patchFaceProcs.setSize(patchFaces.size()); patchFaceProcs.setSize(patchFaces.size());

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -2475,11 +2475,13 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh
InfoInFunction << "Constructed from triSurface:" << endl; InfoInFunction << "Constructed from triSurface:" << endl;
writeStats(Info); writeStats(Info);
labelList nTris(Pstream::nProcs()); labelList nTris
nTris[Pstream::myProcNo()] = triSurface::size(); (
Pstream::gatherList(nTris); UPstream::listGatherValues<label>(triSurface::size())
Pstream::scatterList(nTris); );
if (Pstream::master())
{
Info<< endl<< "\tproc\ttris\tbb" << endl; Info<< endl<< "\tproc\ttris\tbb" << endl;
forAll(nTris, proci) forAll(nTris, proci)
{ {
@ -2489,6 +2491,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh
Info<< endl; Info<< endl;
} }
} }
}
Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh(const IOobject& io) Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh(const IOobject& io)
@ -2573,11 +2576,13 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh(const IOobject& io)
<< "Read distributedTriSurface " << io.name() << "Read distributedTriSurface " << io.name()
<< " from actual path " << actualFile << ':' << endl; << " from actual path " << actualFile << ':' << endl;
labelList nTris(Pstream::nProcs()); labelList nTris
nTris[Pstream::myProcNo()] = triSurface::size(); (
Pstream::gatherList(nTris); UPstream::listGatherValues<label>(triSurface::size())
Pstream::scatterList(nTris); );
if (Pstream::master())
{
Info<< endl<< "\tproc\ttris\tbb" << endl; Info<< endl<< "\tproc\ttris\tbb" << endl;
forAll(nTris, proci) forAll(nTris, proci)
{ {
@ -2587,6 +2592,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh(const IOobject& io)
Info<< endl; Info<< endl;
} }
} }
}
if (debug) if (debug)
{ {
InfoInFunction InfoInFunction
@ -2714,11 +2720,13 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh
<< " from actual path " << actualFile << " from actual path " << actualFile
<< " and dictionary:" << endl; << " and dictionary:" << endl;
labelList nTris(Pstream::nProcs()); labelList nTris
nTris[Pstream::myProcNo()] = triSurface::size(); (
Pstream::gatherList(nTris); UPstream::listGatherValues<label>(triSurface::size())
Pstream::scatterList(nTris); );
if (Pstream::master())
{
Info<< endl<< "\tproc\ttris\tbb" << endl; Info<< endl<< "\tproc\ttris\tbb" << endl;
forAll(nTris, proci) forAll(nTris, proci)
{ {
@ -2728,6 +2736,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh
Info<< endl; Info<< endl;
} }
} }
}
if (debug) if (debug)
{ {
InfoInFunction InfoInFunction
@ -4534,11 +4543,13 @@ void Foam::distributedTriSurfaceMesh::distribute
// Debug information // Debug information
if (debug) if (debug)
{ {
labelList nTris(Pstream::nProcs()); labelList nTris
nTris[Pstream::myProcNo()] = triSurface::size(); (
Pstream::gatherList(nTris); UPstream::listGatherValues<label>(triSurface::size())
Pstream::scatterList(nTris); );
if (Pstream::master())
{
InfoInFunction InfoInFunction
<< "before distribution:" << endl << "\tproc\ttris" << endl; << "before distribution:" << endl << "\tproc\ttris" << endl;
@ -4548,6 +4559,7 @@ void Foam::distributedTriSurfaceMesh::distribute
} }
Info<< endl; Info<< endl;
} }
}
// Use procBbs to determine which faces go where // Use procBbs to determine which faces go where
@ -4757,11 +4769,13 @@ void Foam::distributedTriSurfaceMesh::distribute
if (debug) if (debug)
{ {
labelList nTris(Pstream::nProcs()); labelList nTris
nTris[Pstream::myProcNo()] = triSurface::size(); (
Pstream::gatherList(nTris); UPstream::listGatherValues<label>(triSurface::size())
Pstream::scatterList(nTris); );
if (Pstream::master())
{
InfoInFunction InfoInFunction
<< "after distribution:" << endl << "\tproc\ttris" << endl; << "after distribution:" << endl << "\tproc\ttris" << endl;
@ -4770,19 +4784,18 @@ void Foam::distributedTriSurfaceMesh::distribute
Info<< '\t' << proci << '\t' << nTris[proci] << endl; Info<< '\t' << proci << '\t' << nTris[proci] << endl;
} }
Info<< endl; Info<< endl;
}
if (debug & 2) if (debug & 2)
{ {
OBJstream str(searchableSurface::time().path()/"after.obj"); OBJstream str(searchableSurface::time().path()/"after.obj");
Info<< "Writing local bounding box to " << str.name() << endl; Info<< "Writing local bounding box to " << str.name() << endl;
const List<treeBoundBox>& myBbs = procBb_[Pstream::myProcNo()]; const List<treeBoundBox>& myBbs = procBb_[Pstream::myProcNo()];
forAll(myBbs, i) for (const treeBoundBox& bb : myBbs)
{ {
pointField pts(myBbs[i].points()); pointField pts(bb.points());
const edgeList& es = treeBoundBox::edges; for (const edge& e : treeBoundBox::edges)
forAll(es, ei)
{ {
const edge& e = es[ei];
str.write(linePointRef(pts[e[0]], pts[e[1]])); str.write(linePointRef(pts[e[0]], pts[e[1]]));
} }
} }
@ -4791,15 +4804,13 @@ void Foam::distributedTriSurfaceMesh::distribute
{ {
OBJstream str(searchableSurface::time().path()/"after_all.obj"); OBJstream str(searchableSurface::time().path()/"after_all.obj");
Info<< "Writing all bounding boxes to " << str.name() << endl; Info<< "Writing all bounding boxes to " << str.name() << endl;
for (auto myBbs : procBb_) for (const auto& myBbs : procBb_)
{ {
forAll(myBbs, i) for (const treeBoundBox& bb : myBbs)
{ {
pointField pts(myBbs[i].points()); pointField pts(bb.points());
const edgeList& es = treeBoundBox::edges; for (const edge& e : treeBoundBox::edges)
forAll(es, ei)
{ {
const edge& e = es[ei];
str.write(linePointRef(pts[e[0]], pts[e[1]])); str.write(linePointRef(pts[e[0]], pts[e[1]]));
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -48,35 +48,30 @@ Foam::label Foam::meshToMesh::calcDistribution
if (Pstream::parRun()) if (Pstream::parRun())
{ {
List<label> cellsPresentOnProc(Pstream::nProcs(), Zero); const bitSet hasMesh
if ((src.nCells() > 0) || (tgt.nCells() > 0)) (
UPstream::listGatherValues<bool>
(
src.nCells() > 0 || tgt.nCells() > 0
)
);
const auto nHaveMesh = hasMesh.count();
if (nHaveMesh == 1)
{ {
cellsPresentOnProc[Pstream::myProcNo()] = 1; proci = hasMesh.find_first();
}
else
{
cellsPresentOnProc[Pstream::myProcNo()] = 0;
}
Pstream::gatherList(cellsPresentOnProc);
Pstream::scatterList(cellsPresentOnProc);
label nHaveCells = sum(cellsPresentOnProc);
if (nHaveCells > 1)
{
proci = -1;
DebugInFunction
<< "Meshes split across multiple processors" << endl;
}
else if (nHaveCells == 1)
{
proci = cellsPresentOnProc.find(1);
DebugInFunction DebugInFunction
<< "Meshes local to processor" << proci << endl; << "Meshes local to processor" << proci << endl;
} }
else if (nHaveMesh > 1)
{
proci = -1;
DebugInFunction
<< "Meshes split across multiple processors" << endl;
}
Pstream::broadcast(proci);
} }
return proci; return proci;