Commit e18ff114 authored by Mark Olesen's avatar Mark Olesen
Browse files

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) { ... }
parent f8a8728f
......@@ -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];
......
......@@ -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;
......
......@@ -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];
......
......@@ -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)
......
......@@ -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())
......
......@@ -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
......
......@@ -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
......
......@@ -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.
......
......@@ -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())
{
......
......@@ -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
......
......@@ -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
(
......
......@@ -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])
{
......
......@@ -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];
......
......@@ -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];
......
......@@ -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];
......
......@@ -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);
......
......@@ -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];
......
......@@ -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();
......
......@@ -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())
{
......
......@@ -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];
......
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