From 87b678371d93b9a4d2b6fb2a4b308fc1301044a2 Mon Sep 17 00:00:00 2001 From: abn Date: Fri, 12 May 2023 15:10:52 +0200 Subject: [PATCH] [mpi4py] New CMake option MEDCOUPLING_MPI4PY_DIR to specify mpi4py installation for proper typemaps inclusion in SWIG --- CMakeLists.txt | 9 +++++++++ src/MEDCoupling_Swig/CMakeLists.txt | 2 +- src/ParaMEDMEM_Swig/CMakeLists.txt | 4 ++++ src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i | 6 ++++++ src/PyWrapping/CMakeLists.txt | 4 ++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f130ad150..181e98cb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -220,6 +220,14 @@ IF(MEDCOUPLING_ENABLE_PYTHON) IF(MEDCOUPLING_SWIG4_COMPAT) LIST(APPEND CMAKE_SWIG_FLAGS "-DMEDCOUPLING_SWIG4_COMPAT") ENDIF() + + # Possibility to specify a mpi4py installation + SET(MEDCOUPLING_MPI4PY_DIR "" CACHE PATH "Path to the mpi4py installation") + IF(MEDCOUPLING_MPI4PY_DIR) + MESSAGE(STATUS "Using mpi4py directory: ${MEDCOUPLING_MPI4PY_DIR}") + SET(MEDCOUPLING_MPI4PY_INCLUDE_DIR "${MEDCOUPLING_MPI4PY_DIR}/include") + SET(MEDCOUPLING_MPI4PY_I_FILE "${MEDCOUPLING_MPI4PY_DIR}/include/mpi4py/mpi4py.i") + ENDIF() ENDIF(MEDCOUPLING_ENABLE_PYTHON) IF(MEDCOUPLING_BUILD_DOC) @@ -231,6 +239,7 @@ IF(MEDCOUPLING_BUILD_DOC) SALOME_LOG_OPTIONAL_PACKAGE(Sphinx MEDCOUPLING_BUILD_DOC) ENDIF(MEDCOUPLING_BUILD_DOC) + # Detection report SALOME_PACKAGE_REPORT_AND_CHECK() diff --git a/src/MEDCoupling_Swig/CMakeLists.txt b/src/MEDCoupling_Swig/CMakeLists.txt index 125dda076..387a34a08 100644 --- a/src/MEDCoupling_Swig/CMakeLists.txt +++ b/src/MEDCoupling_Swig/CMakeLists.txt @@ -37,7 +37,7 @@ ENDIF() SET(SWIG_MODULE_MEDCoupling_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS}") IF(MEDCOUPLING_USE_64BIT_IDS) STRING(APPEND SWIG_MODULE_MEDCoupling_EXTRA_FLAGS ";-DMEDCOUPLING_USE_64BIT_IDS") -ENDIF(MEDCOUPLING_USE_64BIT_IDS) +ENDIF() SET (MEDCoupling_SWIG_DPYS_FILES MEDCouplingCommon.i diff --git a/src/ParaMEDMEM_Swig/CMakeLists.txt b/src/ParaMEDMEM_Swig/CMakeLists.txt index 47320923d..28a11ad5e 100644 --- a/src/ParaMEDMEM_Swig/CMakeLists.txt +++ b/src/ParaMEDMEM_Swig/CMakeLists.txt @@ -36,6 +36,10 @@ SET(SWIG_MODULE_ParaMEDMEM_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS IF(MEDCOUPLING_USE_64BIT_IDS) STRING(APPEND SWIG_MODULE_ParaMEDMEM_EXTRA_FLAGS ";-DMEDCOUPLING_USE_64BIT_IDS") ENDIF(MEDCOUPLING_USE_64BIT_IDS) +IF(MEDCOUPLING_MPI4PY_DIR) + INCLUDE_DIRECTORIES(${MEDCOUPLING_MPI4PY_INCLUDE_DIR}) + STRING(APPEND SWIG_MODULE_ParaMEDMEM_EXTRA_FLAGS ";-DMEDCOUPLING_MPI4PY_I_FILE=${MEDCOUPLING_MPI4PY_I_FILE}") +ENDIF() INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_DIRS} diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i index 290da2a8a..e8d1cf114 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i +++ b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i @@ -21,6 +21,12 @@ %template() std::set; +// Include mpi4py typemap if present: +#ifdef MEDCOUPLING_MPI4PY_I_FILE +%include MEDCOUPLING_MPI4PY_I_FILE +%mpi4py_typemap(Comm, MPI_Comm); +#endif + %{ #include "CommInterface.hxx" #include "ProcessorGroup.hxx" diff --git a/src/PyWrapping/CMakeLists.txt b/src/PyWrapping/CMakeLists.txt index 5bf9f8181..94ab53ebd 100644 --- a/src/PyWrapping/CMakeLists.txt +++ b/src/PyWrapping/CMakeLists.txt @@ -36,6 +36,10 @@ SET(SWIG_MODULE_medcoupling_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITION IF(MEDCOUPLING_USE_64BIT_IDS) STRING(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS ";-DMEDCOUPLING_USE_64BIT_IDS") ENDIF(MEDCOUPLING_USE_64BIT_IDS) +IF(MEDCOUPLING_MPI4PY_DIR) + INCLUDE_DIRECTORIES(${MEDCOUPLING_MPI4PY_INCLUDE_DIR}) + STRING(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS ";-DMEDCOUPLING_MPI4PY_I_FILE=${MEDCOUPLING_MPI4PY_I_FILE}") +ENDIF() SET(medcoupling_SWIG_DPYS_FILES medcoupling.i) -- 2.39.2