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:
Mark Olesen
2020-09-28 11:57:40 +02:00
parent e18ff114a6
commit 5dc5ea928a
43 changed files with 140 additions and 398 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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
(

View File

@ -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);

View File

@ -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);

View File

@ -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);