35 #ifndef Foam_PstreamReduceOps_H 36 #define Foam_PstreamReduceOps_H 53 template<
class T,
class BinaryOp>
57 [[maybe_unused]] BinaryOp bop,
82 Perr<<
"** reducing:" << value <<
" comm:" << communicator <<
endl;
95 template<
class T,
class BinaryOp>
100 [[maybe_unused]] BinaryOp bop,
101 [[maybe_unused]]
const int tag,
126 stdFoam::dependent_false_v<T>,
127 "only for specific, contiguous, known data types" 135 template<
class T,
unsigned N,
class BinaryOp>
150 template<
class T,
class BinaryOp>
155 [[maybe_unused]] BinaryOp bop,
156 [[maybe_unused]]
const int tag,
157 const int communicator,
183 stdFoam::dependent_false_v<T>,
184 "only for specific, contiguous, known data types" 192 template<
class T,
class BinaryOp>
198 const int communicator,
203 reduce(&value, 1, tag, communicator, req);
239 template<
class T,
class CountType =
int>
250 static_assert(std::is_arithmetic_v<CountType>,
"Counter not arithmetic");
257 else if constexpr (std::is_floating_point_v<T>)
262 work[1] =
static_cast<T>(
count);
274 count =
static_cast<CountType
>(work[1]);
282 constexpr
auto nCmpts = pTraits_nComponents<T>::value;
288 work[nCmpts] =
static_cast<cmpt
>(
count);
300 count =
static_cast<CountType
>(work[nCmpts]);
316 template<
class T,
class BinaryOp>
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
Combined query of opType and the underlying basic data type.
A 1D vector of objects of type <T> with a fixed length <N>.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Various functors for unary and binary operations. Can be used for parallel combine-reduce operations ...
static void copy_n(Input input, Output result)
Somewhat equivalent to std::copy_n() but with templated loops.
static int & msgType() noexcept
Message tag of standard messages.
static void broadcast(Type &value, const int communicator=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
A supported UPstream (MPI) reduce/window operation type.
void reduce(T &value, [[maybe_unused]] BinaryOp bop, [[maybe_unused]] const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce)
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
An opaque wrapper for MPI_Request with a vendor-independent representation without any <mpi...
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
static bool is_parallel(const label communicator=worldComm)
True if parallel algorithm or exchange is required.
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
static void reduceAnd(bool &value, const int communicator=worldComm)
Logical (and) reduction (MPI_AllReduce)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void sumReduce(T &value, CountType &count, [[maybe_unused]] const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) the sum of value and counter (eg, for averaging) ...
static void printStack(Ostream &os, int size=-1)
Helper function to print a stack, with optional upper limit.
static void gather(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Gather (reduce) data, applying bop to combine value from different processors. The basis for Foam::re...
static void reduceOr(bool &value, const int communicator=worldComm)
Logical (or) reduction (MPI_AllReduce)
static void mpiAllReduce(T values[], int count, const UPstream::opCodes opCodeId, const int communicator)
MPI_Allreduce (blocking) for known operators.