From: Arnaud Giersch Date: Fri, 9 Dec 2011 15:45:13 +0000 (+0100) Subject: In lmm_update_modified_set, don't visit variables twice. X-Git-Tag: exp_20120216~185 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/251e40dfd575845209e8b4191b87064fb68556a9 In lmm_update_modified_set, don't visit variables twice. 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; } } --- diff --git a/src/surf/maxmin.c b/src/surf/maxmin.c index 34fb1289c1..ff65a88169 100644 --- a/src/surf/maxmin.c +++ b/src/surf/maxmin.c @@ -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); } diff --git a/src/surf/maxmin_private.h b/src/surf/maxmin_private.h index a20a7967aa..4d1e379107 100644 --- a/src/surf/maxmin_private.h +++ b/src/surf/maxmin_private.h @@ -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 */