-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EAMxx: add support for passing MPI comm from py to C in pyeamxx
- Loading branch information
Showing
5 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# - FindMPI4PY | ||
# Find mpi4py includes | ||
# This module defines: | ||
# MPI4PY_INCLUDE_DIR, where to find mpi4py.h, etc. | ||
# MPI4PY_FOUND | ||
|
||
function (SetMpi4pyIncludeDir) | ||
endfunction() | ||
|
||
if (NOT TARGET mpi4py) | ||
# If user provided an include dir, we will use that, otherwise we'll ask python to find it | ||
if (NOT MPI4PY_INCLUDE_DIR) | ||
execute_process(COMMAND | ||
"${PYTHON_EXECUTABLE}" "-c" "import mpi4py; print (mpi4py.get_include())" | ||
OUTPUT_VARIABLE OUTPUT | ||
RESULT_VARIABLE RESULT | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
if (RESULT) | ||
set(MPI4PY_FOUND FALSE) | ||
else () | ||
set (MPI4PY_INCLUDE_DIR ${OUTPUT} CACHE PATH "Path to mpi4py include directory" FORCE) | ||
endif() | ||
endif() | ||
|
||
# If we still don't have an include dir, it means we have no mpi4py installed | ||
if (NOT MPI4PY_INCLUDE_DIR) | ||
set(MPI4PY_FOUND FALSE) | ||
else () | ||
add_library(mpi4py INTERFACE) | ||
target_include_directories(mpi4py INTERFACE SYSTEM ${MPI4PY_INCLUDE_DIR}) | ||
set(MPI4PY_FOUND TRUE) | ||
endif() | ||
endif() | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(mpi4py DEFAULT_MSG MPI4PY_INCLUDE_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
find_package(pybind11 REQUIRED) | ||
find_package(mpi4py REQUIRED) | ||
|
||
pybind11_add_module(pyeamxx pyeamxx.cpp) | ||
target_link_libraries(pyeamxx PUBLIC scream_share scream_io diagnostics eamxx_physics) | ||
target_link_libraries(pyeamxx PUBLIC mpi4py scream_share scream_io diagnostics eamxx_physics) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef PYUTILS_HPP | ||
#define PYUTILS_HPP | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <mpi4py/mpi4py.h> | ||
#include <mpi.h> | ||
|
||
#include <typeinfo> | ||
|
||
MPI_Comm get_c_comm (pybind11::object py_comm) { | ||
if (import_mpi4py() < 0) { | ||
throw pybind11::error_already_set(); | ||
} | ||
auto py_src = py_comm.ptr(); | ||
if (not PyObject_TypeCheck(py_src, &PyMPIComm_Type)) { | ||
throw std::bad_cast(); | ||
} | ||
|
||
auto comm_ptr = PyMPIComm_Get(py_src); | ||
return *comm_ptr; | ||
} | ||
|
||
#endif // PYUTILS_HPP |