19#ifndef UTILS_MPI_CART_COMM_HPP
20#define UTILS_MPI_CART_COMM_HPP
24#include <boost/mpi/communicator.hpp>
25#include <boost/mpi/exception.hpp>
42 BOOST_MPI_CHECK_RESULT(MPI_Dims_create,
43 (nodes,
static_cast<int>(dim), dims.data()))
53template <std::
size_t dim>
59 BOOST_MPI_CHECK_RESULT(MPI_Cart_create,
60 (comm, dim, dims.
data(), periodicity.data(),
61 static_cast<int>(reorder), &temp_comm))
63 return {temp_comm, boost::mpi::comm_take_ownership};
71template <std::
size_t dims>
74 BOOST_MPI_CHECK_RESULT(MPI_Cart_coords, (comm, rank, dims, pos.
data()))
83template <std::
size_t dims>
87 BOOST_MPI_CHECK_RESULT(MPI_Cart_rank, (comm, pos.
data(), &rank))
96inline std::pair<int, int>
cart_shift(boost::mpi::communicator
const &comm,
97 int direction,
int displacement) {
98 int src = -1, dst = -1;
99 BOOST_MPI_CHECK_RESULT(MPI_Cart_shift,
100 (comm, direction, displacement, &src, &dst))
113template <std::
size_t dim>
119 for (std::size_t i = 0; i < dim; i++) {
120 ret[2 * i + 0] = std::get<1>(
cart_shift(comm,
static_cast<int>(i), -1));
121 ret[2 * i + 1] = std::get<1>(
cart_shift(comm,
static_cast<int>(i), +1));
149template <std::
size_t dim>
153 BOOST_MPI_CHECK_RESULT(MPI_Cart_get, (comm, dim, ret.dims.data(),
154 ret.periods.data(), ret.coords.data()));
Vector implementation and trait types for boost qvm interoperability.
int cart_rank(boost::mpi::communicator const &comm, const Vector< int, dims > &pos)
Wrapper around MPI_Cart_rank.
std::pair< int, int > cart_shift(boost::mpi::communicator const &comm, int direction, int displacement)
Wrapper around MPI_Cart_shift.
Vector3i cart_coords(boost::mpi::communicator const &comm, int rank)
Wrapper around MPI_Cart_coords.
Vector< int, dim > dims_create(int nodes)
Wrapper around MPI_Dims_create.
CartInfo< dim > cart_get(const boost::mpi::communicator &comm)
Wrapper around MPI_Cart_get.
Utils::Vector< int, 2 *dim > cart_neighbors(const boost::mpi::communicator &comm)
Calculates the numbers of the nearest neighbors for a node.
boost::mpi::communicator cart_create(boost::mpi::communicator const &comm, Vector< int, dim > const &dims, bool reorder=true, Vector< int, dim > const &periodicity=Vector< int, dim >::broadcast(1))
Wrapper around MPI_Cart_create.
DEVICE_QUALIFIER constexpr pointer data() noexcept
Information about a cartesian communicator.
Utils::Vector< int, dim > dims
Utils::Vector< int, dim > periods
Utils::Vector< int, dim > coords