From: Martin Quinson Date: Tue, 15 Mar 2022 09:18:51 +0000 (+0100) Subject: Make the Eigen3 dependency optionnal X-Git-Tag: v3.31~104 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/354b481c19526a34cde110b3cadf49dbde8feec5 Make the Eigen3 dependency optionnal --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 968ab559cd..666520def4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,12 +240,19 @@ if(enable_ns3) endif() ### Check for Eigen library -find_package (Eigen3 3.3 REQUIRED NO_MODULE) -message(STATUS "Found Eigen3: ${EIGEN3_INCLUDE_DIR}") -include_directories(${EIGEN3_INCLUDE_DIR}) -if ("3.3.4" EQUAL EIGEN3_VERSION_STRING AND CMAKE_COMPILER_IS_GNUCC) - message(STATUS "Avoid build error of Eigen3 v3.3.4 using -Wno-error=int-in-bool-context") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=int-in-bool-context") +set(SIMGRID_HAVE_EIGEN3 0) +find_package (Eigen3 3.3 CONFIG + HINTS ${EIGEN3_HINT}) +if (Eigen3_FOUND) + set(SIMGRID_HAVE_EIGEN3 1) + message(STATUS "Found Eigen3: ${EIGEN3_INCLUDE_DIR}") + include_directories(${EIGEN3_INCLUDE_DIR}) + if ("3.3.4" EQUAL EIGEN3_VERSION_STRING AND CMAKE_COMPILER_IS_GNUCC) + message(STATUS "Avoid build error of Eigen3 v3.3.4 using -Wno-error=int-in-bool-context") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=int-in-bool-context") + endif() +else() + message(STATUS "Disabling model BMF because Eigen3 was not found. If it's installed, use EIGEN3_HINT to hint cmake about the location of Eigen3Config.cmake") endif() set(SIMGRID_HAVE_MSG 0) @@ -966,6 +973,11 @@ if(pybind11_FOUND) else() message(" Compile Python bindings .....: OFF (disabled, or pybind11 not found)") endif() +if(Eigen3_FOUND) + message(" Eigen3 library ..............: ${EIGEN3_VERSION_STRING} in ${EIGEN3_INCLUDE_DIR}") +else() + message(" Eigen3 library ..............: not found (EIGEN3_HINT='${EIGEN3_HINT}').") +endif() message(" Compile Smpi ................: ${HAVE_SMPI}") message(" Smpi fortran ..............: ${SMPI_FORTRAN}") message(" MPICH3 testsuite ..........: ${enable_smpi_MPICH3_testsuite}") diff --git a/docs/source/Installing_SimGrid.rst b/docs/source/Installing_SimGrid.rst index e762c42d1d..262641956d 100644 --- a/docs/source/Installing_SimGrid.rst +++ b/docs/source/Installing_SimGrid.rst @@ -124,10 +124,11 @@ boost (at least v1.48, v1.59 recommended) - On Debian / Ubuntu: ``apt install libboost-dev libboost-context-dev`` - On CentOS / Fedora: ``yum install boost-devel`` - On macOS with homebrew: ``brew install boost`` -Eigen3 +Eigen3 (optional) - On Debian / Ubuntu: ``apt install libeigen3-dev`` - On CentOS / Fedora: ``yum install eigen3-devel`` - On macOS with homebrew: ``brew install eigen`` + - Use EIGEN3_HINT to specify where it's installed if cmake doesn't find it automatically. Java (optional): - Debian / Ubuntu: ``apt install default-jdk libgcj18-dev`` (or any version of libgcj) @@ -298,6 +299,9 @@ minimal-bindings (on/OFF) NS3_HINT (empty by default) Alternative path into which ns-3 should be searched for. +EIGEN3_HINT (empty by default) + Alternative path into which Eigen3 should be searched for. + SIMGRID_PYTHON_LIBDIR (auto-detected) Where to install the Python module library. By default, it is set to the cmake Python3_SITEARCH variable if installing to /usr, and a modified version of that variable if installing to another path. Just force another value if the auto-detected default diff --git a/include/simgrid/config.h.in b/include/simgrid/config.h.in index bfd3403fab..e0d14a13b3 100644 --- a/include/simgrid/config.h.in +++ b/include/simgrid/config.h.in @@ -18,4 +18,6 @@ /* Was the ns-3 support compiled in? */ #cmakedefine01 SIMGRID_HAVE_NS3 #cmakedefine NS3_MINOR_VERSION @NS3_MINOR_VERSION@ +/* Was the Eigen3 support compiled in? */ +#cmakedefine01 SIMGRID_HAVE_EIGEN3 #endif /* SIMGRID_PUBLIC_CONFIG_H */ diff --git a/src/kernel/lmm/bmf.cpp b/src/kernel/lmm/bmf.cpp index 4f81303053..b040b5d972 100644 --- a/src/kernel/lmm/bmf.cpp +++ b/src/kernel/lmm/bmf.cpp @@ -4,6 +4,8 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/kernel/lmm/bmf.hpp" +#include "xbt/config.hpp" + #include #include #include @@ -11,7 +13,13 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_bmf, kernel, "Kernel BMF solver"); -int sg_bmf_max_iterations = 1000; /* Change this with --cfg=bmf/max-iterations:VALUE */ +simgrid::config::Flag + cfg_bmf_max_iteration("bmf/max-iterations", + "Maximum number of steps to be performed while searching for a BMF allocation", 1000); + +simgrid::config::Flag cfg_bmf_selective_update{ + "bmf/selective-update", "Update the constraint set propagating recursively to others constraints (off by default)", + false}; namespace simgrid { namespace kernel { @@ -66,6 +74,8 @@ BmfSolver::BmfSolver(Eigen::MatrixXd A, Eigen::MatrixXd maxA, Eigen::VectorXd C, , C_shared_(std::move(shared)) , phi_(std::move(phi)) , gen_(A_) + , max_iteration_(cfg_bmf_max_iteration) + { xbt_assert(max_iteration_ > 0, "Invalid number of iterations for BMF solver. Please check your \"bmf/max-iterations\" configuration."); diff --git a/src/kernel/lmm/bmf.hpp b/src/kernel/lmm/bmf.hpp index d039d247b7..e478df6c36 100644 --- a/src/kernel/lmm/bmf.hpp +++ b/src/kernel/lmm/bmf.hpp @@ -180,7 +180,7 @@ private: AllocationGenerator gen_; std::vector allocations_age_; static constexpr int NO_RESOURCE = -1; //!< flag to indicate player has selected no resource - int max_iteration_ = sg_bmf_max_iterations; //!< number maximum of iterations of BMF algorithm + int max_iteration_; //!< number maximum of iterations of BMF algorithm }; /** diff --git a/src/simgrid/sg_config.cpp b/src/simgrid/sg_config.cpp index 196254d41c..0259c1c5aa 100644 --- a/src/simgrid/sg_config.cpp +++ b/src/simgrid/sg_config.cpp @@ -266,15 +266,6 @@ void sg_config_init(int *argc, char **argv) "Maximum number of concurrent variables in the maxmim system. Also limits the number of " "processes on each host, at higher level. (default: -1 means no such limitation)"); - simgrid::config::bind_flag(sg_bmf_max_iterations, "bmf/max-iterations", - "Maximum number of steps to be performed while searching for a BMF allocation"); - - simgrid::config::Flag _sg_bmf_selective_update{ - "bmf/selective-update", - "Update the constraint set propagating recursively to others constraints " - "(off by default)", - false}; - /* The parameters of network models */ sg_latency_factor = 13.01; // comes from the default LV08 network model diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index 9039cff205..f7a89a700f 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -7,8 +7,11 @@ #include #include +#include "simgrid/config.h" #include "src/kernel/EngineImpl.hpp" +#if SIMGRID_HAVE_EIGEN3 #include "src/kernel/lmm/bmf.hpp" +#endif #include "src/kernel/resource/profile/Event.hpp" #include "src/surf/ptask_L07.hpp" @@ -33,6 +36,7 @@ void surf_host_model_init_ptask_L07() void surf_host_model_init_ptask_BMF() { +#if SIMGRID_HAVE_EIGEN3 XBT_CINFO(xbt_cfg, "Switching to the BMF model to handle parallel tasks."); bool select = simgrid::config::get_value("bmf/selective-update"); @@ -41,6 +45,9 @@ void surf_host_model_init_ptask_BMF() auto* engine = simgrid::kernel::EngineImpl::get_instance(); engine->add_model(host_model); engine->get_netzone_root()->set_host_model(host_model); +#else + xbt_die("Cannot use the BMF ptask model without installing Eigen3."); +#endif } namespace simgrid { diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index d59b9a557f..95d9acebaf 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -29,7 +29,6 @@ XBT_PRIVATE std::ifstream* surf_ifsopen(const std::string& name); XBT_PUBLIC_DATA double sg_maxmin_precision; XBT_PUBLIC_DATA double sg_surf_precision; XBT_PUBLIC_DATA int sg_concurrency_limit; -XBT_PUBLIC_DATA int sg_bmf_max_iterations; extern XBT_PRIVATE double sg_latency_factor; extern XBT_PRIVATE double sg_bandwidth_factor; diff --git a/teshsuite/models/CMakeLists.txt b/teshsuite/models/CMakeLists.txt index ad0da936ce..f5b97d2c24 100644 --- a/teshsuite/models/CMakeLists.txt +++ b/teshsuite/models/CMakeLists.txt @@ -1,4 +1,12 @@ -foreach(x cloud-sharing ptask_L07_usage ptask-subflows wifi_usage wifi_usage_decay cm02-set-lat-bw) +if (Eigen3_FOUND) + set(optional_examples ptask-subflows) +else() + foreach(x ptask-subflows) + set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.cpp) + set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) + endforeach() +endif() +foreach(x cloud-sharing ptask_L07_usage wifi_usage wifi_usage_decay cm02-set-lat-bw ${optional_examples}) add_executable (${x} EXCLUDE_FROM_ALL ${x}/${x}.cpp) target_link_libraries(${x} simgrid) set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index ed9cb8875c..e027e97249 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -292,8 +292,6 @@ set(NS3_SRC src/surf/network_ns3.cpp src/surf/ns3/ns3_simulator.cpp ) set(SURF_SRC - src/kernel/lmm/bmf.hpp - src/kernel/lmm/bmf.cpp src/kernel/lmm/fair_bottleneck.cpp src/kernel/lmm/maxmin.hpp src/kernel/lmm/maxmin.cpp @@ -356,6 +354,17 @@ set(SURF_SRC src/surf/HostImpl.cpp src/surf/ptask_L07.cpp ) +if (Eigen3_FOUND) + set(SURF_SRC + ${SURF_SRC} + src/kernel/lmm/bmf.hpp + src/kernel/lmm/bmf.cpp) +else() + set(EXTRA_DIST + ${EXTRA_DIST} + src/kernel/lmm/bmf.hpp + src/kernel/lmm/bmf.cpp) +endif() set(PLUGINS_SRC src/plugins/ProducerConsumer.cpp diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index b6108a626e..3862f8445e 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -136,15 +136,19 @@ set(UNIT_TESTS src/xbt/unit-tests_main.cpp src/xbt/config_test.cpp src/xbt/dict_test.cpp src/xbt/dynar_test.cpp - src/xbt/random_test.cpp + src/xbt/random_test.cpp src/xbt/xbt_str_test.cpp - src/kernel/lmm/bmf_test.cpp - src/kernel/lmm/maxmin_test.cpp) + src/kernel/lmm/maxmin_test.cpp) if (SIMGRID_HAVE_MC) set(UNIT_TESTS ${UNIT_TESTS} src/mc/sosp/Snapshot_test.cpp src/mc/sosp/PageStore_test.cpp) else() set(EXTRA_DIST ${EXTRA_DIST} src/mc/sosp/Snapshot_test.cpp src/mc/sosp/PageStore_test.cpp) endif() +if (SIMGRID_HAVE_EIGEN3) + set(UNIT_TESTS ${UNIT_TESTS} src/kernel/lmm/bmf_test.cpp) +else() + set(EXTRA_DIST ${EXTRA_DIST} src/kernel/lmm/bmf_test.cpp) +endif() set(EXTRA_DIST ${EXTRA_DIST} src/kernel/routing/NetZone_test.hpp) add_executable (unit-tests EXCLUDE_FROM_ALL ${UNIT_TESTS})