Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more stringification/privatization
[simgrid.git] / src / surf / maxmin.cpp
index 0fafd62..72d2005 100644 (file)
@@ -9,18 +9,18 @@
 #include "xbt/log.h"
 #include "xbt/mallocator.h"
 #include "xbt/sysdep.h"
+#include <cmath>
+#include <cstdlib>
 #include <cxxabi.h>
 #include <limits>
-#include <math.h>
-#include <stdlib.h>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf, "Logging specific to SURF (maxmin)");
 
-typedef struct s_dyn_light {
+struct s_dyn_light_t {
   int *data;
   int pos;
   int size;
-} s_dyn_light_t;
+};
 typedef s_dyn_light_t* dyn_light_t;
 
 double sg_maxmin_precision = 0.00001; /* Change this with --cfg=maxmin/precision:VALUE */
@@ -298,7 +298,7 @@ int lmm_constraint_sharing_policy(lmm_constraint_t cnst)
 }
 
 /* @brief Remove a constraint
- * Currently this is dead code, but it is exposed in maxmin.h
+ * Currently this is dead code, but it is exposed in maxmin.hpp
  * Apparently, this call was designed assuming that constraint would no more have elements in it.
  * If not the case, assertion will fail, and you need to add calls e.g. to lmm_shrink before effectively removing it.
  */
@@ -333,7 +333,7 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, dou
   lmm_variable_t var = (lmm_variable_t)xbt_mallocator_get(sys->variable_mallocator);
   var->id = id;
   var->id_int = Global_debug_id++;
-  var->cnsts = (s_lmm_element_t *) xbt_realloc(var->cnsts, number_of_constraints * sizeof(s_lmm_element_t));
+  var->cnsts = static_cast<s_lmm_element_t*>(xbt_realloc(var->cnsts, number_of_constraints * sizeof(s_lmm_element_t)));
   for (int i = 0; i < number_of_constraints; i++) {
     var->cnsts[i].enabled_element_set_hookup.next = nullptr;
     var->cnsts[i].enabled_element_set_hookup.prev = nullptr;
@@ -767,7 +767,6 @@ void lmm_solve(lmm_system_t sys)
   xbt_swag_foreach(_cnst, cnst_list) {
     lmm_constraint_t cnst = (lmm_constraint_t)_cnst;
     xbt_swag_t elem_list  = &(cnst->enabled_element_set);
-    //XBT_DEBUG("Variable set : %d", xbt_swag_size(elem_list));
     xbt_swag_foreach(_elem, elem_list) {
       lmm_variable_t var = ((lmm_element_t)_elem)->variable;
       xbt_assert(var->sharing_weight > 0.0);
@@ -775,8 +774,8 @@ void lmm_solve(lmm_system_t sys)
     }
   }
 
-  s_lmm_constraint_light_t *cnst_light_tab =
-     (s_lmm_constraint_light_t *)xbt_malloc0(xbt_swag_size(cnst_list)*sizeof(s_lmm_constraint_light_t));
+  s_lmm_constraint_light_tcnst_light_tab =
+      static_cast<s_lmm_constraint_light_t*>(xbt_malloc0(xbt_swag_size(cnst_list) * sizeof(s_lmm_constraint_light_t)));
   int cnst_light_num = 0;
   dyn_light_t saturated_constraint_set = xbt_new0(s_dyn_light_t,1);
   saturated_constraint_set->size = 5;
@@ -852,7 +851,6 @@ void lmm_solve(lmm_system_t sys)
         //If no variable could reach its bound, deal iteratively the constraints usage ( at worst one constraint is
         // saturated at each cycle)
         var->value = min_usage / var->sharing_weight;
-        // XBT_DEBUG("Setting %p (%d) value to %f\n", var, var->id_int, var->value);
         XBT_DEBUG("Setting var (%d) value to %f\n", var->id_int, var->value);
       } else {
          //If there exist a variable that can reach its bound, only update it (and other with the same bound) for now.
@@ -884,9 +882,6 @@ void lmm_solve(lmm_system_t sys)
               int index = (cnst->cnst_light-cnst_light_tab);
               XBT_DEBUG("index: %d \t cnst_light_num: %d \t || usage: %f remaining: %f bound: %f  ",
                          index,cnst_light_num, cnst->usage, cnst->remaining, cnst->bound);
-              //XBT_DEBUG("index: %d \t cnst_light_num: %d \t || \t cnst: %p \t cnst->cnst_light: %p "
-              //          "\t cnst_light_tab: %p usage: %f remaining: %f bound: %f  ", index,cnst_light_num,
-              //          cnst, cnst->cnst_light, cnst_light_tab, cnst->usage, cnst->remaining, cnst->bound);
               cnst_light_tab[index]=cnst_light_tab[cnst_light_num-1];
               cnst_light_tab[index].cnst->cnst_light = &cnst_light_tab[index];
               cnst_light_num--;
@@ -1045,7 +1040,6 @@ void lmm_enable_var(lmm_system_t sys, lmm_variable_t var){
   //When used within lmm_on_disabled_var, we would get an assertion fail, because transiently there can be variables
   // that are staged and could be activated.
   //Anyway, caller functions all call lmm_check_concurrency() in the end.
-  //  lmm_check_concurrency(sys);
 }
 
 void lmm_disable_var(lmm_system_t sys, lmm_variable_t var){
@@ -1114,7 +1108,6 @@ void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr){
   //We could get an assertion fail, because transiently there can be variables that are staged and could be activated.
   //And we need to go through all constraints of the disabled var before getting back a coherent state.
   //Anyway, caller functions all call lmm_check_concurrency() in the end.
-  //  lmm_check_concurrency(sys);
 }
 
 /* \brief update the weight of a variable, and enable/disable it.
@@ -1228,11 +1221,11 @@ static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst)
  */
 static void lmm_remove_all_modified_set(lmm_system_t sys)
 {
-  //We cleverly un-flag all variables just by incrementing sys->visited_counter
-  //In effect, the var->visited value will no more be equal to sys->visited counter
-  //To be clean, when visited counter has wrapped around, we force these var->visited values so that variables that
-  //were in the modified a long (long long) time ago are not wrongly skipped here, which would lead to very nasty bugs
-  //(i.e. not readibily reproducible, and requiring a lot of run time before happening).
+  // We cleverly un-flag all variables just by incrementing sys->visited_counter
+  // In effect, the var->visited value will no more be equal to sys->visited counter
+  // To be clean, when visited counter has wrapped around, we force these var->visited values so that variables that
+  // were in the modified a long long time ago are not wrongly skipped here, which would lead to very nasty bugs
+  // (i.e. not readibily reproducible, and requiring a lot of run time before happening).
   if (++sys->visited_counter == 1) {
     /* the counter wrapped around, reset each variable->visited */
   void *_var;