Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename an option and improve its doc: maxmin/concurrency-limit
[simgrid.git] / src / surf / maxmin.cpp
index 05da403..dc0280b 100644 (file)
@@ -22,10 +22,11 @@ typedef struct s_dyn_light {
   int size;
 } s_dyn_light_t, *dyn_light_t;
 
-double sg_maxmin_precision = 0.00001;
-double sg_surf_precision   = 0.00001;
+double sg_maxmin_precision = 0.00001; /* Change this with --cfg=maxmin/precision:VALUE */
+double sg_surf_precision   = 0.00001; /* Change this with --cfg=surf/precision:VALUE */
+int sg_concurrency_limit   = -1;      /* Change this with --cfg=maxmin/concurrency-limit:VALUE */
 
-static void *lmm_variable_mallocator_new_f(void);
+static void *lmm_variable_mallocator_new_f();
 static void lmm_variable_mallocator_free_f(void *var);
 #define lmm_variable_mallocator_reset_f ((void_f_pvoid_t)nullptr)
 static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst);
@@ -73,7 +74,7 @@ inline void lmm_increase_concurrency(lmm_element_t elem) {
              "Concurrency limit overflow!");
 }
 
-lmm_system_t lmm_system_new(int selective_update)
+lmm_system_t lmm_system_new(bool selective_update)
 {
   lmm_system_t l = nullptr;
   s_lmm_variable_t var;
@@ -101,6 +102,8 @@ lmm_system_t lmm_system_new(int selective_update)
                                               lmm_variable_mallocator_free_f,
                                               lmm_variable_mallocator_reset_f);
 
+  l->solve_fun = &lmm_solve;
+
   return l;
 }
 
@@ -195,8 +198,7 @@ lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id, double bound_val
   cnst->bound = bound_value;
   cnst->concurrency_maximum=0;
   cnst->concurrency_current=0;
-  //TODO MARTIN Maybe a configuration item for the default cap concurrency? 
-  cnst->concurrency_limit=100;
+  cnst->concurrency_limit  = sg_concurrency_limit;
   cnst->usage = 0;
   cnst->sharing_policy = 1; /* FIXME: don't hardcode the value */
   insert_constraint(sys, cnst);
@@ -254,7 +256,7 @@ inline void lmm_constraint_free(lmm_system_t sys,lmm_constraint_t cnst)
   lmm_cnst_free(sys, cnst);
 }
 
-static void *lmm_variable_mallocator_new_f(void)
+static void *lmm_variable_mallocator_new_f()
 {
   lmm_variable_t var = xbt_new(s_lmm_variable_t, 1);
   var->cnsts = nullptr; /* will be created by realloc */
@@ -1051,23 +1053,20 @@ void lmm_disable_var(lmm_system_t sys, lmm_variable_t var){
  * And then add it to enabled variables
  */
 void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr){
-  lmm_element_t elem;
-  lmm_element_t nextelem;
-  int numelem;
 
   if(cnstr->concurrency_limit<0)
     return;
 
-  numelem=xbt_swag_size(&(cnstr->disabled_element_set));
+  int numelem = xbt_swag_size(&(cnstr->disabled_element_set));
   if(!numelem)
     return;
 
-  elem= (lmm_element_t) xbt_swag_getFirst(&(cnstr->disabled_element_set));
+  lmm_element_t elem = (lmm_element_t)xbt_swag_getFirst(&(cnstr->disabled_element_set));
 
   //Cannot use xbt_swag_foreach, because lmm_enable_var will modify disabled_element_set.. within the loop
-  while(numelem-- && elem ){
+  while (numelem-- && elem) {
 
-    nextelem = (lmm_element_t) xbt_swag_getNext(elem, cnstr->disabled_element_set.offset);      
+    lmm_element_t nextelem = (lmm_element_t)xbt_swag_getNext(elem, cnstr->disabled_element_set.offset);
 
     if (elem->variable->staged_weight>0 ){
       //Found a staged variable
@@ -1096,7 +1095,6 @@ void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr){
  */
 void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double weight)
 {
-  int minslack;
 
   xbt_assert(weight>=0,"Variable weight should not be negative!");
 
@@ -1113,8 +1111,8 @@ void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double wei
   //Are we enabling this variable?
   if (enabling_var){
     var->staged_weight = weight;
-    minslack=lmm_cnstrs_min_concurrency_slack(var);
-    if(minslack<var->concurrency_share){      
+    int minslack       = lmm_cnstrs_min_concurrency_slack(var);
+    if (minslack < var->concurrency_share) {
       XBT_DEBUG("Staging var (instead of enabling) because min concurrency slack %i, with weight %f and concurrency"
                 " share %i", minslack, weight, var->concurrency_share);
       return;
@@ -1131,7 +1129,6 @@ void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double wei
   lmm_check_concurrency(sys);
 
   XBT_OUT();
-  return;
 }
 
 double lmm_get_variable_weight(lmm_variable_t var)
@@ -1220,25 +1217,28 @@ static void lmm_remove_all_modified_set(lmm_system_t sys)
 }
 
 /**
- *  Returns total resource load
+ *  Returns resource load (in flop per second, or byte per second, or similar)
  *
- * \param cnst the lmm_constraint_t associated to the resource
+ *  If the resource is shared (the default case), the load is sum of
+ *  resource usage made by every variables located on this resource.
  *
- * This is dead code, but we may use it later for debug/trace.
+ * If the resource is not shared (ie in FATPIPE mode), then the the
+ * load is the max (not the sum) of all resource usages located on this resource.
+ * .
+ * \param cnst the lmm_constraint_t associated to the resource
  */
 double lmm_constraint_get_usage(lmm_constraint_t cnst) {
    double usage = 0.0;
    xbt_swag_t elem_list = &(cnst->enabled_element_set);
    void *_elem;
-   lmm_element_t elem = nullptr;
 
    xbt_swag_foreach(_elem, elem_list) {
-   elem = (lmm_element_t)_elem;
-     if ((elem->value > 0)) {
+     lmm_element_t elem = (lmm_element_t)_elem;
+     if (elem->value > 0) {
        if (cnst->sharing_policy)
          usage += elem->value * elem->variable->value;
        else if (usage < elem->value * elem->variable->value)
-         usage = elem->value * elem->variable->value;
+         usage = std::max(usage, elem->value * elem->variable->value);
      }
    }
   return usage;