55 const int communicator
67 const int communicator
100void printErrorMessage
108 <<
"Bad input for reduce(): likely a programming problem\n";
112 FatalError<<
" Non-basic data tyoe (" << int(datatype_id) <<
")\n";
117 FatalError<<
" Invalid reduce op (" << int(opcode_id) <<
")\n";
120 if (values ==
nullptr)
140#undef Foam_vendor_supports_INPLACE_REDUCE
148 const int communicator,
166 || (values ==
nullptr)
171 printErrorMessage(values, dataTypeId, opCodeId);
175 const bool withTopo =
184 Perr<<
"[mpi_reduce] : (inplace)"
185 <<
" op:" << int(opCodeId)
186 <<
" type:" << int(dataTypeId) <<
" count:" <<
count
187 <<
" comm:" << communicator
196 #ifndef Foam_vendor_supports_INPLACE_REDUCE
197 static std::unique_ptr<char[]> work;
198 static int work_len(0);
200 const int num_bytes = [=](
int n)
203 MPI_Type_size(datatype, &size);
207 if (work_len < num_bytes)
210 work_len = std::max(256, num_bytes);
212 work = std::make_unique<char[]>(work_len);
214 void* send_buffer = work.get();
216 std::memcpy(send_buffer, values, num_bytes);
218 void* send_buffer =
values;
230 Perr<<
"[mpi_reduce] : (inplace)"
231 <<
" op:" << int(opCodeId)
232 <<
" type:" << int(dataTypeId) <<
" count:" <<
count
233 <<
" comm:" << UPstream::commLocalNode_
244 UPstream::commLocalNode_
252 #ifndef Foam_vendor_supports_INPLACE_REDUCE
253 std::memcpy(send_buffer, values, num_bytes);
258 Perr<<
"[mpi_reduce] : (inplace)"
259 <<
" op:" << int(opCodeId)
260 <<
" type:" << int(dataTypeId) <<
" count:" <<
count
261 <<
" comm:" << UPstream::commInterNode_
272 UPstream::commInterNode_
300 const int communicator,
318 || (values ==
nullptr)
323 printErrorMessage(values, dataTypeId, opCodeId);
327 const bool withTopo =
336 Perr<<
"[mpi_allreduce] :"
337 <<
" op:" << int(opCodeId)
338 <<
" type:" << int(dataTypeId) <<
" count:" <<
count
339 <<
" comm:" << communicator
352 Perr<<
"[mpi_allreduce] :"
353 <<
" op:" << int(opCodeId)
354 <<
" type:" << int(dataTypeId) <<
" count:" <<
count
355 <<
" comm:" << UPstream::commLocalNode_
365 UPstream::commLocalNode_
374 Perr<<
"[mpi_allreduce] :"
375 <<
" op:" << int(opCodeId)
376 <<
" type:" << int(dataTypeId) <<
" count:" <<
count
377 <<
" comm:" << UPstream::commInterNode_
387 UPstream::commInterNode_
396 Perr<<
"[mpi_allreduce] :"
397 <<
" op:" << int(opCodeId)
398 <<
" type:" << int(dataTypeId) <<
" count:" <<
count
399 <<
" comm:" << UPstream::commLocalNode_
408 UPstream::commLocalNode_
438 const int communicator,
456 || (values ==
nullptr)
461 printErrorMessage(values, dataTypeId, opCodeId);
467 Perr<<
"[mpi_scan_reduce] : (inplace)"
468 <<
" op:" << int(opCodeId)
469 <<
" type:" << int(dataTypeId) <<
" count:" <<
count
470 <<
" comm:" << communicator
479 static std::unique_ptr<char[]> work;
480 static int work_len(0);
482 const int num_bytes = [=](
int n)
485 MPI_Type_size(datatype, &size);
489 if (work_len < num_bytes)
492 work_len = std::max(256, num_bytes);
494 work = std::make_unique<char[]>(work_len);
496 void* send_buffer = work.get();
498 std::memcpy(send_buffer, values, num_bytes);
519 std::memcpy(values, send_buffer, num_bytes);
Inter-processor communication reduction functions.
Functions to wrap MPI_Bcast, MPI_Allreduce, MPI_Iallreduce etc.
An opaque wrapper for MPI_Request with a vendor-independent representation without any <mpi....
Wrapper for internally indexed communicator label. Always invokes UPstream::allocateCommunicatorCompo...
static void mpi_reduce(void *values, int count, const UPstream::dataTypes dataTypeId, const UPstream::opCodes opCodeId, const int communicator, UPstream::Request *req=nullptr)
In-place reduction of values with result on rank 0.
opCodes
Mapping of some MPI op codes.
@ Basic_end
(internal use) end marker [reduce types]
@ Basic_begin
(internal use) begin marker [reduce/window types]
static void reduceAnd(bool &value, const int communicator=worldComm)
Logical (and) reduction (MPI_AllReduce).
static bool usingTopoControl(UPstream::topoControls ctrl) noexcept
Test for selection of given topology-aware routine.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static void reduceOr(bool &value, const int communicator=worldComm)
Logical (or) reduction (MPI_AllReduce).
static bool is_parallel(const label communicator=worldComm)
True if parallel algorithm or exchange is required.
static bool usingNodeComms(const int communicator)
True if node topology-aware routines have been enabled, it is running in parallel,...
static void mpi_allreduce(void *values, int count, const UPstream::dataTypes dataTypeId, const UPstream::opCodes opCodeId, const int communicator, UPstream::Request *req=nullptr)
In-place reduction of values with same result on all ranks.
static void mpi_scan_reduce(void *values, int count, const UPstream::dataTypes dataTypeId, const UPstream::opCodes opCodeId, const int communicator, const bool exclusive)
In-place scan/exscan reduction of values.
@ reduce
reduce/all-reduce [MPI]
dataTypes
Mapping of some fundamental and aggregate types to MPI data types.
@ Basic_end
(internal use) end marker [basic types]
@ Basic_begin
(internal use) begin marker [basic/all types]
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static bool is_reduce_opCode(Foam::UPstream::opCodes id) noexcept
static bool is_basic_dataType(Foam::UPstream::dataTypes id) noexcept
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
void reduce(const Type *sendData, Type *values, int count, MPI_Datatype datatype, MPI_Op optype, const int communicator, UPstream::Request *req=nullptr)
void allReduce(Type *values, int count, MPI_Datatype datatype, MPI_Op optype, const int communicator, UPstream::Request *req=nullptr)
void scanReduce(const Type *sendData, Type *recvData, int count, MPI_Datatype datatype, MPI_Op optype, const int communicator, const int exclusive)
bool broadcast(Type *values, int count, MPI_Datatype datatype, const int communicator, const int root=0)
MPI_Datatype getDataType(UPstream::dataTypes id)
Lookup of dataTypes enumeration as an MPI_Datatype.
MPI_Op getOpCode(UPstream::opCodes id)
Lookup of opCodes enumeration as an MPI_Op.
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
errorManip< error > abort(error &err)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FOAM_UNLIKELY(cond)