Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't mix LMM sharing policy with S4U.
authorBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 17 Jun 2021 14:51:01 +0000 (16:51 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 28 Jun 2021 15:46:35 +0000 (17:46 +0200)
Add another enum for maxmin sharing policy
In the maxmin system, only FATPIPE and SHARED make sense.

src/kernel/lmm/fair_bottleneck.cpp
src/kernel/lmm/maxmin.cpp
src/kernel/lmm/maxmin.hpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp

index 98397a6..17647ff 100644 (file)
@@ -68,7 +68,7 @@ void simgrid::kernel::lmm::FairBottleneck::bottleneck_solve()
           nb++;
       }
       XBT_DEBUG("\tThere are %d variables", nb);
-      if (nb > 0 && cnst.sharing_policy_ == s4u::Link::SharingPolicy::FATPIPE)
+      if (nb > 0 && cnst.sharing_policy_ == Constraint::SharingPolicy::FATPIPE)
         nb = 1;
       if (nb == 0) {
         cnst.remaining_ = 0.0;
@@ -102,7 +102,7 @@ void simgrid::kernel::lmm::FairBottleneck::bottleneck_solve()
     for (auto iter = std::begin(cnst_list); iter != std::end(cnst_list);) {
       Constraint& cnst = *iter;
       XBT_DEBUG("Updating cnst %p ", &cnst);
-      if (cnst.sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE) {
+      if (cnst.sharing_policy_ != Constraint::SharingPolicy::FATPIPE) {
         for (const Element& elem : cnst.enabled_element_set_) {
           xbt_assert(elem.variable->sharing_penalty_ > 0);
           XBT_DEBUG("\tUpdate constraint %p (%g) with variable %p by %g", &cnst, cnst.remaining_, elem.variable,
index eec60a5..7251492 100644 (file)
@@ -276,7 +276,7 @@ void System::expand_add(Constraint* cnst, Variable* var, double value)
     if (var->sharing_penalty_ != 0.0)
       elem.decrease_concurrency();
 
-    if (cnst->sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE)
+    if (cnst->sharing_policy_ != Constraint::SharingPolicy::FATPIPE)
       elem.consumption_weight += value;
     else
       elem.consumption_weight = std::max(elem.consumption_weight, value);
@@ -402,14 +402,14 @@ static inline void saturated_variable_set_update(const ConstraintLight* cnst_lig
 }
 
 template <class ElemList>
-static void format_element_list(const ElemList& elem_list, s4u::Link::SharingPolicy sharing_policy, double& sum,
+static void format_element_list(const ElemList& elem_list, Constraint::SharingPolicy sharing_policy, double& sum,
                                 std::string& buf)
 {
   for (Element const& elem : elem_list) {
     buf += std::to_string(elem.consumption_weight) + ".'" + std::to_string(elem.variable->rank_) + "'(" +
            std::to_string(elem.variable->value_) + ")" +
-           (sharing_policy != s4u::Link::SharingPolicy::FATPIPE ? " + " : " , ");
-    if (sharing_policy != s4u::Link::SharingPolicy::FATPIPE)
+           (sharing_policy != Constraint::SharingPolicy::FATPIPE ? " + " : " , ");
+    if (sharing_policy != Constraint::SharingPolicy::FATPIPE)
       sum += elem.consumption_weight * elem.variable->value_;
     else
       sum = std::max(sum, elem.consumption_weight * elem.variable->value_);
@@ -433,14 +433,14 @@ void System::print() const
     double sum            = 0.0;
     // Show  the enabled variables
     buf += "\t";
-    buf += cnst.sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE ? "(" : "max(";
+    buf += cnst.sharing_policy_ != Constraint::SharingPolicy::FATPIPE ? "(" : "max(";
     format_element_list(cnst.enabled_element_set_, cnst.sharing_policy_, sum, buf);
     // TODO: Adding disabled elements only for test compatibility, but do we really want them to be printed?
     format_element_list(cnst.disabled_element_set_, cnst.sharing_policy_, sum, buf);
 
     buf += "0) <= " + std::to_string(cnst.bound_) + " ('" + std::to_string(cnst.rank_) + "')";
 
-    if (cnst.sharing_policy_ == s4u::Link::SharingPolicy::FATPIPE) {
+    if (cnst.sharing_policy_ == Constraint::SharingPolicy::FATPIPE) {
       buf += " [MAX-Constraint]";
     }
     XBT_DEBUG("%s", buf.c_str());
@@ -498,7 +498,7 @@ template <class CnstList> void System::lmm_solve(CnstList& cnst_list)
       xbt_assert(elem.variable->sharing_penalty_ > 0.0);
       elem.variable->value_ = 0.0;
       if (elem.consumption_weight > 0) {
-        if (cnst.sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE)
+        if (cnst.sharing_policy_ != Constraint::SharingPolicy::FATPIPE)
           cnst.usage_ += elem.consumption_weight / elem.variable->sharing_penalty_;
         else if (cnst.usage_ < elem.consumption_weight / elem.variable->sharing_penalty_)
           cnst.usage_ = elem.consumption_weight / elem.variable->sharing_penalty_;
@@ -571,7 +571,7 @@ template <class CnstList> void System::lmm_solve(CnstList& cnst_list)
       /* Update the usage of constraints where this variable is involved */
       for (Element& elem : var.cnsts_) {
         Constraint* cnst = elem.constraint;
-        if (cnst->sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE) {
+        if (cnst->sharing_policy_ != Constraint::SharingPolicy::FATPIPE) {
           // Remember: shared constraints require that sum(elem.value * var.value) < cnst->bound
           double_update(&(cnst->remaining_), elem.consumption_weight * var.value_, cnst->bound_ * sg_maxmin_precision);
           double_update(&(cnst->usage_), elem.consumption_weight / var.sharing_penalty_, sg_maxmin_precision);
@@ -914,7 +914,7 @@ void System::remove_all_modified_set()
 double Constraint::get_usage() const
 {
   double result              = 0.0;
-  if (sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE) {
+  if (sharing_policy_ != SharingPolicy::FATPIPE) {
     for (Element const& elem : enabled_element_set_)
       if (elem.consumption_weight > 0)
         result += elem.consumption_weight * elem.variable->value_;
index 3cc65d6..d85e609 100644 (file)
@@ -187,16 +187,17 @@ public:
  */
 class XBT_PUBLIC Constraint {
 public:
+  enum class SharingPolicy { SHARED = 1, FATPIPE = 0 };
   Constraint() = delete;
   Constraint(resource::Resource* id_value, double bound_value);
 
   /** @brief Unshare a constraint. */
-  void unshare() { sharing_policy_ = s4u::Link::SharingPolicy::FATPIPE; }
+  void unshare() { sharing_policy_ = SharingPolicy::FATPIPE; }
 
   /** @brief Set how a constraint is shared  */
-  void set_sharing_policy(s4u::Link::SharingPolicy policy) { sharing_policy_ = policy; }
+  void set_sharing_policy(SharingPolicy policy) { sharing_policy_ = policy; }
   /** @brief Check how a constraint is shared  */
-  s4u::Link::SharingPolicy get_sharing_policy() const { return sharing_policy_; }
+  SharingPolicy get_sharing_policy() const { return sharing_policy_; }
 
   /** @brief Get the usage of the constraint after the last lmm solve */
   double get_usage() const;
@@ -279,7 +280,7 @@ public:
   int concurrency_maximum_ = 0; /* The maximum number of (enabled and disabled) variables associated to the constraint
                                  * at any given time (essentially for tracing)*/
 
-  s4u::Link::SharingPolicy sharing_policy_ = s4u::Link::SharingPolicy::SHARED;
+  SharingPolicy sharing_policy_ = SharingPolicy::SHARED;
   int rank_; // Only used in debug messages to identify the constraint
   double lambda_               = 0.0;
   double new_lambda_           = 0.0;
index de4f57e..2983342 100644 (file)
@@ -84,12 +84,16 @@ bool LinkImpl::is_used() const
 
 LinkImpl* LinkImpl::set_sharing_policy(s4u::Link::SharingPolicy policy)
 {
-  get_constraint()->set_sharing_policy(policy);
+  lmm::Constraint::SharingPolicy ct_policy = lmm::Constraint::SharingPolicy::SHARED;
+  if (policy == s4u::Link::SharingPolicy::FATPIPE)
+    ct_policy = lmm::Constraint::SharingPolicy::FATPIPE;
+  get_constraint()->set_sharing_policy(ct_policy);
+  sharing_policy_ = policy;
   return this;
 }
 s4u::Link::SharingPolicy LinkImpl::get_sharing_policy() const
 {
-  return get_constraint()->get_sharing_policy();
+  return sharing_policy_;
 }
 
 void LinkImpl::latency_check(double latency) const
index 7905057..3917de1 100644 (file)
@@ -102,6 +102,7 @@ public:
  */
 class LinkImpl : public Resource_T<LinkImpl>, public xbt::PropertyHolder {
   s4u::Link piface_;
+  s4u::Link::SharingPolicy sharing_policy_ = s4u::Link::SharingPolicy::SHARED;
 
 protected:
   explicit LinkImpl(const std::string& name);