Commit 9c7aa972 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add UPstream::parRun(const bool)

- slightly neater code when disabling/restoring parallel state

  New
      const bool oldParRun = Pstream::parRun(false);
      ...
      Pstream::parRun(oldParRun);

  Old
      const bool oldParRun = Pstream::parRun();
      Pstream::parRun() = false;
      ...
      Pstream::parRun() = oldParRun;
parent ea0de58b
......@@ -575,8 +575,7 @@ labelList regionRenumber
Info<< " region " << regioni << " starts at " << celli << endl;
// Make sure no parallel comms
const bool oldParRun = UPstream::parRun();
UPstream::parRun() = false;
const bool oldParRun = UPstream::parRun(false);
// Per region do a reordering.
fvMeshSubset subsetter(mesh, regioni, cellToRegion);
......@@ -589,8 +588,8 @@ labelList regionRenumber
subMesh.cellCentres()
);
// Restore state
UPstream::parRun() = oldParRun;
UPstream::parRun(oldParRun); // Restore parallel state
const labelList& cellMap = subsetter.cellMap();
......@@ -914,8 +913,7 @@ int main(int argc, char *argv[])
dictionary decomposeDict(renumberDictPtr().subDict("blockCoeffs"));
decomposeDict.set("numberOfSubdomains", nBlocks);
bool oldParRun = UPstream::parRun();
UPstream::parRun() = false;
const bool oldParRun = UPstream::parRun(false);
autoPtr<decompositionMethod> decomposePtr = decompositionMethod::New
(
......@@ -931,8 +929,8 @@ int main(int argc, char *argv[])
)
);
// Restore state
UPstream::parRun() = oldParRun;
UPstream::parRun(oldParRun); // Restore parallel state
// For debugging: write out region
createScalarField
......
......@@ -157,8 +157,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::loadOrCreateMesh
if (!haveMesh)
{
const bool oldParRun = Pstream::parRun();
Pstream::parRun() = false;
const bool oldParRun = Pstream::parRun(false);
// Create dummy mesh. Only used on procs that don't have mesh.
......@@ -241,7 +240,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::loadOrCreateMesh
// << endl;
dummyMesh.write();
Pstream::parRun() = oldParRun;
Pstream::parRun(oldParRun); // Restore parallel state
}
......
......@@ -2425,10 +2425,9 @@ int main(int argc, char *argv[])
instantList timeDirs;
if (Pstream::master())
{
const bool oldParRun = Pstream::parRun();
Pstream::parRun() = false;
const bool oldParRun = Pstream::parRun(false);
timeDirs = Time::findTimes(args.path(), "constant");
Pstream::parRun() = oldParRun;
Pstream::parRun(oldParRun); // Restore parallel state
}
Pstream::scatter(timeDirs);
for (const instant& t : timeDirs)
......@@ -2464,10 +2463,9 @@ int main(int argc, char *argv[])
if (Pstream::master())
{
const bool oldParRun = Pstream::parRun();
Pstream::parRun() = false;
const bool oldParRun = Pstream::parRun(false);
timeDirs = Time::findTimes(basePath, "constant");
Pstream::parRun() = oldParRun;
Pstream::parRun(oldParRun); // Restore parallel state
}
Pstream::scatter(timeDirs);
for (const instant& t : timeDirs)
......@@ -3038,11 +3036,10 @@ int main(int argc, char *argv[])
if (!Pstream::master() && !haveMesh[Pstream::myProcNo()])
{
// Remove dummy mesh created by loadOrCreateMesh
const bool oldParRun = Pstream::parRun();
Pstream::parRun() = false;
const bool oldParRun = Pstream::parRun(false);
mesh.removeFiles();
rmDir(mesh.objectRegistry::objectPath());
Pstream::parRun() = oldParRun;
Pstream::parRun(oldParRun); // Restore parallel state
}
continue;
}
......
......@@ -88,9 +88,9 @@ if (doLagrangian)
// but that combination does not work.
// So check the header and sync globally
fieldExists =
fieldObject.typeHeaderOk<IOField<scalar>>(false);
const bool oldParRun = Pstream::parRun(false);
fieldExists = fieldObject.typeHeaderOk<IOField<scalar>>(false);
Pstream::parRun(oldParRun); // Restore parallel state
reduce(fieldExists, orOp<bool>());
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2018 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -240,10 +240,9 @@ int main(int argc, char *argv[])
if (Pstream::master())
{
// Actually load the surface
const bool oldParRun = Pstream::parRun();
Pstream::parRun() = false;
const bool oldParRun = Pstream::parRun(false);
triSurfaceMesh surf(io);
Pstream::parRun() = oldParRun;
Pstream::parRun(oldParRun); // Restore parallel state
s = surf;
bbs = List<treeBoundBox>(1, treeBoundBox(boundBox::greatBox));
}
......
......@@ -362,6 +362,9 @@ bool Foam::UPstream::parRun_(false);
bool Foam::UPstream::haveThreads_(false);
int Foam::UPstream::msgType_(1);
Foam::LIFOStack<Foam::label> Foam::UPstream::freeComms_;
Foam::DynamicList<int> Foam::UPstream::myProcNo_(10);
......@@ -370,8 +373,6 @@ Foam::DynamicList<Foam::List<int>> Foam::UPstream::procIDs_(10);
Foam::DynamicList<Foam::label> Foam::UPstream::parentCommunicator_(10);
int Foam::UPstream::msgType_(1);
Foam::DynamicList<Foam::List<Foam::UPstream::commsStruct>>
Foam::UPstream::linearCommunication_(10);
......
......@@ -412,6 +412,15 @@ public:
static void freeTag(const word&, const int tag);
//- Set as parallel run on/off.
// \return the previous value
static bool parRun(const bool on)
{
bool old(parRun_);
parRun_ = on;
return old;
}
//- Is this a parallel run?
static bool& parRun()
{
......
......@@ -1249,8 +1249,7 @@ void Foam::argList::parse
// Disable any parallel comms happening inside the fileHandler
// since we are on master. This can happen e.g. inside
// the masterUncollated/collated handler.
const bool oldParRun = Pstream::parRun();
Pstream::parRun() = false;
const bool oldParRun = Pstream::parRun(false);
autoPtr<ISstream> decompDictStream
(
......@@ -1266,9 +1265,7 @@ void Foam::argList::parse
dictionary decompDict(*decompDictStream);
// Restore parallel behaviour
Pstream::parRun() = oldParRun;
Pstream::parRun(oldParRun); // Restore parallel state
decompDict.readEntry("numberOfSubdomains", dictNProcs);
......
......@@ -1686,8 +1686,7 @@ Foam::fileOperations::masterUncollatedFileOperation::readObjects
{
// Avoid fileOperation::readObjects from triggering parallel ops
// (through call to filePath which triggers parallel )
const bool oldParRun = UPstream::parRun();
UPstream::parRun() = false;
const bool oldParRun = UPstream::parRun(false);
//- Use non-time searching version
objectNames = fileOperation::readObjects
......@@ -1731,7 +1730,7 @@ Foam::fileOperations::masterUncollatedFileOperation::readObjects
}
}
UPstream::parRun() = oldParRun;
UPstream::parRun(oldParRun); // Restore parallel state
}
Pstream::scatter(newInstance); //, Pstream::msgType(), comm_);
......@@ -2111,13 +2110,12 @@ bool Foam::fileOperations::masterUncollatedFileOperation::read
if (Pstream::master()) // comm_))
{
// Do master-only reading always.
const bool oldParRun = UPstream::parRun();
UPstream::parRun() = false;
const bool oldParRun = UPstream::parRun(false);
ok = io.readData(io.readStream(typeName));
io.close();
UPstream::parRun() = oldParRun;
UPstream::parRun(oldParRun); // Restore parallel state
}
Pstream::scatter(ok); //, Pstream::msgType(), comm_);
......@@ -2257,10 +2255,11 @@ Foam::instantList Foam::fileOperations::masterUncollatedFileOperation::findTimes
if (Pstream::master()) // comm_))
{
// Do master-only reading always.
const bool oldParRun = UPstream::parRun();
UPstream::parRun() = false;
const bool oldParRun = UPstream::parRun(false);
times = fileOperation::findTimes(directory, constantName);
UPstream::parRun() = oldParRun;
UPstream::parRun(oldParRun); // Restore parallel state
}
Pstream::scatter(times); //, Pstream::msgType(), comm_);
......
......@@ -1951,8 +1951,8 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
// What to send to neighbouring domains
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bool oldParRun = UPstream::parRun();
UPstream::parRun() = false;
// Disable parallel.
const bool oldParRun = UPstream::parRun(false);
forAll(nSendCells, recvProc)
{
......@@ -2162,7 +2162,7 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
}
UPstream::parRun() = oldParRun;
UPstream::parRun(oldParRun); // Restore parallel state
// Start sending&receiving from buffers
......@@ -2279,8 +2279,8 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
// Receive and add what was sent
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oldParRun = UPstream::parRun();
UPstream::parRun() = false;
// Disable parallel. Original state already known.
UPstream::parRun(false);
forAll(nRevcCells, sendProc)
{
......@@ -2697,7 +2697,8 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
}
}
UPstream::parRun() = oldParRun;
UPstream::parRun(oldParRun); // Restore parallel state
// Print a bit.
if (debug)
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -55,8 +55,7 @@ void Foam::waveMethod::calculate
// The actual matching is only w.r.t local cells so cannot be run in
// parallel.
const bool oldParRun = Pstream::parRun();
Pstream::parRun() = false;
const bool oldParRun = Pstream::parRun(false);
label nSeeds = 0;
......@@ -144,7 +143,7 @@ void Foam::waveMethod::calculate
}
}
Pstream::parRun() = oldParRun;
Pstream::parRun(oldParRun); // Restore parallel state
if (debug)
{
......
......@@ -1691,10 +1691,9 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
calcFaceFaces(s, pointFaces, faceFaces);
// Do the actual decomposition
const bool oldParRun = UPstream::parRun();
UPstream::parRun() = false;
const bool oldParRun = UPstream::parRun(false);
distribution = decomposer_().decompose(faceFaces, triCentres);
UPstream::parRun() = oldParRun;
UPstream::parRun(oldParRun); // Restore parallel state
}
else
{
......@@ -2023,10 +2022,9 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
UIndirectList<point>(mergedPoints, allToMerged) = allCentres;
// Decompose merged centres
const bool oldParRun = UPstream::parRun();
UPstream::parRun() = false;
const bool oldParRun = UPstream::parRun(false);
labelList mergedDist(decomposer_().decompose(mergedPoints));
UPstream::parRun() = oldParRun;
UPstream::parRun(oldParRun); // Restore parallel state
// Convert to all
allDistribution = UIndirectList<label>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment