From cbace6989663a74e18f70d26d09a8b9e4c133479 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 23 Aug 2022 15:58:32 +0200 Subject: [PATCH] ENH: more consistent naming of MPI reductions - combineReduce (older: combineAllGather) - listCombineReduce (older: listCombineAllGather) - mapCombineReduce (older: mapCombineAllGather) --- src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H | 71 +++++++++++-------- .../IOstreams/Pstreams/PstreamCombineGather.C | 46 +++--------- .../Pstreams/PstreamCombineReduceOps.H | 45 ++---------- .../db/IOstreams/Pstreams/PstreamGatherList.C | 18 +---- .../db/IOstreams/Pstreams/PstreamReduceOps.H | 3 +- 5 files changed, 63 insertions(+), 120 deletions(-) diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H index b0ab673da5..0af7d9fa6a 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H @@ -202,13 +202,14 @@ public: 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. //- After completion all processors have the same data. // Uses the specified communication schedule. // Wraps combineGather/broadcast (may change in the future). template - static void combineAllGather + static void combineReduce ( const List& comms, T& value, @@ -217,19 +218,33 @@ public: 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. //- After completion all processors have the same data. // Uses linear/tree communication. // Wraps combineGather/broadcast (may change in the future). template + static void combineReduce + ( + T& value, + const CombineOp& cop, + const int tag = UPstream::msgType(), + const label comm = UPstream::worldComm + ); + + //- Same as Pstream::combineReduce + template static void combineAllGather ( T& value, const CombineOp& cop, const int tag = UPstream::msgType(), const label comm = UPstream::worldComm - ); + ) + { + Pstream::combineReduce(value, cop, tag, comm); + } // Combine variants working on whole List at a time. @@ -256,16 +271,15 @@ public: //- After completion all processors have the same data. template - static void listCombineAllGather + static void listCombineReduce ( - const List& comms, List& values, const CombineOp& cop, - const int tag, - const label comm + const int tag = UPstream::msgType(), + const label comm = UPstream::worldComm ); - //- After completion all processors have the same data. + //- Same as Pstream::listCombineReduce template static void listCombineAllGather ( @@ -273,7 +287,10 @@ public: const CombineOp& cop, const int tag = UPstream::msgType(), const label comm = UPstream::worldComm - ); + ) + { + Pstream::listCombineReduce(values, cop, tag, comm); + } // Combine variants working on whole map at a time. @@ -299,19 +316,23 @@ public: 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. template - static void mapCombineAllGather + static void mapCombineReduce ( - const List& comms, Container& values, const CombineOp& cop, - const int tag, - const label comm + const int tag = UPstream::msgType(), + const label comm = UPstream::worldComm ); - //- After completion all processors have the same data. + //- Same as Pstream::mapCombineReduce template static void mapCombineAllGather ( @@ -319,7 +340,10 @@ public: const CombineOp& cop, const int tag = UPstream::msgType(), const label comm = UPstream::worldComm - ); + ) + { + Pstream::mapCombineReduce(values, cop, tag, comm); + } // Gather/scatter keeping the individual processor data separate. @@ -347,19 +371,6 @@ public: 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 - static void allGatherList - ( - const List& comms, - List& values, - const int tag, - const label comm - ); - //- Gather data, but keep individual values separate. //- Uses linear/tree communication. // After completion all processors have the same data. diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineGather.C b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineGather.C index 946838de21..8449a67f2b 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineGather.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineGather.C @@ -255,13 +255,19 @@ void Foam::Pstream::combineScatter #ifndef Foam_Pstream_scatter_nobroadcast Pstream::broadcast(value, comm); #else - combineScatter(UPstream::whichCommunication(comm), value, tag, comm); + Pstream::combineScatter + ( + UPstream::whichCommunication(comm), + value, + tag, + comm + ); #endif } template -void Foam::Pstream::combineAllGather +void Foam::Pstream::combineReduce ( const List& comms, T& value, @@ -276,7 +282,7 @@ void Foam::Pstream::combineAllGather template -void Foam::Pstream::combineAllGather +void Foam::Pstream::combineReduce ( T& value, const CombineOp& cop, @@ -526,22 +532,7 @@ void Foam::Pstream::listCombineScatter template -void Foam::Pstream::listCombineAllGather -( - const List& comms, - List& values, - const CombineOp& cop, - const int tag, - const label comm -) -{ - Pstream::listCombineGather(comms, values, cop, tag, comm); - Pstream::broadcast(values, comm); -} - - -template -void Foam::Pstream::listCombineAllGather +void Foam::Pstream::listCombineReduce ( List& values, const CombineOp& cop, @@ -747,22 +738,7 @@ void Foam::Pstream::mapCombineScatter template -void Foam::Pstream::mapCombineAllGather -( - const List& comms, - Container& values, - const CombineOp& cop, - const int tag, - const label comm -) -{ - Pstream::mapCombineGather(comms, values, cop, tag, comm); - Pstream::broadcast(values, comm); -} - - -template -void Foam::Pstream::mapCombineAllGather +void Foam::Pstream::mapCombineReduce ( Container& values, const CombineOp& cop, diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H index 209f28eeef..5c8f52d6ac 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H @@ -9,34 +9,16 @@ Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License - This file is part of OpenFOAM. - - 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 . - -InClass - Foam + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description - Combination-Reduction operation for a parallel run. The - information from all nodes is collected on the master node, - combined using the given combination function and the result is - broadcast to all nodes + Compatibility include (AUG-2022). + Foam::combineReduce wrapper for Pstream::combineReduce \*---------------------------------------------------------------------------*/ -#ifndef Foam_PstreamCombineReduceOps_H -#define Foam_PstreamCombineReduceOps_H +#ifndef FoamCompat_PstreamCombineReduceOps_H +#define FoamCompat_PstreamCombineReduceOps_H #include "Pstream.H" #include "ops.H" @@ -48,20 +30,7 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template -void combineReduce -( - const List& comms, - T& value, - const CombineOp& cop, - const int tag, - const label comm -) -{ - Pstream::combineAllGather(comms, value, cop, tag, comm); -} - - +//- Compatibility wrapper for Pstream::combineReduce template void combineReduce ( @@ -71,7 +40,7 @@ void combineReduce const label comm = UPstream::worldComm ) { - Pstream::combineAllGather(value, cop, tag, comm); + Pstream::combineReduce(value, cop, tag, comm); } diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamGatherList.C b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamGatherList.C index cbecc6e6a2..785f6aedf2 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamGatherList.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamGatherList.C @@ -253,7 +253,7 @@ void Foam::Pstream::scatterList { fromAbove >> values[leafID]; - if (debug) + if (debug & 2) { Pout<< " received through " << myComm.above() << " data for:" << leafID @@ -304,7 +304,7 @@ void Foam::Pstream::scatterList { toBelow << values[leafID]; - if (debug) + if (debug & 2) { Pout<< " sent through " << belowID << " data for:" << leafID @@ -341,20 +341,6 @@ void Foam::Pstream::scatterList } -template -void Foam::Pstream::allGatherList -( - const List& comms, - List& values, - const int tag, - const label comm -) -{ - Pstream::gatherList(comms, values, tag, comm); - Pstream::scatterList(comms, values, tag, comm); -} - - template void Foam::Pstream::allGatherList ( diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H index 4438e446eb..4c16912b31 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H @@ -35,8 +35,9 @@ Description #ifndef Foam_PstreamReduceOps_H #define Foam_PstreamReduceOps_H -#include "ops.H" +#include "Pstream.H" #include "FixedList.H" +#include "ops.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //