1#ifndef AMREX_PARALLEL_REDUCE_H_
2#define AMREX_PARALLEL_REDUCE_H_
3#include <AMReX_Config.H>
27 const std::array<MPI_Op, 5> mpi_ops = {{
38 auto mpi_op = mpi_ops[
static_cast<int>(op)];
46 (
void const*)(MPI_IN_PLACE) : (void const*) v;
54 Reduce(op, &v, 1, root, comm);
58 inline void Reduce (
ReduceOp op, Vector<std::reference_wrapper<T> >
const & v,
61 Vector<T> sndrcv(std::begin(v), std::end(v));
62 Reduce(op, sndrcv.data(), v.size(), root, comm);
63 for (
int i = 0; i < v.size(); ++i) {
64 v[i].get() = sndrcv[i];
69 inline void Gather (
const T* v,
int cnt, T* vs,
int root,
MPI_Comm comm)
74 BL_COMM_PROFILE(BLProfiler::Allgather,
sizeof(T), BLProfiler::BeforeCall(),
77 MPI_Allgather(
const_cast<T*
>(v), cnt, mpi_type, vs, cnt, mpi_type, comm);
78 BL_COMM_PROFILE(BLProfiler::Allgather,
sizeof(T), BLProfiler::AfterCall(),
82 MPI_Gather(
const_cast<T*
>(v), cnt, mpi_type, vs, cnt, mpi_type, root, comm);
88 Gather(&v, 1, vs, root, comm);
101namespace ParallelAllGather {
112namespace ParallelGather {
123namespace ParallelAllReduce {
125 template<
typename K,
typename V>
129 MPI_Allreduce(MPI_IN_PLACE, &vi, 1,
138 template<
typename K,
typename V>
142 MPI_Allreduce(MPI_IN_PLACE, vi, cnt,
151 template<
typename K,
typename V>
155 MPI_Allreduce(MPI_IN_PLACE, &vi, 1,
164 template<
typename K,
typename V>
168 MPI_Allreduce(MPI_IN_PLACE, vi, cnt,
217 auto iv =
static_cast<int>(v);
219 v =
static_cast<bool>(iv);
223 auto iv =
static_cast<int>(v);
225 v =
static_cast<bool>(iv);
229namespace ParallelReduce {
231 template<
typename K,
typename V>
236 MPI_Reduce(&tmp, &vi, 1,
246 template<
typename K,
typename V>
250 (
void const*)(MPI_IN_PLACE) : (
void const*)vi;
252 MPI_Reduce(sendbuf, vi, cnt,
262 template<
typename K,
typename V>
267 MPI_Reduce(&tmp, &vi, 1,
277 template<
typename K,
typename V>
281 (
void const*)(MPI_IN_PLACE) : (
void const*)vi;
283 MPI_Reduce(sendbuf, vi, cnt,
333 auto iv =
static_cast<int>(v);
335 v =
static_cast<bool>(iv);
339 auto iv =
static_cast<int>(v);
341 v =
static_cast<bool>(iv);
#define BL_COMM_PROFILE(cft, size, pid, tag)
Definition AMReX_BLProfiler.H:587
int MPI_Comm
Definition AMReX_ccse-mpi.H:47
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:27
void AllGather(const T *v, int cnt, T *vs, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:103
void Or(bool &v, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:216
void And(bool &v, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:222
void Min(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:152
void Sum(T &v, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:204
void Max(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:126
int MyProc() noexcept
return the rank number local to the current Parallel Context
Definition AMReX_ParallelDescriptor.H:125
MPI_Op Mpi_op()
Definition AMReX_ParallelDescriptor.H:1566
void Gather(const T *v, int cnt, T *vs, int root, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:114
void Min(KeyValuePair< K, V > &vi, int root, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:263
void Or(bool &v, int root, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:332
void Max(KeyValuePair< K, V > &vi, int root, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:232
void And(bool &v, int root, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:338
void Sum(T &v, int root, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:320
ReduceOp
Definition AMReX_ParallelReduce.H:16
@ land
Definition AMReX_ParallelReduce.H:21
@ min
Definition AMReX_ParallelReduce.H:18
@ max
Definition AMReX_ParallelReduce.H:17
@ lor
Definition AMReX_ParallelReduce.H:20
@ sum
Definition AMReX_ParallelReduce.H:19
void Reduce(ReduceOp, T *, int, int, MPI_Comm)
Definition AMReX_ParallelReduce.H:92
void Gather(const T *, int, T *, int, MPI_Comm)
Definition AMReX_ParallelReduce.H:96
Definition AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:127
Definition AMReX_FabArrayCommI.H:896
Definition AMReX_Functional.H:41
Definition AMReX_Functional.H:32
Communication datatype (note: this structure also works without MPI)
Definition AMReX_ccse-mpi.H:68
static MPI_Datatype type()
Definition AMReX_ValLocPair.H:10