diff --git a/applications/test/parallel-communicators/Test-parallel-communicators.C b/applications/test/parallel-communicators/Test-parallel-communicators.C index 99a3158d06..6c4662d011 100644 --- a/applications/test/parallel-communicators/Test-parallel-communicators.C +++ b/applications/test/parallel-communicators/Test-parallel-communicators.C @@ -163,16 +163,6 @@ int main(int argc, char *argv[]) if (Pstream::myProcNo(comm) != -1) { - //scalar sum = sumReduce(comm, localValue); - //scalar sum = localValue; - //reduce - //( - // UPstream::treeCommunication(comm), - // sum, - // sumOp(), - // Pstream::msgType(), - // comm - //); scalar sum = returnReduce ( localValue, diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H index 23dd721a11..7ab8c9dbd9 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H @@ -35,8 +35,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef PstreamCombineReduceOps_H -#define PstreamCombineReduceOps_H +#ifndef Foam_PstreamCombineReduceOps_H +#define Foam_PstreamCombineReduceOps_H #include "UPstream.H" #include "Pstream.H" @@ -73,42 +73,11 @@ void combineReduce const label comm = Pstream::worldComm ) { - if (UPstream::nProcs(comm) < UPstream::nProcsSimpleSum) - { - Pstream::combineGather - ( - UPstream::linearCommunication(comm), - Value, - cop, - tag, - comm - ); - Pstream::combineScatter - ( - UPstream::linearCommunication(comm), - Value, - tag, - comm - ); - } - else - { - Pstream::combineGather - ( - UPstream::treeCommunication(comm), - Value, - cop, - tag, - comm - ); - Pstream::combineScatter - ( - UPstream::treeCommunication(comm), - Value, - tag, - comm - ); - } + const List& comms = + UPstream::whichCommunication(comm); + + Pstream::combineGather(comms, Value, cop, tag, comm); + Pstream::combineScatter(comms, Value, tag, comm); } diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H index 2741d562bd..669a37d248 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,11 +32,11 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef PstreamReduceOps_H -#define PstreamReduceOps_H +#ifndef Foam_PstreamReduceOps_H +#define Foam_PstreamReduceOps_H #include "ops.H" -#include "vector2D.H" +#include "FixedList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -45,12 +45,12 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Reduce operation with user specified communication schedule +//- Reduce operation with user specified communication schedule template void reduce ( const List& comms, - T& Value, + T& value, const BinaryOp& bop, const int tag, const label comm @@ -58,96 +58,86 @@ void reduce { if (UPstream::warnComm != -1 && comm != UPstream::warnComm) { - Pout<< "** reducing:" << Value << " with comm:" << comm + Pout<< "** reducing:" << value << " with comm:" << comm << endl; error::printStack(Pout); } - Pstream::gather(comms, Value, bop, tag, comm); - Pstream::scatter(comms, Value, tag, comm); + Pstream::gather(comms, value, bop, tag, comm); + Pstream::scatter(comms, value, tag, comm); } -// Reduce using either linear or tree communication schedule +//- Reduce (inplace) using either linear or tree communication schedule template void reduce ( - T& Value, + T& value, const BinaryOp& bop, - const int tag = Pstream::msgType(), + const int tag = UPstream::msgType(), const label comm = UPstream::worldComm ) { - if (UPstream::nProcs(comm) < UPstream::nProcsSimpleSum) + if (UPstream::parRun()) { - reduce(UPstream::linearCommunication(comm), Value, bop, tag, comm); - } - else - { - reduce(UPstream::treeCommunication(comm), Value, bop, tag, comm); + reduce(UPstream::whichCommunication(comm), value, bop, tag, comm); } } -// Reduce using either linear or tree communication schedule +//- Reduce (copy) and return value template T returnReduce ( - const T& Value, + const T& value, const BinaryOp& bop, - const int tag = Pstream::msgType(), + const int tag = UPstream::msgType(), const label comm = UPstream::worldComm ) { - T WorkValue(Value); - - if (UPstream::nProcs(comm) < UPstream::nProcsSimpleSum) - { - reduce - ( - UPstream::linearCommunication(comm), - WorkValue, - bop, - tag, - comm - ); - } - else - { - reduce - ( - UPstream::treeCommunication(comm), - WorkValue, - bop, - tag, - comm - ); - } - - return WorkValue; + T work(value); + reduce(work, bop, tag, comm); + return work; } -// Reduce with sum of both value and count (for averaging) +//- Reduce with sum of both value and count (for averaging) template void sumReduce ( - T& Value, - label& Count, - const int tag = Pstream::msgType(), + T& value, + label& count, + const int tag = UPstream::msgType(), const label comm = UPstream::worldComm ) { - reduce(Value, sumOp(), tag, comm); - reduce(Count, sumOp