IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
Collectives.hpp
Go to the documentation of this file.
2
4
5namespace ippl {
6 namespace mpi {
7 template <typename T>
8 void Communicator::gather(const T* input, T* output, int count, int root) {
9 MPI_Datatype type = get_mpi_datatype<T>(*input);
10
11 MPI_Gather(const_cast<T*>(input), count, type, output, count, type, root, *comm_m);
12 }
13
14 template <typename T>
15 void Communicator::scatter(const T* input, T* output, int count, int root) {
16 MPI_Datatype type = get_mpi_datatype<T>(*input);
17
18 MPI_Scatter(const_cast<T*>(input), count, type, output, count, type, root, *comm_m);
19 }
20
21 template <typename T, class Op>
22 void Communicator::reduce(const T* input, T* output, int count, Op, int root) {
23 MPI_Datatype type = get_mpi_datatype<T>(*input);
24
25 MPI_Op mpiOp = get_mpi_op<Op, T>();
26
27 MPI_Reduce(const_cast<T*>(input), output, count, type, mpiOp, root, *comm_m);
28 }
29
30 template <typename T, class Op>
31 void Communicator::reduce(const T& input, T& output, int count, Op op, int root) {
32 reduce(&input, &output, count, op, root);
33 }
34
35 template <typename T, class Op>
36 void Communicator::allreduce(const T* input, T* output, int count, Op) {
37 MPI_Datatype type = get_mpi_datatype<T>(*input);
38
39 MPI_Op mpiOp = get_mpi_op<Op, T>();
40
41 MPI_Allreduce(const_cast<T*>(input), output, count, type, mpiOp, *comm_m);
42 }
43
44 template <typename T, class Op>
45 void Communicator::allreduce(const T& input, T& output, int count, Op op) {
46 allreduce(&input, &output, count, op);
47 }
48
49 template <typename T, class Op>
50 void Communicator::allreduce(T* inout, int count, Op) {
51 MPI_Datatype type = get_mpi_datatype<T>(*inout);
52
53 MPI_Op mpiOp = get_mpi_op<Op, T>();
54
55 MPI_Allreduce(MPI_IN_PLACE, inout, count, type, mpiOp, *comm_m);
56 }
57
58 template <typename T, class Op>
59 void Communicator::allreduce(T& inout, int count, Op op) {
60 allreduce(&inout, count, op);
61 }
62 } // namespace mpi
63} // namespace ippl
Definition Archive.h:20
MPI_Op get_mpi_op()
Definition Operations.h:206
MPI_Datatype get_mpi_datatype(const T &)
Definition DataTypes.h:65
void scatter(const T *input, T *output, int count, int root=0)
void reduce(const T *input, T *output, int count, Op op, int root=0)
std::shared_ptr< MPI_Comm > comm_m
void allreduce(const T *input, T *output, int count, Op op)
void gather(const T *input, T *output, int count, int root=0)