ENH: provide getter/setter interface to standard communicators

- similar to UPstream::parRun(), the setter returns the previous value.

  The accessors are prefixed with 'comm':
  Eg, commGlobal(), commWarn(), commWorld(), commSelf().
  This distinguishes them from any existing variables (eg, worldComm)
  and arguably more similar to MPI_COMM_WORLD etc...

  If demand-driven communicators are added in the future, the function
  call syntax can help encapsulate that.

  Previously:

      const label oldWarnComm = UPstream::warnComm;
      const label oldWorldComm = UPstream::worldComm;
      UPstream::warnComm = myComm;
      UPstream::worldComm = myComm;
      ...

      UPstream::warnComm = oldWarnComm;
      UPstream::worldComm = oldWorldComm;

  Now:
      const label oldWarnComm = UPstream::commWarn(myComm);
      const label oldWorldComm = UPstream::commWorld(myComm);
      ...

      UPstream::commWarn(oldWarnComm);
      UPstream::commWorld(oldWorldComm);

STYLE: check (warnComm >= 0) instead of (warnComm != -1)
This commit is contained in:
Mark Olesen
2023-03-09 12:57:41 +00:00
parent 06df44a588
commit 20566a87f5
15 changed files with 155 additions and 128 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd. Copyright (C) 2022-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -51,7 +51,7 @@ void printInfo(const label comm)
<< " sub:" << UPstream::subProcs(comm) << nl; << " sub:" << UPstream::subProcs(comm) << nl;
if (UPstream::selfComm == comm) if (UPstream::commSelf() == comm)
{ {
Pout<< "self all:" << UPstream::allProcs(comm) Pout<< "self all:" << UPstream::allProcs(comm)
<< " sub:" << UPstream::subProcs(comm) << nl; << " sub:" << UPstream::subProcs(comm) << nl;
@ -86,32 +86,32 @@ int main(int argc, char *argv[])
<< "nProcs = " << UPstream::nProcs() << "nProcs = " << UPstream::nProcs()
<< " with " << UPstream::nComms() << " predefined comm(s)" << nl; << " with " << UPstream::nComms() << " predefined comm(s)" << nl;
Info<< "worldComm : "; Info<< "comm-world : ";
printInfo(UPstream::worldComm); printInfo(UPstream::commWorld());
Info<< "selfComm : "; Info<< "comm-self : ";
printInfo(UPstream::selfComm); printInfo(UPstream::commSelf());
Info<< nl; Info<< nl;
// Reductions (using MPI intrinsics) // Reductions (using MPI intrinsics)
{ {
label val = Pstream::myProcNo(UPstream::worldComm); label val = Pstream::myProcNo(UPstream::commWorld());
label worldVal = returnReduce label worldVal = returnReduce
( (
val, val,
sumOp<label>(), sumOp<label>(),
Pstream::msgType(), UPstream::msgType(),
UPstream::worldComm UPstream::commWorld()
); );
label selfVal = returnReduce label selfVal = returnReduce
( (
val, val,
sumOp<label>(), sumOp<label>(),
Pstream::msgType(), UPstream::msgType(),
UPstream::selfComm UPstream::commSelf()
); );
Pout<< "value " << val Pout<< "value " << val
@ -123,8 +123,8 @@ int main(int argc, char *argv[])
{ {
Pair<label> val Pair<label> val
( (
Pstream::myProcNo(UPstream::worldComm), Pstream::myProcNo(UPstream::commWorld()),
Pstream::myProcNo(UPstream::worldComm) Pstream::myProcNo(UPstream::commWorld())
); );
Pair<label> worldVal = val; Pair<label> worldVal = val;
@ -133,8 +133,8 @@ int main(int argc, char *argv[])
( (
worldVal, worldVal,
minFirstEqOp<label>(), minFirstEqOp<label>(),
Pstream::msgType(), UPstream::msgType(),
UPstream::worldComm UPstream::commWorld()
); );
Pair<label> selfVal = val; Pair<label> selfVal = val;
@ -143,8 +143,8 @@ int main(int argc, char *argv[])
( (
worldVal, worldVal,
minFirstEqOp<label>(), minFirstEqOp<label>(),
Pstream::msgType(), UPstream::msgType(),
UPstream::selfComm UPstream::commSelf()
); );
Pout<< "value " << val Pout<< "value " << val

View File

@ -150,11 +150,7 @@ int main(int argc, char *argv[])
Pout<< "localValue :" << localValue << endl; Pout<< "localValue :" << localValue << endl;
label comm = Pstream::allocateCommunicator label comm = UPstream::allocateCommunicator(UPstream::worldComm, top);
(
UPstream::worldComm,
top
);
Pout<< "allocated comm :" << comm << endl; Pout<< "allocated comm :" << comm << endl;
Pout<< "comm myproc :" << Pstream::myProcNo(comm) Pout<< "comm myproc :" << Pstream::myProcNo(comm)
@ -173,7 +169,7 @@ int main(int argc, char *argv[])
Pout<< "sum :" << sum << endl; Pout<< "sum :" << sum << endl;
} }
Pstream::freeCommunicator(comm); UPstream::freeCommunicator(comm);
Pout<< "End\n" << endl; Pout<< "End\n" << endl;

View File

@ -88,12 +88,12 @@ int main(int argc, char *argv[])
//- Process IDs within a given communicator //- Process IDs within a given communicator
Info<< "procIDs: " Info<< "procIDs: "
<< flatOutput(UPstream::procID(UPstream::worldComm)) << endl; << flatOutput(UPstream::procID(UPstream::commWorld())) << endl;
rankInfo(UPstream::worldComm); rankInfo(UPstream::commWorld());
Pout<< endl; Pout<< endl;
const int myProci = UPstream::myProcNo(UPstream::worldComm); const int myProci = UPstream::myProcNo(UPstream::commWorld());
int localRanki = myProci; int localRanki = myProci;
labelList subRanks; labelList subRanks;
@ -101,9 +101,9 @@ int main(int argc, char *argv[])
#if 1 #if 1
// With first ranks // With first ranks
subRanks = identity(UPstream::nProcs(UPstream::worldComm) / 2); subRanks = identity(UPstream::nProcs(UPstream::commWorld()) / 2);
newComm.reset(UPstream::worldComm, subRanks); newComm.reset(UPstream::commWorld(), subRanks);
localRanki = UPstream::myProcNo(newComm); localRanki = UPstream::myProcNo(newComm);
Pout.prefix() = Pout.prefix() =
@ -120,14 +120,14 @@ int main(int argc, char *argv[])
#if 1 #if 1
// With every other rank // With every other rank
subRanks = identity(UPstream::nProcs(UPstream::worldComm)); subRanks = identity(UPstream::nProcs(UPstream::commWorld()));
for (label& val : subRanks) for (label& val : subRanks)
{ {
if (val % 2) val = -1; if (val % 2) val = -1;
} }
newComm.reset(UPstream::worldComm, subRanks); newComm.reset(UPstream::commWorld(), subRanks);
localRanki = UPstream::myProcNo(newComm); localRanki = UPstream::myProcNo(newComm);
Pout.prefix() = Pout.prefix() =
@ -165,19 +165,19 @@ int main(int argc, char *argv[])
} }
if (Pstream::parRun() && args.found("host-comm")) if (Pstream::parRun() && args.found("host-comm"))
{ {
// Host communicator, based on the current worldComm // Host communicator, based on the current world communicator
// Use hostname // Use hostname
// Lowest rank per hostname is the IO rank // Lowest rank per hostname is the IO rank
label numprocs = UPstream::nProcs(UPstream::globalComm); label numprocs = UPstream::nProcs(UPstream::commGlobal());
stringList hosts(numprocs); stringList hosts(numprocs);
hosts[Pstream::myProcNo(UPstream::globalComm)] = hostName(); hosts[Pstream::myProcNo(UPstream::commGlobal())] = hostName();
labelList hostIDs_; labelList hostIDs_;
// Compact // Compact
if (Pstream::master(UPstream::globalComm)) if (Pstream::master(UPstream::commGlobal()))
{ {
DynamicList<word> hostNames(numprocs); DynamicList<word> hostNames(numprocs);
hostIDs_.resize_nocopy(numprocs); hostIDs_.resize_nocopy(numprocs);
@ -196,10 +196,10 @@ int main(int argc, char *argv[])
} }
} }
Pstream::broadcasts(UPstream::globalComm, hostIDs_); Pstream::broadcasts(UPstream::commGlobal(), hostIDs_);
const label myHostId = const label myHostId =
hostIDs_[Pstream::myProcNo(UPstream::globalComm)]; hostIDs_[Pstream::myProcNo(UPstream::commGlobal())];
DynamicList<label> subRanks; DynamicList<label> subRanks;
forAll(hostIDs_, proci) forAll(hostIDs_, proci)
@ -210,11 +210,11 @@ int main(int argc, char *argv[])
} }
} }
// Allocate new communicator with globalComm as its parent // Allocate new communicator with global communicator as its parent
const label hostComm = const label hostComm =
UPstream::allocateCommunicator UPstream::allocateCommunicator
( (
UPstream::globalComm, // parent UPstream::commGlobal(),
subRanks, subRanks,
true true
); );

View File

@ -58,7 +58,7 @@ void reduce
const label comm const label comm
) )
{ {
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
Pout<< "** reducing:" << value << " with comm:" << comm << endl; Pout<< "** reducing:" << value << " with comm:" << comm << endl;
error::printStack(Pout); error::printStack(Pout);

View File

@ -284,24 +284,52 @@ public:
// Standard Communicators // Standard Communicators
//- Default world communicator (all processors). //- Communicator for all ranks.
//- May differ from globalComm if local worlds are in use //- May differ from globalComm if local worlds are in use
static label worldComm; static label worldComm;
//- Debugging: warn for use of any communicator differing from warnComm //- Debugging: warn for use of any communicator differing from warnComm
static label warnComm; static label warnComm;
//- Communicator for all processors, irrespective of any local worlds //- Communicator for all ranks, irrespective of any local worlds
static constexpr label globalComm = 0; static constexpr label globalComm = 0;
//- A communicator within the current rank only //- A communicator within the current rank only
static constexpr label selfComm = 1; static constexpr label selfComm = 1;
//- Communicator for all ranks, irrespective of any local worlds
static constexpr label commGlobal() noexcept { return 0; }
//- Communicator within the current rank only
static constexpr label commSelf() noexcept { return 1; }
//- Communicator for all ranks (respecting any local worlds)
static label commWorld() noexcept { return worldComm; }
//- Alter value of world communicator
// \returns the previous value
static label commWorld(const label communicator) noexcept
{
label old(worldComm);
worldComm = communicator;
return old;
}
//- Alter communicator debugging setting.
//- Warns for use of any communicator differing from specified.
// \returns the previous warn communicator
static label commWarn(const label communicator) noexcept
{
label old(warnComm);
warnComm = communicator;
return old;
}
//- Number of currently defined communicators //- Number of currently defined communicators
static label nComms() noexcept { return parentComm_.size(); } static label nComms() noexcept { return parentComm_.size(); }
//- True if communicator appears to be user-allocated //- True if communicator appears to be user-allocated
static bool isUserComm(label communicator) noexcept static bool isUserComm(const label communicator) noexcept
{ {
return (communicator > worldComm && communicator > selfComm); return (communicator > worldComm && communicator > selfComm);
} }

View File

@ -143,7 +143,7 @@ Foam::OSstream& Foam::messageStream::stream(OSstream* alternative)
Foam::OSstream& Foam::messageStream::masterStream(const label communicator) Foam::OSstream& Foam::messageStream::masterStream(const label communicator)
{ {
if (UPstream::warnComm != -1 && communicator != UPstream::warnComm) if (UPstream::warnComm >= 0 && communicator != UPstream::warnComm)
{ {
Pout<< "** messageStream with comm:" << communicator << endl; Pout<< "** messageStream with comm:" << communicator << endl;
error::printStack(Pout); error::printStack(Pout);

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-2022 OpenCFD Ltd. Copyright (C) 2015-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -2721,8 +2721,7 @@ void Foam::globalMeshData::updateMesh()
identity(UPstream::nProcs(UPstream::worldComm)), identity(UPstream::nProcs(UPstream::worldComm)),
true true
); );
const label oldWarnComm = UPstream::warnComm; const label oldWarnComm = UPstream::commWarn(comm);
UPstream::warnComm = comm;
// Total number of faces. // Total number of faces.
@ -2760,8 +2759,9 @@ void Foam::globalMeshData::updateMesh()
comm comm
); );
// Restore communicator settings
UPstream::freeCommunicator(comm); UPstream::freeCommunicator(comm);
UPstream::warnComm = oldWarnComm; UPstream::commWarn(oldWarnComm);
if (debug) if (debug)
{ {

View File

@ -114,7 +114,7 @@ Foam::label Foam::UIPstream::read
<< " commsType:" << UPstream::commsTypeNames[commsType] << " commsType:" << UPstream::commsTypeNames[commsType]
<< Foam::endl; << Foam::endl;
} }
if (UPstream::warnComm != -1 && communicator != UPstream::warnComm) if (UPstream::warnComm >= 0 && communicator != UPstream::warnComm)
{ {
Pout<< "UIPstream::read : starting read from:" << fromProcNo Pout<< "UIPstream::read : starting read from:" << fromProcNo
<< " tag:" << tag << " comm:" << communicator << " tag:" << tag << " comm:" << communicator

View File

@ -68,7 +68,7 @@ bool Foam::UOPstream::write
<< " commType:" << UPstream::commsTypeNames[commsType] << " commType:" << UPstream::commsTypeNames[commsType]
<< Foam::endl; << Foam::endl;
} }
if (UPstream::warnComm != -1 && communicator != UPstream::warnComm) if (UPstream::warnComm >= 0 && communicator != UPstream::warnComm)
{ {
Pout<< "UOPstream::write : starting write to:" << toProcNo Pout<< "UOPstream::write : starting write to:" << toProcNo
<< " tag:" << tag << " tag:" << tag

View File

@ -54,7 +54,7 @@ bool Foam::UPstream::broadcast
<< " size:" << label(bufSize) << " size:" << label(bufSize)
<< Foam::endl; << Foam::endl;
} }
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
Pout<< "UPstream::broadcast : root:" << rootProcNo Pout<< "UPstream::broadcast : root:" << rootProcNo
<< " comm:" << comm << " comm:" << comm

View File

@ -78,7 +78,7 @@ void Foam::PstreamDetail::reduce0
return; return;
} }
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
Pout<< "** reducing:"; Pout<< "** reducing:";
if (count == 1) if (count == 1)
@ -135,7 +135,7 @@ void Foam::PstreamDetail::allReduce
const bool immediate = (req || requestID); const bool immediate = (req || requestID);
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
if (immediate) if (immediate)
{ {
@ -246,7 +246,7 @@ void Foam::PstreamDetail::allToAll
const label numProc = UPstream::nProcs(comm); const label numProc = UPstream::nProcs(comm);
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
if (immediate) if (immediate)
{ {
@ -383,7 +383,7 @@ void Foam::PstreamDetail::allToAllv
const label np = UPstream::nProcs(comm); const label np = UPstream::nProcs(comm);
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
if (immediate) if (immediate)
{ {
@ -531,7 +531,7 @@ void Foam::PstreamDetail::allToAllConsensus
const label myProci = UPstream::myProcNo(comm); const label myProci = UPstream::myProcNo(comm);
const label numProc = UPstream::nProcs(comm); const label numProc = UPstream::nProcs(comm);
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
Pout<< "** non-blocking consensus Alltoall (list):"; Pout<< "** non-blocking consensus Alltoall (list):";
Pout<< " numProc:" << numProc Pout<< " numProc:" << numProc
@ -717,7 +717,7 @@ void Foam::PstreamDetail::allToAllConsensus
const label myProci = UPstream::myProcNo(comm); const label myProci = UPstream::myProcNo(comm);
const label numProc = UPstream::nProcs(comm); const label numProc = UPstream::nProcs(comm);
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
Pout<< "** non-blocking consensus Alltoall (map):"; Pout<< "** non-blocking consensus Alltoall (map):";
Pout<< " numProc:" << numProc Pout<< " numProc:" << numProc
@ -911,7 +911,7 @@ void Foam::PstreamDetail::gather
const label np = UPstream::nProcs(comm); const label np = UPstream::nProcs(comm);
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
if (immediate) if (immediate)
{ {
@ -1037,7 +1037,7 @@ void Foam::PstreamDetail::scatter
const label np = UPstream::nProcs(comm); const label np = UPstream::nProcs(comm);
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
if (immediate) if (immediate)
{ {
@ -1165,7 +1165,7 @@ void Foam::PstreamDetail::gatherv
const label np = UPstream::nProcs(comm); const label np = UPstream::nProcs(comm);
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
if (immediate) if (immediate)
{ {
@ -1317,7 +1317,7 @@ void Foam::PstreamDetail::scatterv
const label np = UPstream::nProcs(comm); const label np = UPstream::nProcs(comm);
if (UPstream::warnComm != -1 && comm != UPstream::warnComm) if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
{ {
if (immediate) if (immediate)
{ {

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020-2022 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -80,8 +80,7 @@ void Foam::functionObjects::syncObjects::sync()
return; return;
} }
const label oldWarnComm = UPstream::warnComm; const label oldWarnComm = UPstream::commWarn(UPstream::commGlobal());
UPstream::warnComm = 0;
// Send my data to all other processors // Send my data to all other processors
@ -90,7 +89,7 @@ void Foam::functionObjects::syncObjects::sync()
// Note provision of explicit all-world communicator // Note provision of explicit all-world communicator
PstreamBuffers pBufs PstreamBuffers pBufs
( (
UPstream::globalComm, UPstream::commGlobal(),
UPstream::commsTypes::nonBlocking UPstream::commsTypes::nonBlocking
); );
@ -164,7 +163,8 @@ void Foam::functionObjects::syncObjects::sync()
// Pout<< type() << " : after synchronisation:" << allDict << endl; // Pout<< type() << " : after synchronisation:" << allDict << endl;
//} //}
UPstream::warnComm = oldWarnComm; // Restore communicator settings
UPstream::commWarn(oldWarnComm);
} }

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-2022 OpenCFD Ltd. Copyright (C) 2015-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -133,7 +133,7 @@ Foam::label Foam::mappedPatchBase::getWorldCommunicator() const
{ {
if (sameWorld()) if (sameWorld())
{ {
return UPstream::worldComm; return UPstream::commWorld();
} }
const Time& runTime = patch_.boundaryMesh().mesh().time(); const Time& runTime = patch_.boundaryMesh().mesh().time();
@ -187,8 +187,7 @@ void Foam::mappedPatchBase::collectSamples
const label myRank = Pstream::myProcNo(myComm); const label myRank = Pstream::myProcNo(myComm);
const label nProcs = Pstream::nProcs(myComm); const label nProcs = Pstream::nProcs(myComm);
const label oldWarnComm(Pstream::warnComm); const label oldWarnComm = UPstream::commWarn(myComm);
Pstream::warnComm = myComm;
if (debug & 2) if (debug & 2)
{ {
@ -265,7 +264,8 @@ void Foam::mappedPatchBase::collectSamples
} }
} }
Pstream::warnComm = oldWarnComm; // Restore communicator settings
UPstream::commWarn(oldWarnComm);
} }
@ -591,8 +591,7 @@ void Foam::mappedPatchBase::findSamples
const label myRank = Pstream::myProcNo(myComm); const label myRank = Pstream::myProcNo(myComm);
const label nProcs = Pstream::nProcs(myComm); const label nProcs = Pstream::nProcs(myComm);
const label oldWarnComm(Pstream::warnComm); const label oldWarnComm = UPstream::commWarn(myComm);
Pstream::warnComm = myComm;
wordList samplePatches(nProcs); wordList samplePatches(nProcs);
{ {
@ -711,7 +710,8 @@ void Foam::mappedPatchBase::findSamples
} }
} }
Pstream::warnComm = oldWarnComm; // Return communicator settings
UPstream::commWarn(oldWarnComm);
} }
@ -1105,9 +1105,6 @@ void Foam::mappedPatchBase::calcAMI() const
// Pre-calculate surface (if any) // Pre-calculate surface (if any)
const auto& surf = surfPtr(); const auto& surf = surfPtr();
const label oldWorldComm(Pstream::worldComm);
const label oldWarnComm(Pstream::warnComm);
// Check if running locally // Check if running locally
if (sampleWorld_.empty() || sameWorld()) if (sampleWorld_.empty() || sameWorld())
{ {
@ -1143,13 +1140,14 @@ void Foam::mappedPatchBase::calcAMI() const
// weights. // weights.
// Change to use inter-world communicator // Change to use inter-world communicator
Pstream::worldComm = myComm; const label oldWarnComm = UPstream::commWarn(myComm);
Pstream::warnComm = Pstream::worldComm; const label oldWorldComm = UPstream::commWorld(myComm);
AMIPtr_->calculate(patch_, nbrPatch0, surf); AMIPtr_->calculate(patch_, nbrPatch0, surf);
Pstream::warnComm = oldWarnComm; // Restore communicator settings
Pstream::worldComm = oldWorldComm; UPstream::commWarn(oldWarnComm);
UPstream::commWorld(oldWorldComm);
} }
else else
{ {
@ -1162,8 +1160,8 @@ void Foam::mappedPatchBase::calcAMI() const
); );
// Change to use inter-world communicator // Change to use inter-world communicator
Pstream::worldComm = myComm; const label oldWarnComm = UPstream::commWarn(myComm);
Pstream::warnComm = Pstream::worldComm; const label oldWorldComm = UPstream::commWorld(myComm);
if (masterWorld()) if (masterWorld())
{ {
@ -1182,8 +1180,9 @@ void Foam::mappedPatchBase::calcAMI() const
// Now the AMI addressing/weights will be from src side (on masterWorld // Now the AMI addressing/weights will be from src side (on masterWorld
// processors) to tgt side (on other processors) // processors) to tgt side (on other processors)
Pstream::warnComm = oldWarnComm; // Restore communicator settings
Pstream::worldComm = oldWorldComm; UPstream::commWarn(oldWarnComm);
UPstream::commWorld(oldWorldComm);
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,17 +30,14 @@ template<class Type>
void Foam::mappedPatchBase::distribute(List<Type>& lst) const void Foam::mappedPatchBase::distribute(List<Type>& lst) const
{ {
const label myComm = getCommunicator(); // Get or create const label myComm = getCommunicator(); // Get or create
const label oldWarnComm(Pstream::warnComm);
switch (mode_) switch (mode_)
{ {
case NEARESTPATCHFACEAMI: case NEARESTPATCHFACEAMI:
{ {
const label oldWorldComm(Pstream::worldComm);
const auto& interp = AMI(); const auto& interp = AMI();
const label oldWarnComm = UPstream::commWarn(myComm);
Pstream::warnComm = myComm; const label oldWorldComm = UPstream::commWorld(myComm);
Pstream::worldComm = myComm;
if (sameWorld()) if (sameWorld())
{ {
@ -87,17 +84,20 @@ void Foam::mappedPatchBase::distribute(List<Type>& lst) const
lst = tmasterFld; lst = tmasterFld;
} }
} }
Pstream::worldComm = oldWorldComm;
Pstream::warnComm = oldWarnComm; // Restore communicator settings
UPstream::commWarn(oldWarnComm);
UPstream::commWorld(oldWorldComm);
break; break;
} }
default: default:
{ {
const auto& m = map(); const auto& m = map();
const label oldWarnComm = UPstream::commWarn(m.comm());
Pstream::warnComm = m.comm();
m.distribute(lst); m.distribute(lst);
Pstream::warnComm = oldWarnComm;
UPstream::commWarn(oldWarnComm);
} }
} }
} }
@ -111,19 +111,19 @@ void Foam::mappedPatchBase::distribute
) const ) const
{ {
const label myComm = getCommunicator(); // Get or create const label myComm = getCommunicator(); // Get or create
const label oldWarnComm(Pstream::warnComm);
switch (mode_) switch (mode_)
{ {
case NEARESTPATCHFACEAMI: case NEARESTPATCHFACEAMI:
{ {
const label oldWorldComm(Pstream::worldComm);
const auto& interp = AMI(); const auto& interp = AMI();
Pstream::warnComm = myComm; const label oldWarnComm = UPstream::commWarn(myComm);
Pstream::worldComm = myComm; const label oldWorldComm = UPstream::commWorld(myComm);
lst = interp.interpolateToSource(Field<Type>(std::move(lst)), cop); lst = interp.interpolateToSource(Field<Type>(std::move(lst)), cop);
Pstream::worldComm = oldWorldComm;
Pstream::warnComm = oldWarnComm; UPstream::commWarn(oldWarnComm);
UPstream::commWorld(oldWorldComm);
break; break;
} }
default: default:
@ -132,7 +132,7 @@ void Foam::mappedPatchBase::distribute
(void)patch_.boundaryMesh().mesh().tetBasePtIs(); (void)patch_.boundaryMesh().mesh().tetBasePtIs();
const auto& m = map(); const auto& m = map();
Pstream::warnComm = myComm; const label oldWarnComm = UPstream::commWarn(myComm);
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::defaultCommsType, Pstream::defaultCommsType,
@ -149,7 +149,7 @@ void Foam::mappedPatchBase::distribute
UPstream::msgType(), UPstream::msgType(),
myComm myComm
); );
Pstream::warnComm = oldWarnComm; UPstream::commWarn(oldWarnComm);
} }
} }
} }
@ -159,19 +159,19 @@ template<class Type>
void Foam::mappedPatchBase::reverseDistribute(List<Type>& lst) const void Foam::mappedPatchBase::reverseDistribute(List<Type>& lst) const
{ {
const label myComm = getCommunicator(); // Get or create const label myComm = getCommunicator(); // Get or create
const label oldWarnComm(Pstream::warnComm);
switch (mode_) switch (mode_)
{ {
case NEARESTPATCHFACEAMI: case NEARESTPATCHFACEAMI:
{ {
const label oldWorldComm(Pstream::worldComm);
const auto& interp = AMI(); const auto& interp = AMI();
Pstream::warnComm = myComm; const label oldWarnComm = UPstream::commWarn(myComm);
Pstream::worldComm = myComm; const label oldWorldComm = UPstream::commWorld(myComm);
lst = interp.interpolateToTarget(Field<Type>(std::move(lst))); lst = interp.interpolateToTarget(Field<Type>(std::move(lst)));
Pstream::worldComm = oldWorldComm;
Pstream::warnComm = oldWarnComm; UPstream::commWarn(oldWarnComm);
UPstream::commWorld(oldWorldComm);
break; break;
} }
default: default:
@ -180,9 +180,9 @@ void Foam::mappedPatchBase::reverseDistribute(List<Type>& lst) const
(void)patch_.boundaryMesh().mesh().tetBasePtIs(); (void)patch_.boundaryMesh().mesh().tetBasePtIs();
const auto& m = map(); const auto& m = map();
Pstream::warnComm = m.comm(); const label oldWarnComm = UPstream::commWarn(m.comm());
m.reverseDistribute(sampleSize(), lst); m.reverseDistribute(sampleSize(), lst);
Pstream::warnComm = oldWarnComm; UPstream::commWarn(oldWarnComm);
break; break;
} }
} }
@ -197,19 +197,19 @@ void Foam::mappedPatchBase::reverseDistribute
) const ) const
{ {
const label myComm = getCommunicator(); // Get or create const label myComm = getCommunicator(); // Get or create
const label oldWarnComm(Pstream::warnComm);
switch (mode_) switch (mode_)
{ {
case NEARESTPATCHFACEAMI: case NEARESTPATCHFACEAMI:
{ {
const label oldWorldComm(Pstream::worldComm);
const auto& interp = AMI(); const auto& interp = AMI();
Pstream::warnComm = myComm; const label oldWarnComm = UPstream::commWarn(myComm);
Pstream::worldComm = myComm; const label oldWorldComm = UPstream::commWorld(myComm);
lst = interp.interpolateToTarget(Field<Type>(std::move(lst)), cop); lst = interp.interpolateToTarget(Field<Type>(std::move(lst)), cop);
Pstream::worldComm = oldWorldComm;
Pstream::warnComm = oldWarnComm; UPstream::commWarn(oldWarnComm);
UPstream::commWorld(oldWorldComm);
break; break;
} }
default: default:
@ -217,7 +217,9 @@ void Foam::mappedPatchBase::reverseDistribute
(void)patch_.boundaryMesh().mesh().tetBasePtIs(); (void)patch_.boundaryMesh().mesh().tetBasePtIs();
const auto& m = map(); const auto& m = map();
const label cSize = sampleSize(); const label cSize = sampleSize();
Pstream::warnComm = myComm;
const label oldWarnComm = UPstream::commWarn(myComm);
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::defaultCommsType, Pstream::defaultCommsType,
@ -234,7 +236,8 @@ void Foam::mappedPatchBase::reverseDistribute
UPstream::msgType(), UPstream::msgType(),
myComm myComm
); );
Pstream::warnComm = oldWarnComm;
UPstream::commWarn(oldWarnComm);
break; break;
} }
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2021-2022 OpenCFD Ltd. Copyright (C) 2021-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -162,7 +162,8 @@ Foam::label Foam::multiWorldConnections::createCommunicator(const edge& worlds)
} }
// Allocate new communicator with global world // Allocate new communicator with global world
comm = UPstream::allocateCommunicator(UPstream::globalComm, subRanks, true); comm =
UPstream::allocateCommunicator(UPstream::commGlobal(), subRanks, true);
if (debug & 2) if (debug & 2)
{ {
@ -234,10 +235,8 @@ void Foam::multiWorldConnections::createComms()
// Use MPI_COMM_WORLD // Use MPI_COMM_WORLD
const label oldWorldComm(UPstream::worldComm); const label oldWarnComm = UPstream::commWarn(UPstream::commGlobal());
const label oldWarnComm(UPstream::warnComm); const label oldWorldComm = UPstream::commWorld(UPstream::commGlobal());
UPstream::worldComm = UPstream::globalComm;
UPstream::warnComm = UPstream::worldComm;
if (Pstream::parRun()) if (Pstream::parRun())
{ {
@ -258,8 +257,9 @@ void Foam::multiWorldConnections::createComms()
if (brokenConnections) if (brokenConnections)
{ {
Pstream::warnComm = oldWarnComm; // Restore communicator settings
Pstream::worldComm = oldWorldComm; UPstream::commWarn(oldWarnComm);
UPstream::commWorld(oldWorldComm);
FatalErrorInFunction FatalErrorInFunction
<< "Has " << brokenConnections << "Has " << brokenConnections
@ -286,8 +286,9 @@ void Foam::multiWorldConnections::createComms()
} }
} }
Pstream::warnComm = oldWarnComm; // Restore communicator settings
Pstream::worldComm = oldWorldComm; UPstream::commWarn(oldWarnComm);
UPstream::commWorld(oldWorldComm);
} }
if (debug) if (debug)