From e18ff114a6219c7bc7e1e7bc05495aaba278bca1 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Mon, 28 Sep 2020 11:41:24 +0200 Subject: [PATCH] ENH: add UPstream::allProcs() method - returns a range of `int` values that can be iterated across. For example, for (const int proci : Pstream::allProcs()) { ... } instead of for (label proci = 0; proci < Pstream::nProcs(); ++proci) { ... } --- .../laserDTRM/laserDTRM.C | 2 +- .../Test-parallel-nonBlocking.C | 5 ++- .../DelaunayMesh/DistributedDelaunayMesh.C | 2 +- .../backgroundMeshDecomposition.C | 2 +- .../conformalVoronoiMeshConformToSurface.C | 4 +-- .../foamyHexMeshBackgroundMesh.C | 2 +- .../redistributePar/redistributePar.C | 2 +- .../preProcessing/viewFactorsGen/shootRays.H | 2 +- .../Lists/SortableList/ParSortableList.C | 3 +- .../db/IOstreams/Pstreams/PstreamBuffers.H | 5 ++- src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H | 17 +++++++--- .../masterUncollatedFileOperation.C | 7 +--- .../polyMesh/globalMeshData/globalIndex.C | 4 +-- .../mapDistribute/mapDistributeBase.C | 18 +++++----- .../mapDistributeBaseTemplates.C | 34 +++++++++---------- .../hexRef8/refinementHistory.C | 4 +-- .../turbulentDFSEMInletFvPatchVectorField.C | 4 +-- .../fvMesh/zoneDistribute/zoneDistribute.C | 5 +-- .../fvMesh/zoneDistribute/zoneDistributeI.H | 5 +-- src/functionObjects/field/STDMD/STDMD.C | 4 +-- .../field/externalCoupled/externalCoupled.C | 6 ++-- .../energySpectrum/energySpectrum.C | 4 +-- .../basic/InteractionLists/InteractionLists.C | 6 ++-- .../clouds/Templates/SprayCloud/SprayCloudI.H | 4 +-- .../meshRefinement/meshRefinementRefine.C | 8 ++--- .../advancingFrontAMIParallelOps.C | 6 ++-- .../output/foamVtkInternalMeshWriter.C | 2 +- src/meshTools/output/foamVtkPatchMeshWriter.C | 2 +- src/meshTools/processorLOD/box/box.C | 10 +++--- .../inverseDistanceCellCellStencil.C | 6 ++-- .../trackingInverseDistanceCellCellStencil.C | 6 ++-- .../decompose/ptscotchDecomp/ptscotchDecomp.C | 2 +- .../noiseModels/surfaceNoise/surfaceNoise.C | 2 +- .../meshToMesh/meshToMeshParallelOps.C | 4 +-- .../radiationModels/viewFactor/viewFactor.C | 2 +- 35 files changed, 102 insertions(+), 99 deletions(-) diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C index 41b5a02546d..6296b29bf9e 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C @@ -707,7 +707,7 @@ void Foam::radiation::laserDTRM::calculate() Pstream::gatherList(p0); Pstream::scatterList(p0); - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { const pointField& pos = positions[proci]; const pointField& pfinal = p0[proci]; diff --git a/applications/test/parallel-nonBlocking/Test-parallel-nonBlocking.C b/applications/test/parallel-nonBlocking/Test-parallel-nonBlocking.C index 1d9eeebcca0..7fca05e3c22 100644 --- a/applications/test/parallel-nonBlocking/Test-parallel-nonBlocking.C +++ b/applications/test/parallel-nonBlocking/Test-parallel-nonBlocking.C @@ -50,7 +50,6 @@ using namespace Foam; int main(int argc, char *argv[]) { - #include "setRootCase.H" #include "createTime.H" @@ -154,7 +153,7 @@ int main(int argc, char *argv[]) { PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); - for (label proci = 0; proci < Pstream::nProcs(); proci++) + for (const int proci : Pstream::allProcs()) { UOPstream toProc(proci, pBufs); toProc << Pstream::myProcNo(); @@ -164,7 +163,7 @@ int main(int argc, char *argv[]) pBufs.finishedSends(); // Consume - for (label proci = 0; proci < Pstream::nProcs(); proci++) + for (const int proci : Pstream::allProcs()) { UIPstream fromProc(proci, pBufs); label data; diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C index e02810916d1..56b18a898a2 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C @@ -489,7 +489,7 @@ Foam::label Foam::DistributedDelaunayMesh<Triangulation>::referVertices pointMap.distribute(parallelVertices); - for (label proci = 0; proci < Pstream::nProcs(); proci++) + for (const int proci : Pstream::allProcs()) { const labelList& constructMap = pointMap.constructMap()[proci]; diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C index 1b022e59e46..4b50b014cac 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C @@ -473,7 +473,7 @@ void Foam::backgroundMeshDecomposition::printMeshData // globalIndex globalBoundaryFaces(mesh.nBoundaryFaces()); - for (label proci = 0; proci < Pstream::nProcs(); proci++) + for (const int proci : Pstream::allProcs()) { Info<< "Processor " << proci << " " << "Number of cells = " << globalCells.localSize(proci) diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C index 2ba63abf1ae..4affaa57581 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C @@ -703,7 +703,7 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseSurfaceTrees label nStoppedInsertion = 0; // Do the nearness tests here - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { // Skip own points if (proci >= Pstream::myProcNo()) @@ -795,7 +795,7 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseEdgeTrees label nStoppedInsertion = 0; // Do the nearness tests here - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { // Skip own points if (proci >= Pstream::myProcNo()) diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C index 51a68564c58..111ef191ccf 100644 --- a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C @@ -130,7 +130,7 @@ void printMeshData(const polyMesh& mesh) label totProcPatches = 0; label maxProcFaces = 0; - for (label proci = 0; proci < Pstream::nProcs(); proci++) + for (const int proci : Pstream::allProcs()) { Info<< endl << "Processor " << proci << nl diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C index 96f7bc50df6..fd916b8476f 100644 --- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C +++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C @@ -185,7 +185,7 @@ void printMeshData(const polyMesh& mesh) label totProcPatches = 0; label maxProcFaces = 0; - for (label procI = 0; procI < Pstream::nProcs(); ++procI) + for (const int procI : Pstream::allProcs()) { Info<< nl << "Processor " << procI << nl diff --git a/applications/utilities/preProcessing/viewFactorsGen/shootRays.H b/applications/utilities/preProcessing/viewFactorsGen/shootRays.H index 9a44e73addc..9f751ecd200 100644 --- a/applications/utilities/preProcessing/viewFactorsGen/shootRays.H +++ b/applications/utilities/preProcessing/viewFactorsGen/shootRays.H @@ -7,7 +7,7 @@ const label maxDynListLength viewFactorDict.getOrDefault<label>("maxDynListLength", 100000) ); -for (label proci = 0; proci < Pstream::nProcs(); proci++) +for (const int proci : Pstream::allProcs()) { // Shoot rays from me to proci. Note that even if processor has // 0 faces we still need to call findLine to keep calls synced. diff --git a/src/OpenFOAM/containers/Lists/SortableList/ParSortableList.C b/src/OpenFOAM/containers/Lists/SortableList/ParSortableList.C index d4099adc6bf..5e66e78be7c 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/ParSortableList.C +++ b/src/OpenFOAM/containers/Lists/SortableList/ParSortableList.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -285,7 +286,7 @@ void Foam::ParSortableList<Type>::sort() label combinedI = 0; - for (label proci = 0; proci < Pstream::nProcs(); proci++) + for (const int proci : Pstream::allProcs()) { if (proci == Pstream::myProcNo()) { diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H index 1904922c785..df574758242 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H @@ -39,7 +39,7 @@ Description \code PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { if (proci != Pstream::myProcNo()) { @@ -52,7 +52,7 @@ Description pBufs.finishedSends(); // no-op for blocking - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { if (proci != Pstream::myProcNo()) { @@ -62,7 +62,6 @@ Description } \endcode - SourceFiles PstreamBuffers.C diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H index f963347395d..4628871b309 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H @@ -75,7 +75,7 @@ public: static const Enum<commsTypes> commsTypeNames; - // Public classes + // Public Classes //- Structure for communicating between processors class commsStruct @@ -180,7 +180,7 @@ public: private: - // Private data + // Private Data //- By default this is not a parallel run static bool parRun_; @@ -248,7 +248,7 @@ private: protected: - // Protected data + // Protected Data //- Communications type of this stream commsTypes commsType_; @@ -298,7 +298,7 @@ public: {} - // Member functions + // Member Functions //- Allocate a new communicator static label allocateCommunicator @@ -424,7 +424,7 @@ public: return haveThreads_; } - //- Number of processes in parallel run + //- Number of processes in parallel run, and 1 for serial run static label nProcs(const label communicator = 0) { return procIDs_[communicator].size(); @@ -471,6 +471,13 @@ public: return nProcs(communicator) - 1; } + //- Range of process indices for all processes + static IntRange<int> allProcs(const label communicator = 0) + { + // Proc 0 -> nProcs + return IntRange<int>(static_cast<int>(nProcs(communicator))); + } + //- Communication schedule for linear all-to-master (proc 0) static const List<commsStruct>& linearCommunication ( diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C index 15be6750a49..e1b9401108b 100644 --- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C @@ -598,12 +598,7 @@ Foam::fileOperations::masterUncollatedFileOperation::read } DynamicList<label> validProcs(Pstream::nProcs(comm)); - for - ( - label proci = 0; - proci < Pstream::nProcs(comm); - proci++ - ) + for (const int proci : Pstream::allProcs(comm)) { if (procValid[proci]) { diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.C b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.C index d42491eddf6..93a33346e54 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.C +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -119,7 +119,7 @@ void Foam::globalIndex::reset label offset = 0; offsets_[0] = 0; - for (label proci = 0; proci < Pstream::nProcs(comm); ++proci) + for (const int proci : Pstream::allProcs(comm)) { const label oldOffset = offset; offset += localSizes[proci]; diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C index 1f9cb435857..5b90f95a532 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C @@ -898,7 +898,7 @@ void Foam::mapDistributeBase::compact(const boolList& elemIsUsed, const int tag) List<boolList> recvFields(Pstream::nProcs()); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap_[domain]; @@ -919,7 +919,7 @@ void Foam::mapDistributeBase::compact(const boolList& elemIsUsed, const int tag) List<boolList> sendFields(Pstream::nProcs()); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap_[domain]; @@ -976,7 +976,7 @@ void Foam::mapDistributeBase::compact(const boolList& elemIsUsed, const int tag) // Compact out all submap entries that are referring to unused elements - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap_[domain]; @@ -1005,7 +1005,7 @@ void Foam::mapDistributeBase::compact(const boolList& elemIsUsed, const int tag) label maxConstructIndex = -1; - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap_[domain]; @@ -1065,7 +1065,7 @@ void Foam::mapDistributeBase::compact List<boolList> recvFields(Pstream::nProcs()); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap_[domain]; @@ -1086,7 +1086,7 @@ void Foam::mapDistributeBase::compact List<boolList> sendFields(Pstream::nProcs()); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap_[domain]; @@ -1148,7 +1148,7 @@ void Foam::mapDistributeBase::compact boolList sendElemIsUsed(localSize, false); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap_[domain]; forAll(map, i) @@ -1177,7 +1177,7 @@ void Foam::mapDistributeBase::compact // Compact out all submap entries that are referring to unused elements - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap_[domain]; @@ -1227,7 +1227,7 @@ void Foam::mapDistributeBase::compact } } - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap_[domain]; diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C index be48461a9f0..e9f9ebccd5e 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015-2017 OpenFOAM Foundation - Copyright (C) 2015-2016, 2019 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -168,7 +168,7 @@ void Foam::mapDistributeBase::distribute // received data. // Send sub field to neighbour - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap[domain]; @@ -216,7 +216,7 @@ void Foam::mapDistributeBase::distribute ); // Receive sub field from neighbour - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap[domain]; @@ -398,7 +398,7 @@ void Foam::mapDistributeBase::distribute PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking, tag); // Stream data into buffer - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap[domain]; @@ -461,7 +461,7 @@ void Foam::mapDistributeBase::distribute Pstream::waitRequests(nOutstanding); // Consume - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap[domain]; @@ -490,7 +490,7 @@ void Foam::mapDistributeBase::distribute List<List<T>> sendFields(Pstream::nProcs()); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap[domain]; @@ -524,7 +524,7 @@ void Foam::mapDistributeBase::distribute List<List<T>> recvFields(Pstream::nProcs()); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap[domain]; @@ -592,7 +592,7 @@ void Foam::mapDistributeBase::distribute // Collect neighbour fields - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap[domain]; @@ -671,7 +671,7 @@ void Foam::mapDistributeBase::distribute // received data. // Send sub field to neighbour - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap[domain]; @@ -711,7 +711,7 @@ void Foam::mapDistributeBase::distribute flipAndCombine(map, constructHasFlip, subField, cop, negOp, field); // Receive sub field from neighbour - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap[domain]; @@ -896,7 +896,7 @@ void Foam::mapDistributeBase::distribute PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking, tag); // Stream data into buffer - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap[domain]; @@ -962,7 +962,7 @@ void Foam::mapDistributeBase::distribute Pstream::waitRequests(nOutstanding); // Consume - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap[domain]; @@ -991,7 +991,7 @@ void Foam::mapDistributeBase::distribute List<List<T>> sendFields(Pstream::nProcs()); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap[domain]; @@ -1025,7 +1025,7 @@ void Foam::mapDistributeBase::distribute List<List<T>> recvFields(Pstream::nProcs()); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap[domain]; @@ -1092,7 +1092,7 @@ void Foam::mapDistributeBase::distribute // Collect neighbour fields - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap[domain]; @@ -1129,7 +1129,7 @@ void Foam::mapDistributeBase::send(PstreamBuffers& pBufs, const List<T>& field) const { // Stream data into buffer - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = subMap_[domain]; @@ -1165,7 +1165,7 @@ const // Consume field.setSize(constructSize_); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& map = constructMap_[domain]; diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C index 73c38e38e18..032041ad9ca 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C @@ -1303,7 +1303,7 @@ void Foam::refinementHistory::distribute(const mapDistributePolyMesh& map) // Create subsetted refinement tree consisting of all parents that // move in their whole to other processor. - for (label proci = 0; proci < Pstream::nProcs(); proci++) + for (const int proci : Pstream::allProcs()) { //Pout<< "-- Subetting for processor " << proci << endl; @@ -1412,7 +1412,7 @@ void Foam::refinementHistory::distribute(const mapDistributePolyMesh& map) visibleCells_.setSize(mesh.nCells()); visibleCells_ = -1; - for (label proci = 0; proci < Pstream::nProcs(); proci++) + for (const int proci : Pstream::allProcs()) { IPstream fromNbr(Pstream::commsTypes::blocking, proci); List<splitCell8> newSplitCells(fromNbr); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C index 238b84c5029..4a5a681a7d1 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C @@ -692,7 +692,7 @@ void Foam::turbulentDFSEMInletFvPatchVectorField::calcOverlappingProcEddies PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& sendElems = map.subMap()[domain]; @@ -710,7 +710,7 @@ void Foam::turbulentDFSEMInletFvPatchVectorField::calcOverlappingProcEddies pBufs.finishedSends(); // Consume - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& recvElems = map.constructMap()[domain]; diff --git a/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.C b/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.C index 3194c5ae6d1..3cafff4ff9f 100644 --- a/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.C +++ b/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2020 DLR + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -162,7 +163,7 @@ void Foam::zoneDistribute::setUpCommforZone PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); // Stream data into buffer - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { if (domain != Pstream::myProcNo()) { @@ -176,7 +177,7 @@ void Foam::zoneDistribute::setUpCommforZone // wait until everything is written. pBufs.finishedSends(); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { send_[domain].clear(); diff --git a/src/finiteVolume/fvMesh/zoneDistribute/zoneDistributeI.H b/src/finiteVolume/fvMesh/zoneDistribute/zoneDistributeI.H index 2289be2509f..2c733ec6bb5 100644 --- a/src/finiteVolume/fvMesh/zoneDistribute/zoneDistributeI.H +++ b/src/finiteVolume/fvMesh/zoneDistribute/zoneDistributeI.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2019-2020 DLR + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -184,7 +185,7 @@ Foam::Map<Type> Foam::zoneDistribute::getDatafromOtherProc PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); // Stream data into buffer - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { if (domain != Pstream::myProcNo()) { @@ -200,7 +201,7 @@ Foam::Map<Type> Foam::zoneDistribute::getDatafromOtherProc Map<Type> tmpValue; - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { if (domain != Pstream::myProcNo()) { diff --git a/src/functionObjects/field/STDMD/STDMD.C b/src/functionObjects/field/STDMD/STDMD.C index 65d47e68873..4fc192d670a 100644 --- a/src/functionObjects/field/STDMD/STDMD.C +++ b/src/functionObjects/field/STDMD/STDMD.C @@ -293,9 +293,9 @@ void Foam::functionObjects::STDMD::calcAp() Log<< tab << "# " << name() << ": Populating the global Rx #" << endl; label m = 0; - for (label i = 0; i < Pstream::nProcs(); ++i) + for (const int i : Pstream::allProcs()) { - label mRows = RxList[i].m(); + const label mRows = RxList[i].m(); Rx.subMatrix(m, 0, mRows) = RxList[i]; diff --git a/src/functionObjects/field/externalCoupled/externalCoupled.C b/src/functionObjects/field/externalCoupled/externalCoupled.C index e30488bbea0..927e764d27f 100644 --- a/src/functionObjects/field/externalCoupled/externalCoupled.C +++ b/src/functionObjects/field/externalCoupled/externalCoupled.C @@ -117,7 +117,7 @@ void Foam::functionObjects::externalCoupled::readColumns // Read data from file and send to destination processor - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { // Temporary storage List<scalarField> values(nColumns); @@ -188,7 +188,7 @@ void Foam::functionObjects::externalCoupled::readLines // Read line from file and send to destination processor - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { // Number of rows to read for processor proci const label procNRows = globalFaces.localSize(proci); @@ -314,7 +314,7 @@ void Foam::functionObjects::externalCoupled::writeGeometry allPoints.clear(); allFaces.clear(); - for (label proci=0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { allPoints.append(collectedPoints[proci]); allFaces.append(collectedFaces[proci]); diff --git a/src/functionObjects/randomProcesses/energySpectrum/energySpectrum.C b/src/functionObjects/randomProcesses/energySpectrum/energySpectrum.C index 85032821ece..fb8f794b983 100644 --- a/src/functionObjects/randomProcesses/energySpectrum/energySpectrum.C +++ b/src/functionObjects/randomProcesses/energySpectrum/energySpectrum.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -235,7 +235,7 @@ bool Foam::functionObjects::energySpectrum::write() vectorField Uijk(nGlobalCells); vectorField Cijk(nGlobalCells); - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { UIPstream fromProc(proci, pBufs); vectorField Up; diff --git a/src/lagrangian/basic/InteractionLists/InteractionLists.C b/src/lagrangian/basic/InteractionLists/InteractionLists.C index ffd9f041bc8..4e1535ed095 100644 --- a/src/lagrangian/basic/InteractionLists/InteractionLists.C +++ b/src/lagrangian/basic/InteractionLists/InteractionLists.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1172,7 +1172,7 @@ void Foam::InteractionLists<ParticleType>::sendReferredData prepareParticlesToRefer(cellOccupancy); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& subMap = cellMap().subMap()[domain]; @@ -1211,7 +1211,7 @@ void Foam::InteractionLists<ParticleType>::receiveReferredData referredParticles_.setSize(cellMap().constructSize()); - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& constructMap = cellMap().constructMap()[domain]; diff --git a/src/lagrangian/spray/clouds/Templates/SprayCloud/SprayCloudI.H b/src/lagrangian/spray/clouds/Templates/SprayCloud/SprayCloudI.H index a5fdbf9d8f5..3edd6376c94 100644 --- a/src/lagrangian/spray/clouds/Templates/SprayCloud/SprayCloudI.H +++ b/src/lagrangian/spray/clouds/Templates/SprayCloud/SprayCloudI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -133,7 +133,7 @@ inline Foam::scalar Foam::SprayCloud<CloudType>::penetration // flatten the mass lists List<scalar> allMass(nParcelSum, Zero); SortableList<scalar> allDist(nParcelSum, Zero); - for (label proci = 0; proci < Pstream::nProcs(); proci++) + for (const int proci : Pstream::allProcs()) { SubList<scalar> ( diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementRefine.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementRefine.C index 330cc3426ee..f5d9c5f3955 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementRefine.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementRefine.C @@ -2494,7 +2494,7 @@ Foam::meshRefinement::balanceAndRefine // globalIndex globalCells(mesh_.nCells()); // // Info<< "** Distribution before balancing/refining:" << endl; - // for (label procI = 0; procI < Pstream::nProcs(); procI++) + // for (const int procI : Pstream::allProcs()) // { // Info<< " " << procI << '\t' // << globalCells.localSize(procI) << endl; @@ -2505,7 +2505,7 @@ Foam::meshRefinement::balanceAndRefine // globalIndex globalCells(cellsToRefine.size()); // // Info<< "** Cells to be refined:" << endl; - // for (label procI = 0; procI < Pstream::nProcs(); procI++) + // for (const int procI : Pstream::allProcs()) // { // Info<< " " << procI << '\t' // << globalCells.localSize(procI) << endl; @@ -2567,7 +2567,7 @@ Foam::meshRefinement::balanceAndRefine // globalIndex globalCells(mesh_.nCells()); // // Info<< "** Distribution after balancing:" << endl; - // for (label procI = 0; procI < Pstream::nProcs(); procI++) + // for (const int procI : Pstream::allProcs()) // { // Info<< " " << procI << '\t' // << globalCells.localSize(procI) << endl; @@ -2625,7 +2625,7 @@ Foam::meshRefinement::balanceAndRefine // globalIndex globalCells(mesh_.nCells()); // // Info<< "** After refinement distribution:" << endl; - // for (label procI = 0; procI < Pstream::nProcs(); procI++) + // for (const int procI : Pstream::allProcs()) // { // Info<< " " << procI << '\t' // << globalCells.localSize(procI) << endl; diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/advancingFrontAMI/advancingFrontAMIParallelOps.C b/src/meshTools/AMIInterpolation/AMIInterpolation/advancingFrontAMI/advancingFrontAMIParallelOps.C index e67d9e6e400..4a87d1c050a 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/advancingFrontAMI/advancingFrontAMIParallelOps.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/advancingFrontAMI/advancingFrontAMIParallelOps.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,7 +76,7 @@ void Foam::advancingFrontAMI::distributePatches { PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); - for (label domain = 0; domain < Pstream::nProcs(); ++domain) + for (const int domain : Pstream::allProcs()) { const labelList& sendElems = map.subMap()[domain]; @@ -132,7 +132,7 @@ void Foam::advancingFrontAMI::distributePatches } // Consume - for (label domain = 0; domain < Pstream::nProcs(); ++domain) + for (const int domain : Pstream::allProcs()) { const labelList& recvElems = map.constructMap()[domain]; diff --git a/src/meshTools/output/foamVtkInternalMeshWriter.C b/src/meshTools/output/foamVtkInternalMeshWriter.C index a910aea8a79..d48b5830161 100644 --- a/src/meshTools/output/foamVtkInternalMeshWriter.C +++ b/src/meshTools/output/foamVtkInternalMeshWriter.C @@ -712,7 +712,7 @@ bool Foam::vtk::internalMeshWriter::writeProcIDs() } // Per-processor ids - for (label proci=0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { vtk::write(format(), proci, procMaps.localSize(proci)); } diff --git a/src/meshTools/output/foamVtkPatchMeshWriter.C b/src/meshTools/output/foamVtkPatchMeshWriter.C index f9536d548d9..6896777f7fe 100644 --- a/src/meshTools/output/foamVtkPatchMeshWriter.C +++ b/src/meshTools/output/foamVtkPatchMeshWriter.C @@ -697,7 +697,7 @@ bool Foam::vtk::patchMeshWriter::writeProcIDs() if (Pstream::master()) { // Per-processor ids - for (label proci=0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { vtk::write(format(), proci, procSizes.localSize(proci)); } diff --git a/src/meshTools/processorLOD/box/box.C b/src/meshTools/processorLOD/box/box.C index d7ebd5cc663..4bf8dffc5fd 100644 --- a/src/meshTools/processorLOD/box/box.C +++ b/src/meshTools/processorLOD/box/box.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. @@ -61,7 +61,7 @@ void Foam::processorLODs::box::writeBoxes ); label verti = 0; - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { if (proci == Pstream::myProcNo()) { @@ -111,7 +111,7 @@ void Foam::processorLODs::box::setRefineFlags PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); // Identify src boxes that can be refined and send to all remote procs - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { if (proci != Pstream::myProcNo()) { @@ -124,7 +124,7 @@ void Foam::processorLODs::box::setRefineFlags // Test each remote src bb with local tgt objects to identify which remote // src boxes can/should be refined - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { if (proci == Pstream::myProcNo()) { @@ -345,7 +345,7 @@ bool Foam::processorLODs::box::doRefineBoxes List<DynamicList<label>> newToOld(Pstream::nProcs()); - for (label proci = 0; proci < Pstream::nProcs(); ++proci) + for (const int proci : Pstream::allProcs()) { if (proci == Pstream::myProcNo()) { diff --git a/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C b/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C index 616ecce3203..3f40b845032 100644 --- a/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C +++ b/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C @@ -368,7 +368,7 @@ void Foam::cellCellStencils::inverseDistance::markPatchesAsHoles // 2. Send over srcMesh bits that overlap tgt and do calculation pBufs.clear(); - for (label procI = 0; procI < Pstream::nProcs(); procI++) + for (const int procI : Pstream::allProcs()) { if (procI != Pstream::myProcNo()) { @@ -385,7 +385,7 @@ void Foam::cellCellStencils::inverseDistance::markPatchesAsHoles } } pBufs.finishedSends(); - for (label procI = 0; procI < Pstream::nProcs(); procI++) + for (const int procI : Pstream::allProcs()) { if (procI != Pstream::myProcNo()) { @@ -537,7 +537,7 @@ void Foam::cellCellStencils::inverseDistance::markDonors DynamicList<label> tgtOverlapProcs(Pstream::nProcs()); // (remote) processors where the src overlaps my tgt DynamicList<label> srcOverlapProcs(Pstream::nProcs()); - for (label procI = 0; procI < Pstream::nProcs(); procI++) + for (const int procI : Pstream::allProcs()) { if (procI != Pstream::myProcNo()) { diff --git a/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C b/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C index 7f643ba29e2..b19b1b544f8 100644 --- a/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C +++ b/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C @@ -250,7 +250,7 @@ void Foam::cellCellStencils::trackingInverseDistance::markPatchesAsHoles // 2. Send over srcMesh bits that overlap tgt and do calculation pBufs.clear(); - for (label procI = 0; procI < Pstream::nProcs(); procI++) + for (const int procI : Pstream::allProcs()) { if (procI != Pstream::myProcNo()) { @@ -267,7 +267,7 @@ void Foam::cellCellStencils::trackingInverseDistance::markPatchesAsHoles } } pBufs.finishedSends(); - for (label procI = 0; procI < Pstream::nProcs(); procI++) + for (const int procI : Pstream::allProcs()) { if (procI != Pstream::myProcNo()) { @@ -373,7 +373,7 @@ void Foam::cellCellStencils::trackingInverseDistance::markDonors DynamicList<label> tgtOverlapProcs(Pstream::nProcs()); // (remote) processors where the src overlaps my tgt DynamicList<label> srcOverlapProcs(Pstream::nProcs()); - for (label procI = 0; procI < Pstream::nProcs(); procI++) + for (const int procI : Pstream::allProcs()) { if (procI != Pstream::myProcNo()) { diff --git a/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C b/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C index d51804c3b92..c4810938ca9 100644 --- a/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C +++ b/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C @@ -109,7 +109,7 @@ void Foam::ptscotchDecomp::check(const int retVal, const char* str) // globalIndex globalCells(initxadj.size()-1); // // bool hasZeroDomain = false; -// for (label proci = 0; proci < Pstream::nProcs(); proci++) +// for (const int proci : Pstream::allProcs()) // { // if (globalCells.localSize(proci) == 0) // { diff --git a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C index 66d7b22cf2f..c01eaafb0d6 100644 --- a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C +++ b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C @@ -169,7 +169,7 @@ void surfaceNoise::readSurfaceData p *= rhoRef_; // Send subset of faces to each processor - for (label procI = 0; procI < Pstream::nProcs(); ++procI) + for (const int procI : Pstream::allProcs()) { label face0 = procFaceOffset[procI]; label nLocalFace = diff --git a/src/sampling/meshToMesh/meshToMeshParallelOps.C b/src/sampling/meshToMesh/meshToMeshParallelOps.C index 5b3faec2ca0..0f2a393c50e 100644 --- a/src/sampling/meshToMesh/meshToMeshParallelOps.C +++ b/src/sampling/meshToMesh/meshToMeshParallelOps.C @@ -322,7 +322,7 @@ void Foam::meshToMesh::distributeCells procLocalFaceIDs.setSize(Pstream::nProcs());; - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& sendElems = map.subMap()[domain]; @@ -501,7 +501,7 @@ void Foam::meshToMesh::distributeCells pBufs.finishedSends(); // Consume - for (label domain = 0; domain < Pstream::nProcs(); domain++) + for (const int domain : Pstream::allProcs()) { const labelList& recvElems = map.constructMap()[domain]; diff --git a/src/thermophysicalModels/radiation/radiationModels/viewFactor/viewFactor.C b/src/thermophysicalModels/radiation/radiationModels/viewFactor/viewFactor.C index f48f1081bf4..2288d8457a1 100644 --- a/src/thermophysicalModels/radiation/radiationModels/viewFactor/viewFactor.C +++ b/src/thermophysicalModels/radiation/radiationModels/viewFactor/viewFactor.C @@ -139,7 +139,7 @@ void Foam::radiation::viewFactor::initialise() DebugInFunction << "Insert elements in the matrix..." << endl; - for (label procI = 0; procI < Pstream::nProcs(); procI++) + for (const int procI : Pstream::allProcs()) { insertMatrixElements ( -- GitLab