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

View File

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

View File

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

View File

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

View File

@ -284,24 +284,52 @@ public:
// Standard Communicators
//- Default world communicator (all processors).
//- Communicator for all ranks.
//- May differ from globalComm if local worlds are in use
static label worldComm;
//- Debugging: warn for use of any communicator differing from 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;
//- A communicator within the current rank only
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
static label nComms() noexcept { return parentComm_.size(); }
//- 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);
}

View File

@ -143,7 +143,7 @@ Foam::OSstream& Foam::messageStream::stream(OSstream* alternative)
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;
error::printStack(Pout);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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