Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make the Eigen3 dependency optionnal
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 15 Mar 2022 09:18:51 +0000 (10:18 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 15 Mar 2022 09:18:51 +0000 (10:18 +0100)
CMakeLists.txt
docs/source/Installing_SimGrid.rst
include/simgrid/config.h.in
src/kernel/lmm/bmf.cpp
src/kernel/lmm/bmf.hpp
src/simgrid/sg_config.cpp
src/surf/ptask_L07.cpp
src/surf/surf_interface.hpp
teshsuite/models/CMakeLists.txt
tools/cmake/DefinePackages.cmake
tools/cmake/Tests.cmake

index 968ab55..666520d 100644 (file)
@@ -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}")
index e762c42..2626419 100644 (file)
@@ -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 
index bfd3403..e0d14a1 100644 (file)
@@ -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 */
index 4f81303..b040b5d 100644 (file)
@@ -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 <Eigen/LU>
 #include <iostream>
 #include <numeric>
 
 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<int>
+    cfg_bmf_max_iteration("bmf/max-iterations",
+                          "Maximum number of steps to be performed while searching for a BMF allocation", 1000);
+
+simgrid::config::Flag<bool> 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.");
index d039d24..e478df6 100644 (file)
@@ -180,7 +180,7 @@ private:
   AllocationGenerator gen_;
   std::vector<int> 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
 };
 
 /**
index 196254d..0259c1c 100644 (file)
@@ -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<bool> _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
index 9039cff..f7a89a7 100644 (file)
@@ -7,8 +7,11 @@
 #include <simgrid/s4u/Engine.hpp>
 #include <xbt/config.hpp>
 
+#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<bool>("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 {
index d59b9a5..95d9ace 100644 (file)
@@ -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;
index ad0da93..f5b97d2 100644 (file)
@@ -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})
index ed9cb88..e027e97 100644 (file)
@@ -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
index b6108a6..3862f84 100644 (file)
@@ -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})