This repository was archived by the owner on Feb 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Allow custom communicators #12
Copy link
Copy link
Open
Description
This is technically not as trivial as expected, since it requires something along the lines of
#include <mpi4py/mpi4py.h>
namespace pybind11 { namespace detail {
template <> struct type_caster<mpi4py_comm> {
public:
PYBIND11_TYPE_CASTER(mpi4py_comm, _("mpi4py_comm"));
// Python -> C++
bool load(handle src, bool) {
PyObject *py_src = src.ptr();
// Check that we have been passed an mpi4py communicator
if (PyObject_TypeCheck(py_src, &PyMPIComm_Type)) {
// Convert to regular MPI communicator
value.value = *PyMPIComm_Get(py_src);
} else {
return false;
}
return !PyErr_Occurred();
}
// C++ -> Python
static handle cast(mpi4py_comm src,
return_value_policy /* policy */,
handle /* parent */)
{
// Create an mpi4py handle
return PyMPIComm_New(src.value);
}
};
}} // namespace pybind11::detail
See: https://stackoverflow.com/a/62449190
The issue is that it requires that we build our C++ against the C++ backend of mpi4py. Which opens us up to incompatibilities, e.g., because pip install mpi4py installs one version but CMake picks up an entirely different version.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels