Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
In lmm_update_modified_set, don't visit variables twice.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Fri, 9 Dec 2011 15:45:13 +0000 (16:45 +0100)
committerNavarrop <Pierre.Navarro@imag.fr>
Fri, 6 Jan 2012 15:30:52 +0000 (16:30 +0100)
Note: the constraints may be ordered differently in
modified_constraint_set, and the timings may vary a bit.
If it is really important, the following patch fixes that:

--- a/src/surf/maxmin.c
+++ b/src/surf/maxmin.c
@@ -790,10 +790,8 @@ static void lmm_update_modified_set_rec(lmm_system_t sys,
     lmm_variable_t var = elem->variable;
     s_lmm_element_t *cnsts = var->cnsts;
     int i;
-    if (var->visited == sys->visited_counter)
-      continue;
-    var->visited = sys->visited_counter;
-    for (i = 0; i < var->cnsts_number; i++) {
+    for (i = 0; var->visited != sys->visited_counter
+                && i < var->cnsts_number ; i++) {
       if (cnsts[i].constraint != cnst
           && !xbt_swag_belongs(cnsts[i].constraint,
                                &sys->modified_constraint_set)) {
@@ -801,6 +799,7 @@ static void lmm_update_modified_set_rec(lmm_system_t sys,
         lmm_update_modified_set_rec(sys, cnsts[i].constraint);
       }
     }
+    var->visited = sys->visited_counter;
   }
 }

src/surf/maxmin.c
src/surf/maxmin_private.h

index 34fb128..ff65a88 100644 (file)
@@ -37,6 +37,7 @@ lmm_system_t lmm_system_new(int selective_update)
 
   l->modified = 0;
   l->selective_update_active = selective_update;
+  l->visited_counter = 1;
 
   XBT_DEBUG("Setting selective_update_active flag to %d\n",
          l->selective_update_active);
@@ -211,7 +212,7 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
   var->weight = weight;
   var->bound = bound;
   var->value = 0.0;
-
+  var->visited = sys->visited_counter - 1;
   var->mu = 0.0;
   var->new_mu = 0.0;
   var->func_f = func_f_def;
@@ -788,6 +789,9 @@ static void lmm_update_modified_set_rec(lmm_system_t sys,
     lmm_variable_t var = elem->variable;
     s_lmm_element_t *cnsts = var->cnsts;
     int i;
+    if (var->visited == sys->visited_counter)
+       continue;
+    var->visited = sys->visited_counter;
     for (i = 0; i < var->cnsts_number; i++) {
       if (cnsts[i].constraint != cnst
           && !xbt_swag_belongs(cnsts[i].constraint,
@@ -816,5 +820,11 @@ static void lmm_update_modified_set(lmm_system_t sys,
  */
 static void lmm_remove_all_modified_set(lmm_system_t sys)
 {
+  if (++sys->visited_counter == 1) {
+    /* the counter wrapped around, reset each variable->visited */
+    lmm_variable_t var;
+    xbt_swag_foreach(var, &sys->variable_set)
+      var->visited = 0;
+  }
   xbt_swag_reset(&sys->modified_constraint_set);
 }
index a20a796..4d1e379 100644 (file)
@@ -55,6 +55,7 @@ typedef struct lmm_variable {
   double value;
   void *id;
   int id_int;
+  unsigned visited;             /* used by lmm_update_modified_set */
   /* \begin{For Lagrange only} */
   double mu;
   double new_mu;
@@ -67,7 +68,7 @@ typedef struct lmm_variable {
 typedef struct lmm_system {
   int modified;
   int selective_update_active;  /* flag to update partially the system only selecting changed portions */
-
+  unsigned visited_counter;     /* used by lmm_update_modified_set */
   s_xbt_swag_t variable_set;    /* a list of lmm_variable_t */
   s_xbt_swag_t constraint_set;  /* a list of lmm_constraint_t */