Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make s_lmm_constraint_t a class with its methods.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 22 Nov 2017 22:40:09 +0000 (23:40 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 26 Nov 2017 15:15:25 +0000 (16:15 +0100)
13 files changed:
src/include/surf/maxmin.hpp
src/s4u/s4u_link.cpp
src/surf/HostImpl.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_interface.cpp
src/surf/maxmin.cpp
src/surf/maxmin_private.hpp
src/surf/network_cm02.cpp
src/surf/network_interface.cpp
src/surf/plugins/host_energy.cpp
src/surf/plugins/host_load.cpp
src/surf/ptask_L07.cpp
teshsuite/surf/maxmin_bench/maxmin_bench.cpp

index d2aad09..e5e896b 100644 (file)
@@ -149,56 +149,6 @@ static inline int double_equals(double value1, double value2, double precision)
 
 /** @{ @ingroup SURF_lmm */
 
-/**
- * @brief Share a constraint
- * @param cnst The constraint to share
- */
-XBT_PUBLIC(void) lmm_constraint_shared(lmm_constraint_t cnst);
-
-/**
- * @brief Check if a constraint is shared (shared by default)
- * @param cnst The constraint to share
- * @return 1 if shared, 0 otherwise
- */
-XBT_PUBLIC(int) lmm_constraint_sharing_policy(lmm_constraint_t cnst);
-
-/**
- * @brief Get the usage of the constraint after the last lmm solve
- * @param cnst A constraint
- * @return The usage of the constraint
- */
-XBT_PUBLIC(double) lmm_constraint_get_usage(lmm_constraint_t cnst);
-
-XBT_PUBLIC(int) lmm_constraint_get_variable_amount(lmm_constraint_t cnst);
-
-/**
- * @brief Sets the concurrency limit for this constraint
- * @param cnst A constraint
- * @param concurrency_limit The concurrency limit to use for this constraint
- */
-XBT_PUBLIC(void) lmm_constraint_concurrency_limit_set(lmm_constraint_t cnst, int concurrency_limit);
-
-/**
- * @brief Gets the concurrency limit for this constraint
- * @param cnst A constraint
- * @return The concurrency limit used by this constraint
- */
-XBT_PUBLIC(int) lmm_constraint_concurrency_limit_get(lmm_constraint_t cnst);
-
-/**
- * @brief Reset the concurrency maximum for a given variable (we will update the maximum to reflect constraint
- * evolution).
- * @param cnst A constraint
-*/
-XBT_PUBLIC(void) lmm_constraint_concurrency_maximum_reset(lmm_constraint_t cnst);
-
-/**
- * @brief Get the concurrency maximum for a given variable (which reflects constraint evolution).
- * @param cnst A constraint
- * @return the maximum concurrency of the constraint
- */
-XBT_PUBLIC(int) lmm_constraint_concurrency_maximum_get(lmm_constraint_t cnst);
-
 /**
  * @brief Get the value of the variable after the last lmm solve
  * @param var A variable
@@ -246,37 +196,6 @@ XBT_PUBLIC(double) lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t
  */
 XBT_PUBLIC(int) lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var);
 
-/**
- * @brief Get a var associated to a constraint
- * @details Get the first variable of the next variable of elem if elem is not NULL
- * @param sys The system associated to the variable (not used)
- * @param cnst A constraint
- * @param elem A element of constraint of the constraint or NULL
- * @return A variable associated to a constraint
- */
-XBT_PUBLIC(lmm_variable_t) lmm_get_var_from_cnst(lmm_system_t sys, lmm_constraint_t cnst, lmm_element_t* elem);
-
-/**
- * @brief Get a var associated to a constraint
- * @details Get the first variable of the next variable of elem if elem is not NULL
- * @param cnst A constraint
- * @param elem A element of constraint of the constraint or NULL
- * @param nextelem A element of constraint of the constraint or NULL, the one after elem
- * @param numelem parameter representing the number of elements to go
- *
- * @return A variable associated to a constraint
- */
-XBT_PUBLIC(lmm_variable_t)
-lmm_get_var_from_cnst_safe(lmm_system_t sys, lmm_constraint_t cnst, lmm_element_t* elem, lmm_element_t* nextelem,
-                           int* numelem);
-
-/**
- * @brief Get the data associated to a constraint
- * @param cnst A constraint
- * @return The data associated to the constraint
- */
-XBT_PUBLIC(void*) lmm_constraint_id(lmm_constraint_t cnst);
-
 /**
  * @brief Get the data associated to a variable
  * @param var A variable
index 7a38166..c374d07 100644 (file)
@@ -8,6 +8,7 @@
 #include "simgrid/s4u/Link.hpp"
 #include "simgrid/sg_config.h"
 #include "simgrid/simix.hpp"
+#include "src/surf/maxmin_private.hpp"
 #include "src/surf/network_interface.hpp"
 #include "xbt/log.h"
 
@@ -116,7 +117,7 @@ int Link::sharingPolicy()
 
 double Link::getUsage()
 {
-  return lmm_constraint_get_usage(this->pimpl_->constraint());
+  return this->pimpl_->constraint()->get_usage();
 }
 
 void Link::turnOn()
index 97bd943..2a24cc6 100644 (file)
@@ -30,7 +30,7 @@ void HostModel::ignoreEmptyVmInPmLMM()
   /* iterate for all virtual machines */
   for (s4u::VirtualMachine* const& ws_vm : vm::VirtualMachineImpl::allVms_) {
     Cpu* cpu = ws_vm->pimpl_cpu;
-    int active_tasks = lmm_constraint_get_variable_amount(cpu->constraint());
+    int active_tasks = cpu->constraint()->get_variable_amount();
 
     /* The impact of the VM over its PM is the min between its vCPU amount and the amount of tasks it contains */
     int impact = std::min(active_tasks, ws_vm->pimpl_vm_->coreAmount());
index c25b816..69a16b3 100644 (file)
@@ -107,7 +107,7 @@ void CpuCas01::onSpeedChange() {
   lmm_element_t elem = nullptr;
 
   model()->getMaxminSystem()->update_constraint_bound(constraint(), coresAmount_ * speed_.scale * speed_.peak);
-  while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), constraint(), &elem))) {
+  while ((var = constraint()->get_variable(&elem))) {
     CpuCas01Action* action = static_cast<CpuCas01Action*>(lmm_variable_id(var));
 
     model()->getMaxminSystem()->update_variable_bound(action->getVariable(),
@@ -143,7 +143,7 @@ void CpuCas01::apply_event(tmgr_trace_event_t event, double value)
 
       turnOff();
 
-      while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), cnst, &elem))) {
+      while ((var = cnst->get_variable(&elem))) {
         Action *action = static_cast<Action*>(lmm_variable_id(var));
 
         if (action->getState() == Action::State::running ||
index 2c4e308..4ef732c 100644 (file)
@@ -28,7 +28,7 @@ void CpuModel::updateActionsStateLazy(double now, double /*delta*/)
     CpuAction* action = static_cast<CpuAction*>(actionHeapPop());
     XBT_CDEBUG(surf_kernel, "Something happened to action %p", action);
     if (TRACE_is_enabled()) {
-      Cpu *cpu = static_cast<Cpu*>(lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action->getVariable(), 0)));
+      Cpu* cpu = static_cast<Cpu*>(lmm_get_cnst_from_var(getMaxminSystem(), action->getVariable(), 0)->get_id());
       TRACE_surf_host_set_utilization(cpu->getCname(), action->getCategory(),
                                       lmm_variable_getvalue(action->getVariable()), action->getLastUpdate(),
                                       now - action->getLastUpdate());
@@ -60,9 +60,7 @@ void CpuModel::updateActionsStateFull(double now, double delta)
     CpuAction& action = static_cast<CpuAction&>(*it);
     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
     if (TRACE_is_enabled()) {
-      Cpu* cpu =
-          static_cast<Cpu*>(lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action.getVariable(), 0)));
-
+      Cpu* cpu = static_cast<Cpu*>(lmm_get_cnst_from_var(getMaxminSystem(), action.getVariable(), 0)->get_id());
       TRACE_surf_host_set_utilization(cpu->getCname(), action.getCategory(),
                                       lmm_variable_getvalue(action.getVariable()), now - delta, delta);
       TRACE_last_timestamp_to_dump = now - delta;
@@ -190,7 +188,7 @@ void CpuAction::updateRemainingLazy(double now)
     updateRemains(getLastValue() * delta);
 
     if (TRACE_is_enabled()) {
-      Cpu *cpu = static_cast<Cpu*>(lmm_constraint_id(lmm_get_cnst_from_var(getModel()->getMaxminSystem(), getVariable(), 0)));
+      Cpu* cpu = static_cast<Cpu*>(lmm_get_cnst_from_var(getModel()->getMaxminSystem(), getVariable(), 0)->get_id());
       TRACE_surf_host_set_utilization(cpu->getCname(), getCategory(), getLastValue(), getLastUpdate(),
                                       now - getLastUpdate());
     }
@@ -229,7 +227,7 @@ std::list<Cpu*> CpuAction::cpus() {
   for (int i = 0; i < llen; i++) {
     /* Beware of composite actions: ptasks put links and cpus together */
     // extra pb: we cannot dynamic_cast from void*...
-    Resource* resource = static_cast<Resource*>(lmm_constraint_id(lmm_get_cnst_from_var(sys, getVariable(), i)));
+    Resource* resource = static_cast<Resource*>(lmm_get_cnst_from_var(sys, getVariable(), i)->get_id());
     Cpu* cpu           = dynamic_cast<Cpu*>(resource);
     if (cpu != nullptr)
       retlist.push_back(cpu);
index f76a376..703762a 100644 (file)
@@ -26,10 +26,9 @@ double sg_surf_precision   = 0.00001; /* Change this with --cfg=surf/precision:V
 int sg_concurrency_limit   = -1;      /* Change this with --cfg=maxmin/concurrency-limit:VALUE */
 
 static int Global_debug_id = 1;
-static int Global_const_debug_id = 1;
+int s_lmm_constraint_t::Global_debug_id = 1;
 
 static int lmm_can_enable_var(lmm_variable_t var);
-static int lmm_concurrency_slack(lmm_constraint_t cnstr);
 static int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var);
 
 static inline int lmm_element_concurrency(lmm_element_t elem)
@@ -59,7 +58,7 @@ static inline void lmm_increase_concurrency(lmm_element_t elem)
   if(cnstr->concurrency_current > cnstr->concurrency_maximum)
     cnstr->concurrency_maximum= cnstr->concurrency_current;
 
-  xbt_assert(cnstr->concurrency_limit<0 || cnstr->concurrency_current<=cnstr->concurrency_limit,
+  xbt_assert(cnstr->get_concurrency_limit() < 0 || cnstr->concurrency_current <= cnstr->get_concurrency_limit(),
              "Concurrency limit overflow!");
 }
 
@@ -86,12 +85,13 @@ void s_lmm_system_t::check_concurrency()
     {
       lmm_element_t elem = (lmm_element_t)elemIt;
       // We should have staged variables only if concurrency is reached in some constraint
-      xbt_assert(cnst->concurrency_limit < 0 || elem->variable->staged_weight == 0 ||
+      xbt_assert(cnst->get_concurrency_limit() < 0 || elem->variable->staged_weight == 0 ||
                      lmm_cnstrs_min_concurrency_slack(elem->variable) < elem->variable->concurrency_share,
                  "should not have staged variable!");
     }
 
-    xbt_assert(cnst->concurrency_limit < 0 || cnst->concurrency_limit >= concurrency, "concurrency check failed!");
+    xbt_assert(cnst->get_concurrency_limit() < 0 || cnst->get_concurrency_limit() >= concurrency,
+               "concurrency check failed!");
     xbt_assert(cnst->concurrency_current == concurrency, "concurrency_current is out-of-date!");
   }
 
@@ -201,63 +201,34 @@ void s_lmm_system_t::cnst_free(lmm_constraint_t cnst)
   delete cnst;
 }
 
-lmm_constraint_t s_lmm_system_t::constraint_new(void* id, double bound_value)
+s_lmm_constraint_t::s_lmm_constraint_t(void* id_value, double bound_value)
 {
-  lmm_constraint_t cnst = nullptr;
   s_lmm_element_t elem;
 
-  cnst         = new s_lmm_constraint_t();
-  cnst->id     = id;
-  cnst->id_int = Global_const_debug_id++;
-  xbt_swag_init(&(cnst->enabled_element_set), xbt_swag_offset(elem, enabled_element_set_hookup));
-  xbt_swag_init(&(cnst->disabled_element_set), xbt_swag_offset(elem, disabled_element_set_hookup));
-  xbt_swag_init(&(cnst->active_element_set), xbt_swag_offset(elem, active_element_set_hookup));
-
-  cnst->bound = bound_value;
-  cnst->concurrency_maximum=0;
-  cnst->concurrency_current=0;
-  cnst->concurrency_limit  = sg_concurrency_limit;
-  cnst->usage = 0;
-  cnst->sharing_policy = 1; /* FIXME: don't hardcode the value */
-  insert_constraint(cnst);
-
-  return cnst;
-}
-
-int lmm_constraint_concurrency_limit_get(lmm_constraint_t cnst)
-{
- return cnst->concurrency_limit;
-}
-
-void lmm_constraint_concurrency_limit_set(lmm_constraint_t cnst, int concurrency_limit)
-{
-  xbt_assert(concurrency_limit<0 || cnst->concurrency_maximum<=concurrency_limit,
-             "New concurrency limit should be larger than observed concurrency maximum. Maybe you want to call"
-             " lmm_constraint_concurrency_maximum_reset() to reset the maximum?");
-  cnst->concurrency_limit = concurrency_limit;
-}
-
-void lmm_constraint_concurrency_maximum_reset(lmm_constraint_t cnst)
-{
-  cnst->concurrency_maximum = 0;
-}
-
-int lmm_constraint_concurrency_maximum_get(lmm_constraint_t cnst)
-{
- xbt_assert(cnst->concurrency_limit<0 || cnst->concurrency_maximum<=cnst->concurrency_limit,
-            "Very bad: maximum observed concurrency is higher than limit. This is a bug of SURF, please report it.");
-  return cnst->concurrency_maximum;
-}
-
-void lmm_constraint_shared(lmm_constraint_t cnst)
-{
-  cnst->sharing_policy = 0;
+  id     = id_value;
+  id_int = Global_debug_id++;
+  xbt_swag_init(&enabled_element_set, xbt_swag_offset(elem, enabled_element_set_hookup));
+  xbt_swag_init(&disabled_element_set, xbt_swag_offset(elem, disabled_element_set_hookup));
+  xbt_swag_init(&active_element_set, xbt_swag_offset(elem, active_element_set_hookup));
+
+  remaining           = 0.0;
+  usage               = 0.0;
+  bound               = bound_value;
+  concurrency_limit   = sg_concurrency_limit;
+  concurrency_current = 0;
+  concurrency_maximum = 0;
+  sharing_policy      = 1; /* FIXME: don't hardcode the value */
+
+  lambda     = 0.0;
+  new_lambda = 0.0;
+  cnst_light = nullptr;
 }
 
-/** Return true if the constraint is shared, and false if it's FATPIPE */
-int lmm_constraint_sharing_policy(lmm_constraint_t cnst)
+lmm_constraint_t s_lmm_system_t::constraint_new(void* id, double bound_value)
 {
-  return (cnst->sharing_policy);
+  lmm_constraint_t cnst = new s_lmm_constraint_t(id, bound_value);
+  insert_constraint(cnst);
+  return cnst;
 }
 
 void* s_lmm_system_t::variable_mallocator_new_f()
@@ -341,7 +312,7 @@ void s_lmm_system_t::expand(lmm_constraint_t cnst, lmm_variable_t var, double co
   }
 
   //Check if we need to disable the variable
-  if (var->sharing_weight > 0 && var->concurrency_share - current_share > lmm_concurrency_slack(cnst)) {
+  if (var->sharing_weight > 0 && var->concurrency_share - current_share > cnst->get_concurrency_slack()) {
     double weight = var->sharing_weight;
     disable_var(var);
     for (s_lmm_element_t const& elem : var->cnsts)
@@ -400,7 +371,7 @@ void s_lmm_system_t::expand_add(lmm_constraint_t cnst, lmm_variable_t var, doubl
 
     //We need to check that increasing value of the element does not cross the concurrency limit
     if (var->sharing_weight) {
-      if (lmm_concurrency_slack(cnst) < lmm_element_concurrency(&elem)) {
+      if (cnst->get_concurrency_slack() < lmm_element_concurrency(&elem)) {
         double weight = var->sharing_weight;
         disable_var(var);
         for (s_lmm_element_t const& elem2 : var->cnsts)
@@ -438,23 +409,23 @@ int lmm_get_number_of_cnst_from_var(lmm_system_t /*sys*/, lmm_variable_t var)
   return (var->cnsts.size());
 }
 
-lmm_variable_t lmm_get_var_from_cnst(lmm_system_t /*sys*/, lmm_constraint_t cnst, lmm_element_t * elem)
+lmm_variable_t s_lmm_constraint_t::get_variable(lmm_element_t* elem) const
 {
   if (*elem == nullptr) {
     // That is the first call, pick the first element among enabled_element_set (or disabled_element_set if
     // enabled_element_set is empty)
-    *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->enabled_element_set));
+    *elem = (lmm_element_t)xbt_swag_getFirst(&enabled_element_set);
     if (*elem == nullptr)
-      *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
+      *elem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set);
   } else {
     //elem is not null, so we carry on
-    if(xbt_swag_belongs(*elem,&(cnst->enabled_element_set))){
+    if (xbt_swag_belongs(*elem, &enabled_element_set)) {
       //Look at enabled_element_set, and jump to disabled_element_set when finished
-      *elem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->enabled_element_set.offset);
+      *elem = (lmm_element_t)xbt_swag_getNext(*elem, enabled_element_set.offset);
       if (*elem == nullptr)
-        *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
+        *elem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set);
     } else {
-      *elem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->disabled_element_set.offset);
+      *elem = (lmm_element_t)xbt_swag_getNext(*elem, disabled_element_set.offset);
     }
   }
   if (*elem)
@@ -465,14 +436,13 @@ lmm_variable_t lmm_get_var_from_cnst(lmm_system_t /*sys*/, lmm_constraint_t cnst
 
 //if we modify the swag between calls, normal version may loop forever
 //this safe version ensures that we browse the swag elements only once
-lmm_variable_t lmm_get_var_from_cnst_safe(lmm_system_t /*sys*/, lmm_constraint_t cnst, lmm_element_t * elem,
-                                          lmm_element_t * nextelem, int * numelem)
+lmm_variable_t s_lmm_constraint_t::get_variable_safe(lmm_element_t* elem, lmm_element_t* nextelem, int* numelem) const
 {
   if (*elem == nullptr) {
-    *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->enabled_element_set));
-    *numelem = xbt_swag_size(&(cnst->enabled_element_set))+xbt_swag_size(&(cnst->disabled_element_set))-1;
+    *elem    = (lmm_element_t)xbt_swag_getFirst(&enabled_element_set);
+    *numelem = xbt_swag_size(&enabled_element_set) + xbt_swag_size(&disabled_element_set) - 1;
     if (*elem == nullptr)
-      *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
+      *elem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set);
   }else{
     *elem = *nextelem;
     if(*numelem>0){
@@ -482,24 +452,19 @@ lmm_variable_t lmm_get_var_from_cnst_safe(lmm_system_t /*sys*/, lmm_constraint_t
   }
   if (*elem){
     //elem is not null, so we carry on
-    if(xbt_swag_belongs(*elem,&(cnst->enabled_element_set))){
+    if (xbt_swag_belongs(*elem, &enabled_element_set)) {
       //Look at enabled_element_set, and jump to disabled_element_set when finished
-      *nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->enabled_element_set.offset);
+      *nextelem = (lmm_element_t)xbt_swag_getNext(*elem, enabled_element_set.offset);
       if (*nextelem == nullptr)
-        *nextelem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
+        *nextelem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set);
     } else {
-      *nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->disabled_element_set.offset);
+      *nextelem = (lmm_element_t)xbt_swag_getNext(*elem, disabled_element_set.offset);
     }
     return (*elem)->variable;
   }else
     return nullptr;
 }
 
-void *lmm_constraint_id(lmm_constraint_t cnst)
-{
-  return cnst->id;
-}
-
 void *lmm_variable_id(lmm_variable_t var)
 {
   return var->id;
@@ -669,7 +634,7 @@ void s_lmm_system_t::solve()
       }
     }
     XBT_DEBUG("Constraint '%d' usage: %f remaining: %f concurrency: %i<=%i<=%i", cnst->id_int, cnst->usage,
-              cnst->remaining,cnst->concurrency_current,cnst->concurrency_maximum,cnst->concurrency_limit);
+              cnst->remaining, cnst->concurrency_current, cnst->concurrency_maximum, cnst->get_concurrency_limit());
     /* Saturated constraints update */
 
     if(cnst->usage > 0) {
@@ -843,19 +808,12 @@ void s_lmm_system_t::update_variable_bound(lmm_variable_t var, double bound)
     update_modified_set(var->cnsts[0].constraint);
 }
 
-int lmm_concurrency_slack(lmm_constraint_t cnstr)
-{
-  if (cnstr->concurrency_limit < 0)
-    return std::numeric_limits<int>::max();
-  return  cnstr->concurrency_limit - cnstr->concurrency_current;
-}
-
 /** \brief Measure the minimum concurrency slack across all constraints where the given var is involved */
 int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var)
 {
   int minslack = std::numeric_limits<int>::max();
   for (s_lmm_element_t const& elem : var->cnsts) {
-    int slack = lmm_concurrency_slack(elem.constraint);
+    int slack = elem.constraint->get_concurrency_slack();
     if (slack < minslack) {
       // This is only an optimization, to avoid looking at more constraints when slack is already zero
       if (slack == 0)
@@ -936,7 +894,7 @@ void s_lmm_system_t::disable_var(lmm_variable_t var)
  */
 void s_lmm_system_t::on_disabled_var(lmm_constraint_t cnstr)
 {
-  if(cnstr->concurrency_limit<0)
+  if (cnstr->get_concurrency_limit() < 0)
     return;
 
   int numelem = xbt_swag_size(&(cnstr->disabled_element_set));
@@ -957,8 +915,8 @@ void s_lmm_system_t::on_disabled_var(lmm_constraint_t cnstr)
       enable_var(elem->variable);
     }
 
-    xbt_assert(cnstr->concurrency_current<=cnstr->concurrency_limit,"Concurrency overflow!");
-    if(cnstr->concurrency_current==cnstr->concurrency_limit)
+    xbt_assert(cnstr->concurrency_current <= cnstr->get_concurrency_limit(), "Concurrency overflow!");
+    if (cnstr->concurrency_current == cnstr->get_concurrency_limit())
       break;
 
     elem = nextelem;
@@ -1085,16 +1043,17 @@ void s_lmm_system_t::remove_all_modified_set()
  *
  * \param cnst the lmm_constraint_t associated to the resource
  */
-double lmm_constraint_get_usage(lmm_constraint_t cnst) {
+double s_lmm_constraint_t::get_usage() const
+{
   double usage         = 0.0;
-  xbt_swag_t elem_list = &(cnst->enabled_element_set);
+  const_xbt_swag_t elem_list = &enabled_element_set;
   void* _elem;
 
   xbt_swag_foreach(_elem, elem_list)
   {
     lmm_element_t elem = (lmm_element_t)_elem;
     if (elem->consumption_weight > 0) {
-      if (cnst->sharing_policy)
+      if (sharing_policy)
         usage += elem->consumption_weight * elem->variable->value;
       else if (usage < elem->consumption_weight * elem->variable->value)
         usage = std::max(usage, elem->consumption_weight * elem->variable->value);
@@ -1103,9 +1062,10 @@ double lmm_constraint_get_usage(lmm_constraint_t cnst) {
   return usage;
 }
 
-int lmm_constraint_get_variable_amount(lmm_constraint_t cnst) {
+int s_lmm_constraint_t::get_variable_amount() const
+{
   int usage = 0;
-  xbt_swag_t elem_list = &(cnst->enabled_element_set);
+  const_xbt_swag_t elem_list = &enabled_element_set;
   void *_elem;
 
   xbt_swag_foreach(_elem, elem_list) {
index 581e424..72dbf37 100644 (file)
@@ -49,30 +49,117 @@ struct s_lmm_constraint_light_t {
  * \li Active elements which variable's weight is non-zero (i.e. it is enabled) AND its element value is non-zero. LMM_solve iterates over active elements during resolution, dynamically making them active or unactive.
  *
  */
-struct s_lmm_constraint_t {
-  /* hookup to system */
-  s_xbt_swag_hookup_t constraint_set_hookup;
-  s_xbt_swag_hookup_t active_constraint_set_hookup;
-  s_xbt_swag_hookup_t modified_constraint_set_hookup;
-  s_xbt_swag_hookup_t saturated_constraint_set_hookup;
+class s_lmm_constraint_t {
+public:
+  s_lmm_constraint_t() = default;
+  s_lmm_constraint_t(void* id_value, double bound_value);
+
+  /** @brief Share a constraint. FIXME: name is misleading */
+  void shared() { sharing_policy = 0; }
+
+  /**
+   * @brief Check if a constraint is shared (shared by default)
+   * @return 1 if shared, 0 otherwise
+   */
+  int get_sharing_policy() const { return sharing_policy; }
+
+  /**
+   * @brief Get the usage of the constraint after the last lmm solve
+   * @return The usage of the constraint
+   */
+  double get_usage() const;
+  int get_variable_amount() const;
+
+  /**
+   * @brief Sets the concurrency limit for this constraint
+   * @param concurrency_limit The concurrency limit to use for this constraint
+   */
+  void set_concurrency_limit(int limit)
+  {
+    xbt_assert(limit < 0 || concurrency_maximum <= limit,
+               "New concurrency limit should be larger than observed concurrency maximum. Maybe you want to call"
+               " concurrency_maximum_reset() to reset the maximum?");
+    concurrency_limit = limit;
+  }
+
+  /**
+   * @brief Gets the concurrency limit for this constraint
+   * @return The concurrency limit used by this constraint
+   */
+  int get_concurrency_limit() const { return concurrency_limit; }
+
+  /**
+   * @brief Reset the concurrency maximum for a given variable (we will update the maximum to reflect constraint
+   * evolution).
+   */
+  void reset_concurrency_maximum() { concurrency_maximum = 0; }
 
+  /**
+   * @brief Get the concurrency maximum for a given variable (which reflects constraint evolution).
+   * @return the maximum concurrency of the constraint
+   */
+  int get_concurrency_maximum() const
+  {
+    xbt_assert(concurrency_limit < 0 || concurrency_maximum <= concurrency_limit,
+               "Very bad: maximum observed concurrency is higher than limit. This is a bug of SURF, please report it.");
+    return concurrency_maximum;
+  }
+
+  int get_concurrency_slack() const
+  {
+    return concurrency_limit < 0 ? std::numeric_limits<int>::max() : concurrency_limit - concurrency_current;
+  }
+
+  /**
+   * @brief Get a var associated to a constraint
+   * @details Get the first variable of the next variable of elem if elem is not NULL
+   * @param elem A element of constraint of the constraint or NULL
+   * @return A variable associated to a constraint
+   */
+  lmm_variable_t get_variable(lmm_element_t* elem) const;
+
+  /**
+   * @brief Get a var associated to a constraint
+   * @details Get the first variable of the next variable of elem if elem is not NULL
+   * @param elem A element of constraint of the constraint or NULL
+   * @param nextelem A element of constraint of the constraint or NULL, the one after elem
+   * @param numelem parameter representing the number of elements to go
+   * @return A variable associated to a constraint
+   */
+  lmm_variable_t get_variable_safe(lmm_element_t* elem, lmm_element_t* nextelem, int* numelem) const;
+
+  /**
+   * @brief Get the data associated to a constraint
+   * @return The data associated to the constraint
+   */
+  void* get_id() const { return id; }
+
+  /* hookup to system */
+  s_xbt_swag_hookup_t constraint_set_hookup           = {nullptr, nullptr};
+  s_xbt_swag_hookup_t active_constraint_set_hookup    = {nullptr, nullptr};
+  s_xbt_swag_hookup_t modified_constraint_set_hookup  = {nullptr, nullptr};
+  s_xbt_swag_hookup_t saturated_constraint_set_hookup = {nullptr, nullptr};
   s_xbt_swag_t enabled_element_set;     /* a list of lmm_element_t */
   s_xbt_swag_t disabled_element_set;     /* a list of lmm_element_t */
   s_xbt_swag_t active_element_set;      /* a list of lmm_element_t */
   double remaining;
   double usage;
   double bound;
-  int concurrency_limit; /* The maximum number of variables that may be enabled at any time (stage variables if necessary) */
   //TODO MARTIN Check maximum value across resources at the end of simulation and give a warning is more than e.g. 500
   int concurrency_current; /* The current concurrency */
   int concurrency_maximum; /* The maximum number of (enabled and disabled) variables associated to the constraint at any given time (essentially for tracing)*/
 
   int sharing_policy; /* see @e_surf_link_sharing_policy_t (0: FATPIPE, 1: SHARED, 2: FULLDUPLEX) */
-  void *id;
   int id_int;
   double lambda;
   double new_lambda;
   lmm_constraint_light_t cnst_light;
+
+private:
+  static int Global_debug_id;
+  int concurrency_limit; /* The maximum number of variables that may be enabled at any time (stage variables if
+                          * necessary) */
+  void* id;
 };
 
 /** @ingroup SURF_lmm
index 9cd804c..91bcb42 100644 (file)
@@ -180,7 +180,7 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
 
       for (int i = 0; i < n; i++){
         lmm_constraint_t constraint = lmm_get_cnst_from_var(maxminSystem_, action->getVariable(), i);
-        NetworkCm02Link *link = static_cast<NetworkCm02Link*>(lmm_constraint_id(constraint));
+        NetworkCm02Link* link       = static_cast<NetworkCm02Link*>(constraint->get_id());
         double value = lmm_variable_getvalue(action->getVariable())*
             lmm_get_cnst_weight_from_var(maxminSystem_, action->getVariable(), i);
         TRACE_surf_link_set_utilization(link->getCname(), action->getCategory(), value, action->getLastUpdate(),
@@ -231,7 +231,7 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta)
       for (int i = 0; i < n; i++) {
         lmm_constraint_t constraint = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i);
 
-        NetworkCm02Link* link = static_cast<NetworkCm02Link*>(lmm_constraint_id(constraint));
+        NetworkCm02Link* link = static_cast<NetworkCm02Link*>(constraint->get_id());
         TRACE_surf_link_set_utilization(link->getCname(), action.getCategory(),
                                         (lmm_variable_getvalue(action.getVariable()) *
                                          lmm_get_cnst_weight_from_var(maxminSystem_, action.getVariable(), i)),
@@ -358,7 +358,7 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model* model, const std::string& nam
   latency_.peak  = latency;
 
   if (policy == SURF_LINK_FATPIPE)
-    lmm_constraint_shared(constraint());
+    constraint()->shared();
 
   simgrid::s4u::Link::onCreation(this->piface_);
 }
@@ -383,7 +383,7 @@ void NetworkCm02Link::apply_event(tmgr_trace_event_t triggered, double value)
       double now = surf_get_clock();
 
       turnOff();
-      while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), constraint(), &elem))) {
+      while ((var = constraint()->get_variable(&elem))) {
         Action *action = static_cast<Action*>( lmm_variable_id(var) );
 
         if (action->getState() == Action::State::running ||
@@ -416,7 +416,7 @@ void NetworkCm02Link::setBandwidth(double value)
     lmm_element_t elem = nullptr;
     lmm_element_t nextelem = nullptr;
     int numelem = 0;
-    while ((var = lmm_get_var_from_cnst_safe(model()->getMaxminSystem(), constraint(), &elem, &nextelem, &numelem))) {
+    while ((var = constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
       NetworkCm02Action *action = static_cast<NetworkCm02Action*>(lmm_variable_id(var));
       action->weight_ += delta;
       if (not action->isSuspended())
@@ -435,7 +435,7 @@ void NetworkCm02Link::setLatency(double value)
 
   latency_.peak = value;
 
-  while ((var = lmm_get_var_from_cnst_safe(model()->getMaxminSystem(), constraint(), &elem, &nextelem, &numelem))) {
+  while ((var = constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
     NetworkCm02Action *action = static_cast<NetworkCm02Action*>(lmm_variable_id(var));
     action->latCurrent_ += delta;
     action->weight_ += delta;
index 7cbef8e..66e1e0b 100644 (file)
@@ -154,7 +154,7 @@ namespace simgrid {
 
     int LinkImpl::sharingPolicy()
     {
-      return lmm_constraint_sharing_policy(constraint());
+      return constraint()->get_sharing_policy();
     }
 
     void LinkImpl::turnOn()
@@ -208,7 +208,7 @@ namespace simgrid {
       for (int i = 0; i < llen; i++) {
         /* Beware of composite actions: ptasks put links and cpus together */
         // extra pb: we cannot dynamic_cast from void*...
-        Resource* resource = static_cast<Resource*>(lmm_constraint_id(lmm_get_cnst_from_var(sys, getVariable(), i)));
+        Resource* resource = static_cast<Resource*>(lmm_get_cnst_from_var(sys, getVariable(), i)->get_id());
         LinkImpl* link     = dynamic_cast<LinkImpl*>(resource);
         if (link != nullptr)
           retlist.push_back(link);
index 7b9c025..21853c6 100644 (file)
@@ -174,7 +174,7 @@ void HostEnergy::update()
       // We consider that the machine is then fully loaded. That's arbitrary but it avoids a NaN
       cpu_load = 1;
     else
-      cpu_load = lmm_constraint_get_usage(host->pimpl_cpu->constraint()) / current_speed;
+      cpu_load = host->pimpl_cpu->constraint()->get_usage() / current_speed;
 
     /** Divide by the number of cores here **/
     cpu_load /= host->pimpl_cpu->coreCount();
@@ -518,7 +518,7 @@ double sg_host_get_current_consumption(sg_host_t host)
 {
   xbt_assert(HostEnergy::EXTENSION_ID.valid(),
              "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
-  double cpu_load = lmm_constraint_get_usage(host->pimpl_cpu->constraint()) / host->getSpeed();
+  double cpu_load = host->pimpl_cpu->constraint()->get_usage() / host->getSpeed();
   return host->extension<HostEnergy>()->getCurrentWattsValue(cpu_load);
 }
 }
index 3d5a901..71e8bf0 100644 (file)
@@ -54,7 +54,7 @@ HostLoad::HostLoad(simgrid::s4u::Host* ptr)
     : host(ptr)
     , last_updated(surf_get_clock())
     , last_reset(surf_get_clock())
-    , current_flops(lmm_constraint_get_usage(host->pimpl_cpu->constraint()))
+    , current_flops(host->pimpl_cpu->constraint()->get_usage())
 {
 }
 
@@ -66,7 +66,7 @@ void HostLoad::update()
   if (last_updated < now) {
     /* Current flop per second computed by the cpu; current_flops = k * pstate_speed_in_flops, k \in {0, 1, ..., cores}
      * number of active cores */
-    current_flops = lmm_constraint_get_usage(host->pimpl_cpu->constraint());
+    current_flops = host->pimpl_cpu->constraint()->get_usage();
 
     /* flops == pstate_speed * cores_being_currently_used */
     computed_flops += (now - last_updated) * current_flops;
index 17b1366..57b4b5b 100644 (file)
@@ -128,7 +128,7 @@ void HostL07Model::updateActionsState(double /*now*/, double delta)
       lmm_constraint_t cnst = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i);
       while (cnst != nullptr) {
         i++;
-        void *constraint_id = lmm_constraint_id(cnst);
+        void* constraint_id = cnst->get_id();
         if (static_cast<simgrid::surf::Resource*>(constraint_id)->isOff()) {
           XBT_DEBUG("Action (%p) Failed!!", &action);
           action.finish(Action::State::failed);
@@ -262,7 +262,7 @@ LinkL07::LinkL07(NetworkL07Model* model, const std::string& name, double bandwid
   latency_.peak   = latency;
 
   if (policy == SURF_LINK_FATPIPE)
-    lmm_constraint_shared(constraint());
+    constraint()->shared();
 
   s4u::Link::onCreation(this->piface_);
 }
@@ -298,7 +298,7 @@ void CpuL07::onSpeedChange() {
   lmm_element_t elem = nullptr;
 
   model()->getMaxminSystem()->update_constraint_bound(constraint(), speed_.peak * speed_.scale);
-  while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), constraint(), &elem))) {
+  while ((var = constraint()->get_variable(&elem))) {
     Action* action = static_cast<Action*>(lmm_variable_id(var));
 
     model()->getMaxminSystem()->update_variable_bound(action->getVariable(), speed_.scale * speed_.peak);
@@ -368,7 +368,7 @@ void LinkL07::setLatency(double value)
   lmm_element_t elem = nullptr;
 
   latency_.peak = value;
-  while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), constraint(), &elem))) {
+  while ((var = constraint()->get_variable(&elem))) {
     action = static_cast<L07Action*>(lmm_variable_id(var));
     action->updateBound();
   }
index 5cd623b..df51dde 100644 (file)
@@ -56,7 +56,7 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi
       //Badly logarithmically random concurrency limit in [2^pw_base_limit+1,2^pw_base_limit+2^pw_max_limit]
       l=(1<<pw_base_limit)+(1<<int_random(pw_max_limit));
 
-    lmm_constraint_concurrency_limit_set(cnst[i],l );
+    cnst[i]->set_concurrency_limit(l);
   }
 
   for (int i = 0; i < nb_var; i++) {
@@ -88,14 +88,14 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi
     fprintf(stderr,"Max concurrency:\n");
     int l=0;
     for (int i = 0; i < nb_cnst; i++) {
-      int j=lmm_constraint_concurrency_maximum_get(cnst[i]);
-      int k=lmm_constraint_concurrency_limit_get(cnst[i]);
+      int j = cnst[i]->get_concurrency_maximum();
+      int k = cnst[i]->get_concurrency_limit();
       xbt_assert(k<0 || j<=k);
       if(j>l)
         l=j;
       fprintf(stderr,"(%i):%i/%i ",i,j,k);
-      lmm_constraint_concurrency_maximum_reset(cnst[i]);
-      xbt_assert(not lmm_constraint_concurrency_maximum_get(cnst[i]));
+      cnst[i]->reset_concurrency_maximum();
+      xbt_assert(not cnst[i]->get_concurrency_maximum());
       if(i%10==9)
         fprintf(stderr,"\n");
     }