Skip to content

Commit 7bfe885

Browse files
support no MPI install
1 parent e15d5cc commit 7bfe885

File tree

4 files changed

+41
-30
lines changed

4 files changed

+41
-30
lines changed

CMakeLists.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ cmake_format(cmake_format ${PROJECT_SOURCE_DIR}/CMakeLists.txt)
4444
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
4545

4646
# MPI
47-
find_package(MPI REQUIRED)
48-
message("-- MPI libraries found in " "${MPI_LIBRARIES}")
49-
message("-- MPI include files found in " "${MPI_INCLUDE_PATH}")
50-
separate_arguments(MPIEXEC_PREFLAGS) # to support multi flags
51-
47+
find_package(MPI)
48+
if(MPI_FOUND)
49+
message("-- MPI libraries found in " "${MPI_LIBRARIES}")
50+
message("-- MPI include files found in " "${MPI_INCLUDE_PATH}")
51+
separate_arguments(MPIEXEC_PREFLAGS) # to support multi flags
52+
endif()
5253
# OPENMP
5354
find_package(OpenMP)
5455

@@ -68,21 +69,20 @@ find_package(
6869
message("-- Python executable:" "${Python_EXECUTABLE}")
6970

7071
# MPI4PY
71-
find_package(MPI4PY REQUIRED)
72-
message("-- MPI4PY include dir:" "${MPI4PY_INCLUDE_DIR}")
72+
if(MPI_FOUND)
73+
find_package(MPI4PY REQUIRED)
74+
message("-- MPI4PY include dir:" "${MPI4PY_INCLUDE_DIR}")
75+
endif()
7376

7477
add_subdirectory(lib/pybind11)
7578

7679
pybind11_add_module(Htool src/htool/main.cpp)
77-
target_include_directories(
78-
Htool
79-
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/htool/include>
80-
$<INSTALL_INTERFACE:lib/htool/include>
81-
lib/htool/include
82-
lib/hpddm/include
83-
${MPI_INCLUDE_PATH}
84-
${MKL_INC_DIR}
85-
${MPI4PY_INCLUDE_DIR})
80+
target_include_directories(Htool PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/htool/include> $<INSTALL_INTERFACE:lib/htool/include> lib/htool/include lib/hpddm/include ${MKL_INC_DIR})
81+
if(MPI_FOUND)
82+
target_link_libraries(Htool PRIVATE MPI::MPI_CXX)
83+
target_include_directories(Htool PRIVATE ${MPI_INCLUDE_PATH} ${MPI4PY_INCLUDE_DIR})
84+
target_compile_definitions(Htool PRIVATE HAVE_MPI)
85+
endif()
8686
target_link_libraries(Htool PRIVATE ${MPI_LIBRARIES} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${ARPACK_LIBRARIES} ${OpenMP_CXX_LIBRARIES})
8787

8888
if("${BLA_VENDOR}" STREQUAL "Intel10_32"

src/htool/clustering/cluster_node.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define HTOOL_CLUSTER_CPP
33
#define PYBIND11_DETAILED_ERROR_MESSAGES
44
#include <htool/clustering/cluster_node.hpp>
5-
#include <mpi.h>
65
#include <pybind11/numpy.h>
76
#include <pybind11/pybind11.h>
87
#include <pybind11/stl.h>

src/htool/hmatrix/hmatrix.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
#include <pybind11/pybind11.h>
88
#include <pybind11/stl.h>
99

10-
#include "../misc/wrapper_mpi.hpp"
11-
1210
#include <htool/hmatrix/hmatrix.hpp>
13-
#include <htool/hmatrix/hmatrix_distributed_output.hpp>
1411
#include <htool/hmatrix/hmatrix_output.hpp>
1512
#include <htool/hmatrix/linalg/add_hmatrix_vector_product.hpp>
1613
#include <htool/hmatrix/utils/recompression.hpp>
1714

15+
#ifdef HAVE_MPI
16+
# include "../misc/wrapper_mpi.hpp"
17+
# include <htool/hmatrix/hmatrix_distributed_output.hpp>
18+
#endif
19+
1820
namespace py = pybind11;
1921
using namespace pybind11::literals;
2022
using namespace htool;
@@ -45,7 +47,9 @@ void declare_HMatrix(py::module &m, const std::string &className) {
4547

4648
py_class.def("get_tree_parameters", [](const HMatrix<CoefficientPrecision, CoordinatePrecision> &hmatrix) { return htool::get_tree_parameters(hmatrix); });
4749
py_class.def("get_local_information", [](const HMatrix<CoefficientPrecision, CoordinatePrecision> &hmatrix) { return htool::get_hmatrix_information(hmatrix); });
50+
#ifdef HAVE_MPI
4851
py_class.def("get_distributed_information", [](const HMatrix<CoefficientPrecision, CoordinatePrecision> &hmatrix, MPI_Comm_wrapper comm) { return htool::get_distributed_hmatrix_information(hmatrix, comm); });
52+
#endif
4953
py_class.def("get_target_cluster", &HMatrix<CoefficientPrecision, CoordinatePrecision>::get_target_cluster, py::return_value_policy::reference_internal);
5054
py_class.def("get_source_cluster", &HMatrix<CoefficientPrecision, CoordinatePrecision>::get_source_cluster, py::return_value_policy::reference_internal);
5155

src/htool/main.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,33 @@
1919
#include "local_operator/local_renumbering.hpp"
2020
#include "local_operator/virtual_local_to_local_operator.hpp"
2121

22-
#include "distributed_operator/distributed_operator.hpp"
23-
#include "distributed_operator/utility.hpp"
24-
25-
#include "solver/geneo/coarse_operator_builder.hpp"
26-
#include "solver/geneo/coarse_space_dense_builder.hpp"
27-
#include "solver/interfaces/virtual_coarse_operator_builder.hpp"
28-
#include "solver/interfaces/virtual_coarse_space_builder.hpp"
29-
#include "solver/solver.hpp"
30-
#include "solver/utility.hpp"
22+
#ifdef HAVE_MPI
23+
# include "distributed_operator/distributed_operator.hpp"
24+
# include "distributed_operator/utility.hpp"
25+
26+
# include "misc/wrapper_mpi.hpp"
27+
# include "solver/geneo/coarse_operator_builder.hpp"
28+
# include "solver/geneo/coarse_space_dense_builder.hpp"
29+
# include "solver/interfaces/virtual_coarse_operator_builder.hpp"
30+
# include "solver/interfaces/virtual_coarse_space_builder.hpp"
31+
# include "solver/solver.hpp"
32+
# include "solver/utility.hpp"
33+
#endif
3134

3235
#include "matplotlib/cluster.hpp"
3336
#include "matplotlib/hmatrix.hpp"
3437
#include "misc/logger.hpp"
35-
#include "misc/wrapper_mpi.hpp"
3638

3739
PYBIND11_MODULE(Htool, m) {
3840
// Delegate logging to python logging module
3941
htool::Logger::get_instance().set_current_writer(std::make_shared<PythonLoggerWriter>());
4042

43+
#ifdef HAVE_MPI
4144
// import the mpi4py API
4245
if (import_mpi4py() < 0) {
4346
throw std::runtime_error("Could not load mpi4py API."); // LCOV_EXCL_LINE
4447
}
48+
#endif
4549

4650
declare_cluster_node<double>(m, "Cluster");
4751
declare_virtual_partitioning<double>(m, "");
@@ -59,6 +63,7 @@ PYBIND11_MODULE(Htool, m) {
5963
declare_custom_VirtualDenseBlocksGenerator<double>(m, "VirtualDenseBlocksGenerator");
6064
declare_hmatrix_builder<double, double>(m, "HMatrixTreeBuilder");
6165

66+
#ifdef HAVE_MPI
6267
declare_local_renumbering<double>(m, "LocalRenumbering");
6368
declare_global_to_local_operator<double>(m, "");
6469
declare_virtual_local_to_local_operator<double>(m, "");
@@ -73,6 +78,7 @@ PYBIND11_MODULE(Htool, m) {
7378
declare_DDM<double>(m, "Solver");
7479

7580
declare_solver_utility<double, double>(m);
81+
#endif
7682

7783
declare_matplotlib_cluster<double>(m);
7884
declare_matplotlib_hmatrix<double, double>(m);
@@ -85,6 +91,7 @@ PYBIND11_MODULE(Htool, m) {
8591
declare_custom_VirtualDenseBlocksGenerator<std::complex<double>>(m, "ComplexVirtualDenseBlocksGenerator");
8692
declare_hmatrix_builder<std::complex<double>, double>(m, "ComplexHMatrixTreeBuilder");
8793

94+
#ifdef HAVE_MPI
8895
declare_global_to_local_operator<std::complex<double>>(m, "Complex");
8996
declare_virtual_local_to_local_operator<std::complex<double>>(m, "Complex");
9097
declare_distributed_operator<std::complex<double>>(m, "ComplexDistributedOperator");
@@ -98,4 +105,5 @@ PYBIND11_MODULE(Htool, m) {
98105
declare_virtual_geneo_coarse_space_dense_builder<std::complex<double>>(m, "VirtualComplexGeneoCoarseSpaceDenseBuilder");
99106

100107
declare_solver_utility<std::complex<double>, double>(m, "Complex");
108+
#endif
101109
}

0 commit comments

Comments
 (0)