mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-11 16:49:16 +05:00
mpi4py support
This commit is contained in:
parent
31a64cd728
commit
eb75bc31a6
@ -14,6 +14,7 @@ option( USE_NATIVE_ARCH "build for native cpu architecture" ON)
|
||||
option( USE_GUI "don't build netgen with GUI" ON )
|
||||
option( USE_PYTHON "build with python interface" ON )
|
||||
option( USE_MPI "enable mpi parallelization" OFF )
|
||||
option( USE_MPI4PY "enable mpi4py interface" ON )
|
||||
option( USE_OCC "(not supported) compile with OpenCascade geometry kernel" OFF)
|
||||
option( USE_JPEG "enable snapshots using library libjpeg" OFF )
|
||||
option( USE_MPEG "enable video recording with FFmpeg, uses libavcodec" OFF )
|
||||
@ -297,6 +298,14 @@ if (USE_MPI)
|
||||
target_include_directories(netgen_metis INTERFACE ${METIS_INCLUDE_DIR})
|
||||
target_link_libraries(netgen_metis INTERFACE ${METIS_LIBRARY} )
|
||||
target_compile_definitions(netgen_metis INTERFACE METIS )
|
||||
|
||||
if(USE_MPI4PY AND USE_PYTHON)
|
||||
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import mpi4py;print(mpi4py.get_include())" OUTPUT_VARIABLE mpi4py_path OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
find_path(MPI4PY_INCLUDE_DIR mpi4py.h HINTS ${mpi4py_path}/mpi4py NO_DEFAULT_PATH REQUIRED)
|
||||
target_include_directories(netgen_metis INTERFACE ${MPI4PY_INCLUDE_DIR})
|
||||
target_compile_definitions(netgen_metis INTERFACE NG_MPI4PY )
|
||||
message(STATUS "Found mpi4py: ${MPI4PY_INCLUDE_DIR}")
|
||||
endif(USE_MPI4PY AND USE_PYTHON)
|
||||
endif (USE_MPI)
|
||||
install(TARGETS netgen_mpi netgen_metis ${NG_INSTALL_DIR})
|
||||
|
||||
|
@ -13,6 +13,53 @@
|
||||
#include <../interface/writeuser.hpp>
|
||||
|
||||
|
||||
#ifdef NG_MPI4PY
|
||||
#include <mpi4py.h>
|
||||
|
||||
struct mpi4py_comm {
|
||||
mpi4py_comm() = default;
|
||||
mpi4py_comm(MPI_Comm value) : value(value) {}
|
||||
operator MPI_Comm () { return value; }
|
||||
|
||||
MPI_Comm value;
|
||||
};
|
||||
|
||||
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
|
||||
|
||||
#endif // NG_MPI4PY
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace netgen;
|
||||
|
||||
extern const char *ngscript[];
|
||||
@ -50,8 +97,15 @@ void TranslateException (const NgException & ex)
|
||||
|
||||
static Transformation<3> global_trafo(Vec<3> (0,0,0));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
{
|
||||
#ifdef NG_MPI4PY
|
||||
import_mpi4py();
|
||||
#endif // NG_MPI4PY
|
||||
py::register_exception<NgException>(m, "NgException");
|
||||
m.attr("_netgen_executable_started") = py::cast(netgen::netgen_executable_started);
|
||||
string script;
|
||||
@ -71,6 +125,12 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
m.def("_SetThreadPercentage", [](double percent) { SetThreadPercent(percent); });
|
||||
|
||||
py::class_<NgMPI_Comm> (m, "MPI_Comm")
|
||||
#ifdef NG_MPI4PY
|
||||
.def(py::init([] (mpi4py_comm comm)
|
||||
{
|
||||
return NgMPI_Comm(comm);
|
||||
}))
|
||||
#endif // NG_MPI4PY
|
||||
.def_property_readonly ("rank", &NgMPI_Comm::Rank)
|
||||
.def_property_readonly ("size", &NgMPI_Comm::Size)
|
||||
.def("Barrier", &NgMPI_Comm::Barrier)
|
||||
@ -100,6 +160,9 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
;
|
||||
|
||||
|
||||
#ifdef NG_MPI4PY
|
||||
py::implicitly_convertible<mpi4py_comm, NgMPI_Comm>();
|
||||
#endif // NG_MPI4PY
|
||||
|
||||
|
||||
py::class_<NGDummyArgument>(m, "NGDummyArgument")
|
||||
|
@ -1,5 +1,5 @@
|
||||
FROM ubuntu:18.04
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
MAINTAINER Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
|
||||
RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy python3-tk clang-tidy python3-distutils clang libopenmpi-dev openmpi-bin gfortran
|
||||
RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy python3-tk python3-mpi4py clang-tidy python3-distutils clang libopenmpi-dev openmpi-bin gfortran
|
||||
ADD . /root/src/netgen
|
||||
|
Loading…
Reference in New Issue
Block a user