Skip to content

Commit fa9a7e1

Browse files
committed
feat(mpi): add MPI reduction op conversion logic
Signed-off-by: Gabriel Dos Santos <[email protected]>
1 parent a0a05aa commit fa9a7e1

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
// SPDX-FileCopyrightText: Copyright Contributors to the Kokkos project
3+
4+
#pragma once
5+
6+
#include <type_traits>
7+
8+
#include <mpi.h>
9+
10+
#include <KokkosComm/concepts.hpp>
11+
#include <KokkosComm/reduction_op.hpp>
12+
13+
namespace KokkosComm::mpi::Impl {
14+
15+
template <ReductionOperator RedOp>
16+
constexpr auto reduction_op() -> MPI_Op {
17+
if constexpr (std::is_same_v<RedOp, Max>) {
18+
return MPI_MAX;
19+
} else if constexpr (std::is_same_v<RedOp, Min>) {
20+
return MPI_MIN;
21+
} else if constexpr (std::is_same_v<RedOp, Sum>) {
22+
return MPI_SUM;
23+
} else if constexpr (std::is_same_v<RedOp, Prod>) {
24+
return MPI_PROD;
25+
} else if constexpr (std::is_same_v<RedOp, LAnd>) {
26+
return MPI_LAND;
27+
} else if constexpr (std::is_same_v<RedOp, BAnd>) {
28+
return MPI_BAND;
29+
} else if constexpr (std::is_same_v<RedOp, LOr>) {
30+
return MPI_LOR;
31+
} else if constexpr (std::is_same_v<RedOp, BOr>) {
32+
return MPI_BOR;
33+
} else if constexpr (std::is_same_v<RedOp, LXor>) {
34+
return MPI_LXOR;
35+
} else if constexpr (std::is_same_v<RedOp, BXor>) {
36+
return MPI_BXOR;
37+
} else if constexpr (std::is_same_v<RedOp, MaxLoc>) {
38+
return MPI_MAXLOC;
39+
} else if constexpr (std::is_same_v<RedOp, MinLoc>) {
40+
return MPI_MINLOC;
41+
} else {
42+
static_assert(std::is_void_v<RedOp>, "mpi::Impl::reduction_op: operator not implemented");
43+
return MPI_SUM; // unreachable
44+
}
45+
}
46+
47+
template <ReductionOperator RedOp>
48+
inline constexpr MPI_Op reduction_op_v = reduction_op<RedOp>();
49+
50+
} // namespace KokkosComm::mpi::Impl

0 commit comments

Comments
 (0)