diff --git a/.github/workflows/spack_cpu_build.yaml b/.github/workflows/spack_cpu_build.yaml index a342c9e8..89f41b36 100644 --- a/.github/workflows/spack_cpu_build.yaml +++ b/.github/workflows/spack_cpu_build.yaml @@ -14,17 +14,14 @@ jobs: # Minimal Build(s) # Need S3 mirror to have these builds speedup spack_spec: - # See #39 - ~python~mpi causes issues - # - exago@develop~mpi~ipopt~hiop~python~raja - # See #44 - +mpi~python should fail if no python in system, - # but the runner happens to have one... - - exago@develop+mpi~ipopt+hiop~python~raja ^openmpi + # See #39 - minimal build useful for sanity + - exago@develop~mpi~ipopt~hiop~python~raja + # See #16 / #44 - +python~mpi catches mpi4py / python config + - exago@develop~mpi~ipopt~hiop+python~raja # See #18 - +hiop~mpi causes issues # - exago@develop~mpi~ipopt+hiop~python+raja - # See #16 - +python~mpi causes issues - # - exago@develop~mpi~ipopt+hiop+python~raja - exago@develop+mpi~ipopt+hiop+python~raja ^openmpi - # See #40 - +hiop+raja~ipopt ^hiop~sparse is useful for edge cases + # See #40 - +hiop+raja~ipopt ^hiop~sparse is useful for edge cases in xSDK - exago@develop+mpi~ipopt+hiop~python+raja ^openmpi ^hiop+raja~sparse name: Build ExaGO with Spack @@ -41,8 +38,10 @@ jobs: SPACK_SPEC: ${{ matrix.spack_spec }} run: | ls && pwd - . ./tpl/spack/share/spack/setup-env.sh + . /opt/spack/share/spack/setup-env.sh spack debug report + spack mirror add spack_public_mirror https://binaries.spack.io/develop + spack buildcache keys --install --trust spack env create -d ./spack-env spack env activate ./spack-env spack add $SPACK_SPEC target=x86_64 diff --git a/CMakeLists.txt b/CMakeLists.txt index f3213209..8e32e86c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -406,8 +406,8 @@ else() endif() endif() -include(ExaGOCheckPython) if(EXAGO_ENABLE_PYTHON) + include(ExaGOCheckPython) # Build pybind11 target manually add_subdirectory(tpl/pybind11) add_subdirectory(interfaces/python) diff --git a/interfaces/python/CMakeLists.txt b/interfaces/python/CMakeLists.txt index 8f410aa8..e0ab774c 100644 --- a/interfaces/python/CMakeLists.txt +++ b/interfaces/python/CMakeLists.txt @@ -31,33 +31,19 @@ target_link_libraries(exago PRIVATE ${EXAGO_PY_LIBS}) # Find mpi4py c headers include(ExaGOFindPythonModule) -find_python_module(mpi4py REQUIRED) - -# Get the include directories needed -if(mpi4py_FOUND) - execute_process( - COMMAND "${Python_EXECUTABLE}" "-c" - "import mpi4py as m; print(m.__version__); print(m.get_include());" - RESULT_VARIABLE _mpi4py_SEARCH_SUCCESS - OUTPUT_VARIABLE _mpi4py_VALUES - ERROR_VARIABLE _mpi4py_ERROR_VALUE - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - # Find pytest c headers - find_python_module(pytest REQUIRED) - +if(EXAGO_ENABLE_MPI) + find_python_module(mpi4py REQUIRED) # Get the include directories needed - if(pytest_FOUND) + if(mpi4py_FOUND) execute_process( - COMMAND "${Python_EXECUTABLE}" "-c" - "import pytest as p; print(p.__version__);" - RESULT_VARIABLE _pytest_SEARCH_SUCCESS - OUTPUT_VARIABLE _pytest_VALUES - ERROR_VARIABLE _pytest_ERROR_VALUE + COMMAND + "${Python_EXECUTABLE}" "-c" + "import mpi4py as m; print(m.__version__); print(m.get_include());" + RESULT_VARIABLE _mpi4py_SEARCH_SUCCESS + OUTPUT_VARIABLE _mpi4py_VALUES + ERROR_VARIABLE _mpi4py_ERROR_VALUE OUTPUT_STRIP_TRAILING_WHITESPACE ) - # Convert the process output into a list string(REGEX REPLACE ";" "\\\\;" _mpi4py_VALUES ${_mpi4py_VALUES}) string(REGEX REPLACE "\n" ";" _mpi4py_VALUES ${_mpi4py_VALUES}) @@ -78,32 +64,47 @@ if(mpi4py_FOUND) mpi4py_VERSION_DECIMAL "(${mpi4py_VERSION_MAJOR} * 10000) + (${mpi4py_VERSION_MINOR} * 100) + ${mpi4py_VERSION_PATCH}" ) - endif() - - target_include_directories(exago SYSTEM PRIVATE ${mpi4py_INCLUDE_DIRS}) - - string(REGEX REPLACE ";" "\\\\;" _pytest_VALUES ${_pytest_VALUES}) - string(REGEX REPLACE "\n" ";" _pytest_VALUES ${_pytest_VALUES}) - list(GET _pytest_VALUES 0 pytest_VERSION) - list(GET _pytest_VALUES 0 pytest_INCLUDE_DIRS) - - # Make sure all directory separators are '/' - string(REGEX REPLACE "\\\\" "/" pytest_INCLUDE_DIRS ${pytest_INCLUDE_DIRS}) - - # Get the major and minor version numbers - string(REGEX REPLACE "\\." ";" _pytest_VERSION_LIST ${pytest_VERSION}) - list(GET _pytest_VERSION_LIST 0 pytest_VERSION_MAJOR) - list(GET _pytest_VERSION_LIST 1 pytest_VERSION_MINOR) - list(GET _pytest_VERSION_LIST 2 pytest_VERSION_PATCH) - string(REGEX MATCH "[0-9]*" pytest_VERSION_PATCH ${pytest_VERSION_PATCH}) - math( - EXPR - pytest_VERSION_DECIMAL - "(${pytest_VERSION_MAJOR} * 10000) + (${pytest_VERSION_MINOR} * 100) + ${pytest_VERSION_PATCH}" - ) -endif() -target_include_directories(exago SYSTEM PRIVATE ${pytest_INCLUDE_DIRS}) + target_include_directories(exago SYSTEM PRIVATE ${mpi4py_INCLUDE_DIRS}) + endif(mpi4py_FOUND) +endif(EXAGO_ENABLE_MPI) + +if(EXAGO_RUN_TESTS) + # Find pytest c headers + find_python_module(pytest REQUIRED) + + # Get the include directories needed + if(pytest_FOUND) + execute_process( + COMMAND "${Python_EXECUTABLE}" "-c" + "import pytest as p; print(p.__version__);" + RESULT_VARIABLE _pytest_SEARCH_SUCCESS + OUTPUT_VARIABLE _pytest_VALUES + ERROR_VARIABLE _pytest_ERROR_VALUE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + string(REGEX REPLACE ";" "\\\\;" _pytest_VALUES ${_pytest_VALUES}) + string(REGEX REPLACE "\n" ";" _pytest_VALUES ${_pytest_VALUES}) + list(GET _pytest_VALUES 0 pytest_VERSION) + list(GET _pytest_VALUES 0 pytest_INCLUDE_DIRS) + + # Make sure all directory separators are '/' + string(REGEX REPLACE "\\\\" "/" pytest_INCLUDE_DIRS ${pytest_INCLUDE_DIRS}) + + # Get the major and minor version numbers + string(REGEX REPLACE "\\." ";" _pytest_VERSION_LIST ${pytest_VERSION}) + list(GET _pytest_VERSION_LIST 0 pytest_VERSION_MAJOR) + list(GET _pytest_VERSION_LIST 1 pytest_VERSION_MINOR) + list(GET _pytest_VERSION_LIST 2 pytest_VERSION_PATCH) + string(REGEX MATCH "[0-9]*" pytest_VERSION_PATCH ${pytest_VERSION_PATCH}) + math( + EXPR + pytest_VERSION_DECIMAL + "(${pytest_VERSION_MAJOR} * 10000) + (${pytest_VERSION_MINOR} * 100) + ${pytest_VERSION_PATCH}" + ) + target_include_directories(exago SYSTEM PRIVATE ${pytest_INCLUDE_DIRS}) + endif(pytest_FOUND) +endif(EXAGO_RUN_TESTS) # Install Python bindings to same installation path: install(TARGETS exago DESTINATION ${EXAGO_PYTHON_SITELIB}) diff --git a/interfaces/python/exago_python.hpp b/interfaces/python/exago_python.hpp index 2ec153a9..34e4bde1 100644 --- a/interfaces/python/exago_python.hpp +++ b/interfaces/python/exago_python.hpp @@ -7,8 +7,11 @@ #include #include +#ifdef EXAGO_ENABLE_MPI #include #include +#endif + #include #include