ENH: more consistent naming of MPI reductions

- combineReduce     (older: combineAllGather)
- listCombineReduce (older: listCombineAllGather)
- mapCombineReduce  (older: mapCombineAllGather)
This commit is contained in:
Mark Olesen
2022-08-23 15:58:32 +02:00
parent 39fc7cc957
commit cbace69896
5 changed files with 63 additions and 120 deletions

View File

@ -202,13 +202,14 @@ public:
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
//- Gather data, applying \c cop to inplace combine \c value //- Reduce inplace (cf. MPI Allreduce)
//- applying \c cop to inplace combine \c value
//- from different processors. //- from different processors.
//- After completion all processors have the same data. //- After completion all processors have the same data.
// Uses the specified communication schedule. // Uses the specified communication schedule.
// Wraps combineGather/broadcast (may change in the future). // Wraps combineGather/broadcast (may change in the future).
template<class T, class CombineOp> template<class T, class CombineOp>
static void combineAllGather static void combineReduce
( (
const List<commsStruct>& comms, const List<commsStruct>& comms,
T& value, T& value,
@ -217,19 +218,33 @@ public:
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
//- Gather data, applying \c cop to inplace combine \c value //- Reduce inplace (cf. MPI Allreduce)
//- applying \c cop to inplace combine \c value
//- from different processors. //- from different processors.
//- After completion all processors have the same data. //- After completion all processors have the same data.
// Uses linear/tree communication. // Uses linear/tree communication.
// Wraps combineGather/broadcast (may change in the future). // Wraps combineGather/broadcast (may change in the future).
template<class T, class CombineOp> template<class T, class CombineOp>
static void combineReduce
(
T& value,
const CombineOp& cop,
const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm
);
//- Same as Pstream::combineReduce
template<class T, class CombineOp>
static void combineAllGather static void combineAllGather
( (
T& value, T& value,
const CombineOp& cop, const CombineOp& cop,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); )
{
Pstream::combineReduce(value, cop, tag, comm);
}
// Combine variants working on whole List at a time. // Combine variants working on whole List at a time.
@ -256,16 +271,15 @@ public:
//- After completion all processors have the same data. //- After completion all processors have the same data.
template<class T, class CombineOp> template<class T, class CombineOp>
static void listCombineAllGather static void listCombineReduce
( (
const List<commsStruct>& comms,
List<T>& values, List<T>& values,
const CombineOp& cop, const CombineOp& cop,
const int tag, const int tag = UPstream::msgType(),
const label comm const label comm = UPstream::worldComm
); );
//- After completion all processors have the same data. //- Same as Pstream::listCombineReduce
template<class T, class CombineOp> template<class T, class CombineOp>
static void listCombineAllGather static void listCombineAllGather
( (
@ -273,7 +287,10 @@ public:
const CombineOp& cop, const CombineOp& cop,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); )
{
Pstream::listCombineReduce(values, cop, tag, comm);
}
// Combine variants working on whole map at a time. // Combine variants working on whole map at a time.
@ -299,19 +316,23 @@ public:
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
//- Reduce inplace (cf. MPI Allreduce)
//- applying \c cop to inplace combine map \c values
//- from different processors.
//- After completion all processors have the same data.
// Uses the specified communication schedule.
// Wraps mapCombineGather/broadcast (may change in the future).
//- After completion all processors have the same data. //- After completion all processors have the same data.
template<class Container, class CombineOp> template<class Container, class CombineOp>
static void mapCombineAllGather static void mapCombineReduce
( (
const List<commsStruct>& comms,
Container& values, Container& values,
const CombineOp& cop, const CombineOp& cop,
const int tag, const int tag = UPstream::msgType(),
const label comm const label comm = UPstream::worldComm
); );
//- After completion all processors have the same data. //- Same as Pstream::mapCombineReduce
template<class Container, class CombineOp> template<class Container, class CombineOp>
static void mapCombineAllGather static void mapCombineAllGather
( (
@ -319,7 +340,10 @@ public:
const CombineOp& cop, const CombineOp& cop,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); )
{
Pstream::mapCombineReduce(values, cop, tag, comm);
}
// Gather/scatter keeping the individual processor data separate. // Gather/scatter keeping the individual processor data separate.
@ -347,19 +371,6 @@ public:
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
//- Gather data, but keep individual values separate.
//- Uses the specified communication schedule.
// After completion all processors have the same data.
// Wraps gatherList/scatterList (may change in the future).
template<class T>
static void allGatherList
(
const List<commsStruct>& comms,
List<T>& values,
const int tag,
const label comm
);
//- Gather data, but keep individual values separate. //- Gather data, but keep individual values separate.
//- Uses linear/tree communication. //- Uses linear/tree communication.
// After completion all processors have the same data. // After completion all processors have the same data.

View File

@ -255,13 +255,19 @@ void Foam::Pstream::combineScatter
#ifndef Foam_Pstream_scatter_nobroadcast #ifndef Foam_Pstream_scatter_nobroadcast
Pstream::broadcast(value, comm); Pstream::broadcast(value, comm);
#else #else
combineScatter(UPstream::whichCommunication(comm), value, tag, comm); Pstream::combineScatter
(
UPstream::whichCommunication(comm),
value,
tag,
comm
);
#endif #endif
} }
template<class T, class CombineOp> template<class T, class CombineOp>
void Foam::Pstream::combineAllGather void Foam::Pstream::combineReduce
( (
const List<UPstream::commsStruct>& comms, const List<UPstream::commsStruct>& comms,
T& value, T& value,
@ -276,7 +282,7 @@ void Foam::Pstream::combineAllGather
template<class T, class CombineOp> template<class T, class CombineOp>
void Foam::Pstream::combineAllGather void Foam::Pstream::combineReduce
( (
T& value, T& value,
const CombineOp& cop, const CombineOp& cop,
@ -526,22 +532,7 @@ void Foam::Pstream::listCombineScatter
template<class T, class CombineOp> template<class T, class CombineOp>
void Foam::Pstream::listCombineAllGather void Foam::Pstream::listCombineReduce
(
const List<UPstream::commsStruct>& comms,
List<T>& values,
const CombineOp& cop,
const int tag,
const label comm
)
{
Pstream::listCombineGather(comms, values, cop, tag, comm);
Pstream::broadcast(values, comm);
}
template<class T, class CombineOp>
void Foam::Pstream::listCombineAllGather
( (
List<T>& values, List<T>& values,
const CombineOp& cop, const CombineOp& cop,
@ -747,22 +738,7 @@ void Foam::Pstream::mapCombineScatter
template<class Container, class CombineOp> template<class Container, class CombineOp>
void Foam::Pstream::mapCombineAllGather void Foam::Pstream::mapCombineReduce
(
const List<UPstream::commsStruct>& comms,
Container& values,
const CombineOp& cop,
const int tag,
const label comm
)
{
Pstream::mapCombineGather(comms, values, cop, tag, comm);
Pstream::broadcast(values, comm);
}
template<class Container, class CombineOp>
void Foam::Pstream::mapCombineAllGather
( (
Container& values, Container& values,
const CombineOp& cop, const CombineOp& cop,

View File

@ -9,34 +9,16 @@
Copyright (C) 2022 OpenCFD Ltd. Copyright (C) 2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
InClass
Foam
Description Description
Combination-Reduction operation for a parallel run. The Compatibility include (AUG-2022).
information from all nodes is collected on the master node, Foam::combineReduce wrapper for Pstream::combineReduce
combined using the given combination function and the result is
broadcast to all nodes
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef Foam_PstreamCombineReduceOps_H #ifndef FoamCompat_PstreamCombineReduceOps_H
#define Foam_PstreamCombineReduceOps_H #define FoamCompat_PstreamCombineReduceOps_H
#include "Pstream.H" #include "Pstream.H"
#include "ops.H" #include "ops.H"
@ -48,20 +30,7 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class T, class CombineOp> //- Compatibility wrapper for Pstream::combineReduce
void combineReduce
(
const List<UPstream::commsStruct>& comms,
T& value,
const CombineOp& cop,
const int tag,
const label comm
)
{
Pstream::combineAllGather(comms, value, cop, tag, comm);
}
template<class T, class CombineOp> template<class T, class CombineOp>
void combineReduce void combineReduce
( (
@ -71,7 +40,7 @@ void combineReduce
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
) )
{ {
Pstream::combineAllGather(value, cop, tag, comm); Pstream::combineReduce(value, cop, tag, comm);
} }

View File

@ -253,7 +253,7 @@ void Foam::Pstream::scatterList
{ {
fromAbove >> values[leafID]; fromAbove >> values[leafID];
if (debug) if (debug & 2)
{ {
Pout<< " received through " Pout<< " received through "
<< myComm.above() << " data for:" << leafID << myComm.above() << " data for:" << leafID
@ -304,7 +304,7 @@ void Foam::Pstream::scatterList
{ {
toBelow << values[leafID]; toBelow << values[leafID];
if (debug) if (debug & 2)
{ {
Pout<< " sent through " Pout<< " sent through "
<< belowID << " data for:" << leafID << belowID << " data for:" << leafID
@ -341,20 +341,6 @@ void Foam::Pstream::scatterList
} }
template<class T>
void Foam::Pstream::allGatherList
(
const List<UPstream::commsStruct>& comms,
List<T>& values,
const int tag,
const label comm
)
{
Pstream::gatherList(comms, values, tag, comm);
Pstream::scatterList(comms, values, tag, comm);
}
template<class T> template<class T>
void Foam::Pstream::allGatherList void Foam::Pstream::allGatherList
( (

View File

@ -35,8 +35,9 @@ Description
#ifndef Foam_PstreamReduceOps_H #ifndef Foam_PstreamReduceOps_H
#define Foam_PstreamReduceOps_H #define Foam_PstreamReduceOps_H
#include "ops.H" #include "Pstream.H"
#include "FixedList.H" #include "FixedList.H"
#include "ops.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //