Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Solver as an configuration option for CPU
[simgrid.git] / src / kernel / lmm / maxmin.cpp
index 485159d..1eaae73 100644 (file)
@@ -4,6 +4,9 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/kernel/lmm/maxmin.hpp"
+#if SIMGRID_HAVE_EIGEN3
+#include "src/kernel/lmm/bmf.hpp"
+#endif
 #include <boost/core/demangle.hpp>
 #include <typeinfo>
 
@@ -22,6 +25,11 @@ using dyn_light_t = std::vector<int>;
 int Variable::next_rank_   = 1;
 int Constraint::next_rank_ = 1;
 
+Element::Element(Constraint* constraint, Variable* variable, double cweight)
+    : constraint(constraint), variable(variable), consumption_weight(cweight), max_consumption_weight(cweight)
+{
+}
+
 int Element::get_concurrency() const
 {
   // Ignore element with weight less than one (e.g. cross-traffic)
@@ -52,6 +60,34 @@ void Element::increase_concurrency()
              "Concurrency limit overflow!");
 }
 
+System* System::build(const std::string& solver_name, bool selective_update)
+{
+  System* system = nullptr;
+  if (solver_name == "bmf") {
+#if SIMGRID_HAVE_EIGEN3
+    system = new lmm::BmfSystem(selective_update);
+#endif
+  } else if (solver_name == "fairbottleneck") {
+    system = new FairBottleneck(selective_update);
+  } else {
+    system = new System(selective_update);
+  }
+  return system;
+}
+
+void System::validate_solver(const std::string& solver_name)
+{
+  static const std::vector<std::string> opts{"bmf", "maxmin", "fairbottleneck"};
+  if (solver_name == "bmf") {
+#if !SIMGRID_HAVE_EIGEN3
+    xbt_die("Cannot use the BMF solver without installing Eigen3.");
+#endif
+  }
+  if (std::find(opts.begin(), opts.end(), solver_name) == std::end(opts)) {
+    xbt_die("Invalid system solver, it should be one of: \"maxmin\", \"fairbottleneck\" or \"bmf\"");
+  }
+}
+
 void System::check_concurrency() const
 {
   // These checks are very expensive, so do them only if we want to debug SURF LMM
@@ -236,13 +272,9 @@ void System::expand(Constraint* cnst, Variable* var, double consumption_weight)
 
   xbt_assert(var->cnsts_.size() < var->cnsts_.capacity(), "Too much constraints");
 
-  var->cnsts_.emplace_back();
+  var->cnsts_.emplace_back(cnst, var, consumption_weight);
   Element& elem = var->cnsts_.back();
 
-  elem.consumption_weight = consumption_weight;
-  elem.constraint         = cnst;
-  elem.variable           = var;
-
   if (var->sharing_penalty_ != 0.0) {
     elem.constraint->enabled_element_set_.push_front(elem);
     elem.increase_concurrency();
@@ -276,6 +308,7 @@ void System::expand_add(Constraint* cnst, Variable* var, double value)
     if (var->sharing_penalty_ != 0.0)
       elem.decrease_concurrency();
 
+    elem.max_consumption_weight = std::max(elem.max_consumption_weight, value);
     if (cnst->sharing_policy_ != Constraint::SharingPolicy::FATPIPE)
       elem.consumption_weight += value;
     else