mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add UPstream::subProcs() static method
- returns a range of `int` values that can be iterated across.
For example,
for (const int proci : Pstream::subProcs()) { ... }
instead of
for
(
int proci = Pstream::firstSlave();
proci <= Pstream::lastSlave();
++proci
)
{
...
}
This commit is contained in:
@ -297,12 +297,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (Pstream::master())
|
||||
{
|
||||
for
|
||||
(
|
||||
int proci = Pstream::firstSlave();
|
||||
proci <= Pstream::lastSlave();
|
||||
++proci
|
||||
)
|
||||
for (const int proci : Pstream::subProcs())
|
||||
{
|
||||
IPstream fromSlave(Pstream::commsTypes::blocking, proci);
|
||||
FixedList<label, 2> list3(fromSlave);
|
||||
|
||||
@ -148,12 +148,7 @@ int main(int argc, char *argv[])
|
||||
Pout<< "full: " << flatOutput(idl3.values()) << nl
|
||||
<< "send: " << flatOutput(idl3) << endl;
|
||||
|
||||
for
|
||||
(
|
||||
int proci = Pstream::firstSlave();
|
||||
proci <= Pstream::lastSlave();
|
||||
++proci
|
||||
)
|
||||
for (const int proci : Pstream::subProcs())
|
||||
{
|
||||
OPstream toSlave(Pstream::commsTypes::scheduled, proci);
|
||||
toSlave << idl3;
|
||||
|
||||
@ -57,12 +57,7 @@ scalar sumReduce
|
||||
// Add master value and all slaves
|
||||
sum = localValue;
|
||||
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave(comm);
|
||||
slave++
|
||||
)
|
||||
for (const int slave : UPstream::subProcs(comm))
|
||||
{
|
||||
scalar slaveValue;
|
||||
UIPstream::read
|
||||
@ -80,12 +75,7 @@ scalar sumReduce
|
||||
|
||||
// Send back to slaves
|
||||
|
||||
for
|
||||
(
|
||||
int slave=UPstream::firstSlave();
|
||||
slave<=UPstream::lastSlave(comm);
|
||||
slave++
|
||||
)
|
||||
for (const int slave : UPstream::subProcs(comm))
|
||||
{
|
||||
UOPstream::write
|
||||
(
|
||||
|
||||
@ -87,12 +87,7 @@ int main(int argc, char *argv[])
|
||||
// Collect my own data
|
||||
allData.append(data);
|
||||
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
slave++
|
||||
)
|
||||
for (const int slave : Pstream::subProcs())
|
||||
{
|
||||
Perr << "master receiving from slave " << slave << endl;
|
||||
UIPstream fromSlave(slave, pBufs);
|
||||
@ -105,12 +100,7 @@ int main(int argc, char *argv[])
|
||||
PstreamBuffers pBufs2(Pstream::commsTypes::nonBlocking);
|
||||
if (Pstream::master())
|
||||
{
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
slave++
|
||||
)
|
||||
for (const int slave : Pstream::subProcs())
|
||||
{
|
||||
Perr << "master sending to slave " << slave << endl;
|
||||
UOPstream toSlave(slave, pBufs2);
|
||||
|
||||
@ -154,12 +154,7 @@ void testTransfer(const T& input)
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
for
|
||||
(
|
||||
int slave = Pstream::firstSlave();
|
||||
slave <= Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
for (const int slave : Pstream::subProcs())
|
||||
{
|
||||
Perr<< "master receiving from slave " << slave << endl;
|
||||
IPstream fromSlave(Pstream::commsTypes::blocking, slave);
|
||||
@ -167,12 +162,7 @@ void testTransfer(const T& input)
|
||||
perrInfo(data) << endl;
|
||||
}
|
||||
|
||||
for
|
||||
(
|
||||
int slave = Pstream::firstSlave();
|
||||
slave <= Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
for (const int slave : Pstream::subProcs())
|
||||
{
|
||||
Perr<< "master sending to slave " << slave << endl;
|
||||
OPstream toSlave(Pstream::commsTypes::blocking, slave);
|
||||
@ -207,12 +197,7 @@ void testTokenized(const T& data)
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
for
|
||||
(
|
||||
int slave = Pstream::firstSlave();
|
||||
slave <= Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
for (const int slave : Pstream::subProcs())
|
||||
{
|
||||
Perr<< "master receiving from slave " << slave << endl;
|
||||
IPstream fromSlave(Pstream::commsTypes::blocking, slave);
|
||||
@ -220,12 +205,7 @@ void testTokenized(const T& data)
|
||||
Perr<< tok.info() << endl;
|
||||
}
|
||||
|
||||
for
|
||||
(
|
||||
int slave = Pstream::firstSlave();
|
||||
slave <= Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
for (const int slave : Pstream::subProcs())
|
||||
{
|
||||
Perr<< "master sending to slave " << slave << endl;
|
||||
OPstream toSlave(Pstream::commsTypes::blocking, slave);
|
||||
|
||||
@ -58,24 +58,14 @@ Gather<T0>::Gather(const T0& localData, const bool redistribute)
|
||||
*outIter = localData;
|
||||
|
||||
// Receive data
|
||||
for
|
||||
(
|
||||
int proci = Pstream::firstSlave();
|
||||
proci <= Pstream::lastSlave();
|
||||
++proci
|
||||
)
|
||||
for (const int proci : Pstream::subProcs())
|
||||
{
|
||||
IPstream fromSlave(Pstream::commsTypes::scheduled, proci);
|
||||
fromSlave >> *(++outIter);
|
||||
}
|
||||
|
||||
// Send data
|
||||
for
|
||||
(
|
||||
int proci = Pstream::firstSlave();
|
||||
proci <= Pstream::lastSlave();
|
||||
++proci
|
||||
)
|
||||
for (const int proci : Pstream::subProcs())
|
||||
{
|
||||
OPstream toSlave(Pstream::commsTypes::scheduled, proci);
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -445,7 +445,7 @@ void Foam::mergeAndWrite
|
||||
pOffset += myPoints.size();
|
||||
|
||||
// Receive slave ones
|
||||
for (int slave=1; slave<Pstream::nProcs(); slave++)
|
||||
for (const int slave : Pstream::subProcs())
|
||||
{
|
||||
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -387,12 +387,7 @@ void getInterfaceSizes
|
||||
if (Pstream::master())
|
||||
{
|
||||
// Receive and add to my sizes
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
slave++
|
||||
)
|
||||
for (const int slave : Pstream::subProcs())
|
||||
{
|
||||
IPstream fromSlave(Pstream::commsTypes::blocking, slave);
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2012-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -124,12 +124,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::loadOrCreateMesh
|
||||
);
|
||||
|
||||
// Send patches
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
slave++
|
||||
)
|
||||
for (const int slave : Pstream::subProcs())
|
||||
{
|
||||
OPstream toSlave(Pstream::commsTypes::scheduled, slave);
|
||||
toSlave << patchEntries;
|
||||
|
||||
@ -677,7 +677,7 @@ void readFields
|
||||
tmp<GeoField> tsubfld = subsetterPtr->interpolate(fields[i]);
|
||||
|
||||
// Send to all processors that don't have a mesh
|
||||
for (label procI = 1; procI < Pstream::nProcs(); ++procI)
|
||||
for (const int procI : Pstream::subProcs())
|
||||
{
|
||||
if (!haveMesh[procI])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user