5#include <pybind11/stl.h>
6#include <pybind11/numpy.h>
17 .def(py::init([](uintptr_t pComm)
19 {
return std::make_unique<MPIInfo>(MPI_Comm(pComm)); }))
23 .def(
"comm", [](
const MPIInfo &self)
24 {
return size_t(self.
comm); })
25 .def(
"equals", &MPIInfo::operator==);
33 auto m_MPI =
m.def_submodule(
"MPI");
36 [](
const std::vector<std::string> &pArgv)
49 int initial_argc =
static_cast<int>(pArgv.size());
50 int initial_argc_mine = initial_argc;
59 char **argv_array =
new char *[initial_argc + 1];
60 char **argv_array_mine = argv_array;
63 for (
int i = 0;
i < initial_argc; ++
i)
65 const std::string &s = pArgv[
i];
66 size_t len = s.length();
67 char *cstr =
new char[len + 1];
68 strcpy(cstr, s.c_str());
71 argv_array[initial_argc] =
nullptr;
73 int *pargc = &initial_argc;
74 char ***pargv = &argv_array;
79 std::vector<std::string> pArgvOut;
80 pArgvOut.reserve(*pargc);
81 for (
int i = 0;
i < *pargc; ++
i)
82 pArgvOut.emplace_back(argv_array[
i]);
87 for (
int i = 0;
i <= initial_argc_mine; ++
i)
88 delete[] argv_array_mine[
i];
89 delete[] argv_array_mine;
92 return std::make_tuple(ret, pArgvOut);
105 auto m_MPI =
m.def_submodule(
"MPI");
108 [](
const py::buffer &py_sendbuf,
const py::buffer &py_recvbuf,
const std::string &op,
const MPIInfo &mpi)
110 auto send_info = py_sendbuf.request(
false);
111 auto recv_info = py_recvbuf.request(
true);
114 fmt::format(
"send and recv buffer format incompatible: [{}], [{}]",
115 send_info.format, recv_info.format));
126 datatype, mpi_op, mpi.comm);
128 py::arg(
"send"), py::arg(
"recv"), py::arg(
"op"), py::arg(
"mpi"));
139 auto m_Debug =
m.def_submodule(
"Debug");
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
MPI wrappers: MPIInfo, collective operations, type mapping, CommStrategy.
pybind11 bindings for the DNDS MPI wrappers (MPIInfo, CommStrategy, buffer-protocol datatype helpers)...
Eigen::Matrix< real, 3, 3 > m
bool IsDebugged()
Whether the current process is running under a debugger. Implemented via /proc/self/status TracerPid ...
void MPIDebugHold(const MPIInfo &mpi)
If isDebugging is set, block every rank in a busy-wait loop so the user can attach a debugger and ins...
void pybind11_Debug(py::module_ &m)
void pybind11_Init_thread(py::module_ &m)
int Finalize()
Release DNDSR-registered MPI resources then call MPI_Finalize.
void pybind11_MPI_Operations(py::module_ &m)
MPI_int Allreduce(const void *sendbuf, void *recvbuf, MPI_int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
Wrapper over MPI_Allreduce.
MPI_int Init_thread(int *argc, char ***argv)
Initialise MPI with thread support, honouring the DNDS_DISABLE_ASYNC_MPI environment override.
int GetMPIThreadLevel()
Return the MPI thread-support level the current process was initialised with.
the host side operators are provided as implemented
MPI_Op py_get_simple_mpi_op_by_name(const std::string &op)
py::classh< T > py_class_ssp
std::tuple< ssize_t, char > py_buffer_get_contigious_size(const py::buffer_info &info)
void pybind11_MPIInfo(py::module_ &m)
MPI_Datatype py_get_buffer_basic_mpi_datatype(const py::buffer_info &info)
void pybind11_bind_MPI_All(py::module_ &m)
int MPI_int
MPI counterpart type for MPI_int (= C int). Used for counts and ranks in MPI calls.
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
int size
Number of ranks in comm (-1 until initialised).
int rank
This rank's 0-based index within comm (-1 until initialised).
MPI_Comm comm
The underlying MPI communicator handle.
void setWorld()
Initialise the object to MPI_COMM_WORLD. Requires MPI_Init to have run.