29 MPI_Init(&argc, &argv);
51 MPI_Initialized(&mpi_init);
68 using U = std::remove_const_t<T>;
69 if constexpr (std::is_same_v<U, bool>)
73 if constexpr (std::is_same_v<U, char>)
77 if constexpr (std::is_same_v<U, double>)
81 if constexpr (std::is_same_v<U, float>)
85 if constexpr (std::is_same_v<U, int>)
89 if constexpr (std::is_same_v<U, std::size_t>)
91 return MPI_UNSIGNED_LONG;
93 if constexpr (std::is_same_v<U, unsigned int>)
102 std::vector<T> result(mpi.
size);
104 result[mpi.
rank] = value;
106 MPI_Allgather(&result[mpi.
rank], 1,
mpiType<T>(), result.data(), 1,
113static std::vector<T>
allgather(std::vector<T>
const& vector,
Mpi const& mpi)
115 std::size_t
const size = vector.size();
117 std::vector<T> result(mpi.
size * size);
119 std::copy_n(vector.begin(), size, &result[mpi.
rank * size]);
121 MPI_Allgather(&result[mpi.
rank * size], size,
mpiType<T>(), result.data(),
128static T
allreduce(T
const& value, MPI_Op
const& mpi_op,
Mpi const& mpi)
137static std::vector<T>
allreduce(std::vector<T>
const& vector,
138 MPI_Op
const& mpi_op,
Mpi const& mpi)
140 std::size_t
const size = vector.size();
141 std::vector<T> result(vector.size());
143 MPI_Allreduce(vector.data(), result.data(), size,
mpiType<T>(), mpi_op,
150 MPI_Op
const& mpi_op,
153 MPI_Allreduce(MPI_IN_PLACE,
165 std::span<T>
const send_buffer,
166 std::vector<std::remove_const_t<T>>& receive_buffer,
170 int const size =
static_cast<int>(send_buffer.size());
173 std::vector<int>
const sizes =
allgather(size, mpi);
179 receive_buffer.resize(offsets.back());
181 MPI_Allgatherv(send_buffer.data(), size,
mpiType<T>(),
182 receive_buffer.data(), sizes.data(), offsets.data(),
static int reduceMin(int const val)
static void allreduceInplace(std::vector< T > &vector, MPI_Op const &mpi_op, Mpi const &mpi)
static std::vector< int > allgatherv(std::span< T > const send_buffer, std::vector< std::remove_const_t< T > > &receive_buffer, Mpi const &mpi)
static T allreduce(T const &value, MPI_Op const &mpi_op, Mpi const &mpi)
constexpr MPI_Datatype mpiType()
static std::vector< T > allgather(T const &value, Mpi const &mpi)
std::vector< ranges::range_value_t< R > > sizesToOffsets(R const &sizes)
Mpi(MPI_Comm const communicator=MPI_COMM_WORLD)
Setup(int argc, char *argv[])