diff --git a/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C b/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C index b6bf8476a1cdf6158de0ee90a128a7a467cc0e26..5fd9762ef0468fe3dd837ae598f40359d73222da 100644 --- a/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C +++ b/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C @@ -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 diff --git a/applications/utilities/parallelProcessing/redistributePar/loadOrCreateMesh.C b/applications/utilities/parallelProcessing/redistributePar/loadOrCreateMesh.C index f905908adc3acdb5bd27060c29ec44a72ecdad05..dbcec2a27a4327cdb4b7f815d7d856a26bfe85d1 100644 --- a/applications/utilities/parallelProcessing/redistributePar/loadOrCreateMesh.C +++ b/applications/utilities/parallelProcessing/redistributePar/loadOrCreateMesh.C @@ -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 } diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C index 9eaae1eb1a97078e09ef10554db3d88d65b55089..45dd9210c97f0520c0f6bff9da095a2a02915d1d 100644 --- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C +++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C @@ -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; } diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H index 143f9f226f799edbc925144a52067d148ce3a00a..92755ce449a615faa120ad4f914e80cbd787e01e 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H @@ -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>()); } diff --git a/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C b/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C index 7b9824c0b0c97d22caac65e29afe7dfca6433653..9ef2bbdb9fd68dc4a42f4cd54a187ac0dd572aba 100644 --- a/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C +++ b/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C @@ -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)); } diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C index 2bba13bb92a693d69349dd7e9fc47678b3238bf8..51a1dfaf946a2d3e070fadd9793e699ebb367899 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C @@ -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); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H index e8d18edb29d69556cb6537182c5c3ca337b0140b..ede1cf9794d59e94108f77f5c2909f690e03aeae 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H @@ -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() { diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index fcc4c5357610630681093ed674eb7492f39988ce..735a2487c97d223c7d59af2a9738b0ee143a0059 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -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); diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C index ba488be83ea155c6cc0427f47a7200c942c75664..6adb7eada43eb2d710df044bbcc58b831fa0d479 100644 --- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C @@ -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_); diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C index 15fe5ab5d00c4c4e4dce68024fda6a21a8fc6ff5..1fe48b0fc1310e52e7f29c3e2bb022d414deb028 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C @@ -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) diff --git a/src/overset/cellCellStencil/inverseDistance/waveMethod.C b/src/overset/cellCellStencil/inverseDistance/waveMethod.C index d7d0b210aa103f3748ca7572e8578cc0a670ae31..ef54ca9de4fcaef79f20d588a2be95f396cf957a 100644 --- a/src/overset/cellCellStencil/inverseDistance/waveMethod.C +++ b/src/overset/cellCellStencil/inverseDistance/waveMethod.C @@ -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) { diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C index 0aa35c88d9721f54a2b4ef1280f7566736a0fa3f..80aa0bce58485b891cf77c046ff26f8e3f201cb4 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C @@ -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>