X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/daf533bcb25008af1fe9992c3a924121e56a8328..05cd623b7418a3a9f6f6a1f61e2a02251042762a:/src/surf/maxmin.c diff --git a/src/surf/maxmin.c b/src/surf/maxmin.c index 014457ba6b..e9f635de1c 100644 --- a/src/surf/maxmin.c +++ b/src/surf/maxmin.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2004-2011. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -15,20 +15,24 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf, "Logging specific to SURF (maxmin)"); +typedef struct s_dyn_light { + int *data; + int pos; + int size; +} s_dyn_light_t, *dyn_light_t; + double sg_maxmin_precision = 0.00001; static void *lmm_variable_mallocator_new_f(void); static void lmm_variable_mallocator_free_f(void *var); -static void lmm_variable_mallocator_reset_f(void *var); +#define lmm_variable_mallocator_reset_f ((void_f_pvoid_t)NULL) 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); -int sg_maxmin_selective_update = 1; static int Global_debug_id = 1; static int Global_const_debug_id = 1; -extern xbt_swag_t keep_track; -lmm_system_t lmm_system_new(void) +lmm_system_t lmm_system_new(int selective_update) { lmm_system_t l = NULL; s_lmm_variable_t var; @@ -37,9 +41,10 @@ lmm_system_t lmm_system_new(void) l = xbt_new0(s_lmm_system_t, 1); l->modified = 0; - l->selective_update_active = sg_maxmin_selective_update; + l->selective_update_active = selective_update; + l->visited_counter = 1; - DEBUG1("Setting selective_update_active flag to %d\n", + XBT_DEBUG("Setting selective_update_active flag to %d\n", l->selective_update_active); xbt_swag_init(&(l->variable_set), @@ -71,7 +76,7 @@ void lmm_system_free(lmm_system_t sys) lmm_constraint_t cnst = NULL; while ((var = extract_variable(sys))) { - WARN2 + XBT_WARN ("Variable %p (%d) still in LMM system when freing it: this may be a bug", var, var->id_int); lmm_var_free(sys, var); @@ -87,22 +92,33 @@ void lmm_system_free(lmm_system_t sys) XBT_INLINE void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var) { int i; + int n; + lmm_element_t elem = NULL; - XBT_IN2("(sys=%p, var=%p)", sys, var); + XBT_IN("(sys=%p, var=%p)", sys, var); sys->modified = 1; + n = 0; for (i = 0; i < var->cnsts_number; i++) { elem = &var->cnsts[i]; xbt_swag_remove(elem, &(elem->constraint->element_set)); xbt_swag_remove(elem, &(elem->constraint->active_element_set)); if (!xbt_swag_size(&(elem->constraint->element_set))) make_constraint_inactive(sys, elem->constraint); - else - lmm_update_modified_set(sys, elem->constraint); + else { + if (n < i) + var->cnsts[n].constraint = elem->constraint; + n++; + } } + if (n) { + var->cnsts_number = n; + lmm_update_modified_set(sys, var->cnsts[0].constraint); + } + var->cnsts_number = 0; - XBT_OUT; + XBT_OUT(); } static void lmm_var_free(lmm_system_t sys, lmm_variable_t var) @@ -115,9 +131,9 @@ static void lmm_var_free(lmm_system_t sys, lmm_variable_t var) static XBT_INLINE void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst) { -/* xbt_assert0(xbt_swag_size(&(cnst->element_set)), */ -/* "This list should be empty!"); */ - remove_active_constraint(sys, cnst); +/* xbt_assert(xbt_swag_size(&(cnst->element_set)), */ +/* "This list should be empty!"); */ + make_constraint_inactive(sys, cnst); free(cnst); } @@ -173,11 +189,6 @@ static void lmm_variable_mallocator_free_f(void *var) xbt_free(var); } -static void lmm_variable_mallocator_reset_f(void *var) -{ - /* lmm_variable_new() initializes everything */ -} - lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id, double weight, double bound, int number_of_constraints) @@ -185,7 +196,7 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id, lmm_variable_t var = NULL; int i; - XBT_IN5("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)", + XBT_IN("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)", sys, id, weight, bound, number_of_constraints); var = xbt_mallocator_get(sys->variable_mallocator); @@ -206,7 +217,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; @@ -222,7 +233,8 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id, xbt_swag_insert_at_head(var, &(sys->variable_set)); else xbt_swag_insert_at_tail(var, &(sys->variable_set)); - XBT_OUT; + + XBT_OUT(" returns %p", var); return var; } @@ -249,7 +261,7 @@ void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, sys->modified = 1; - xbt_assert0(var->cnsts_number < var->cnsts_size, "Too much constraints"); + xbt_assert(var->cnsts_number < var->cnsts_size, "Too much constraints"); elem = &(var->cnsts[var->cnsts_number++]); @@ -261,9 +273,14 @@ void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, xbt_swag_insert_at_head(elem, &(elem->constraint->element_set)); else xbt_swag_insert_at_tail(elem, &(elem->constraint->element_set)); - - make_constraint_active(sys, cnst); - lmm_update_modified_set(sys, cnst); + if(!sys->selective_update_active) { + make_constraint_active(sys, cnst); + } else if(elem->value>0 || var->weight >0) { + make_constraint_active(sys, cnst); + lmm_update_modified_set(sys, cnst); + if (var->cnsts_number > 1) + lmm_update_modified_set(sys, var->cnsts[0].constraint); + } } void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, @@ -313,6 +330,16 @@ XBT_INLINE lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, return NULL; } +XBT_INLINE double lmm_get_cnst_weight_from_var(lmm_system_t sys, + lmm_variable_t var, + int num) +{ + if (num < var->cnsts_number) + return (var->cnsts[num].value); + else + return 0.0; +} + XBT_INLINE int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var) { @@ -343,55 +370,46 @@ XBT_INLINE void *lmm_variable_id(lmm_variable_t var) return var->id; } -static XBT_INLINE void saturated_constraint_set_update(lmm_system_t sys, - lmm_constraint_t - cnst, - double *min_usage) +static XBT_INLINE void saturated_constraint_set_update(double usage, + int cnst_light_num, + dyn_light_t saturated_constraint_set, + double *min_usage) { - lmm_constraint_t useless_cnst = NULL; + xbt_assert(usage > 0,"Impossible"); - XBT_IN3("sys=%p, cnst=%p, min_usage=%f", sys, cnst, *min_usage); - if (cnst->usage <= 0) { - XBT_OUT; - return; - } - if (cnst->remaining <= 0) { - XBT_OUT; - return; - } - if ((*min_usage < 0) || (*min_usage > cnst->remaining / cnst->usage)) { - *min_usage = cnst->remaining / cnst->usage; - LOG3(xbt_log_priority_trace, - "min_usage=%f (cnst->remaining=%f, cnst->usage=%f)", *min_usage, - cnst->remaining, cnst->usage); - while ((useless_cnst = - xbt_swag_getFirst(&(sys->saturated_constraint_set)))) - xbt_swag_remove(useless_cnst, &(sys->saturated_constraint_set)); - - xbt_swag_insert(cnst, &(sys->saturated_constraint_set)); - } else if (*min_usage == cnst->remaining / cnst->usage) { - xbt_swag_insert(cnst, &(sys->saturated_constraint_set)); + if (*min_usage < 0 || *min_usage > usage) { + *min_usage = usage; + // XBT_HERE(" min_usage=%f (cnst->remaining / cnst->usage =%f)", *min_usage, usage); + saturated_constraint_set->data[0] = cnst_light_num; + saturated_constraint_set->pos = 1; + } else if (*min_usage == usage) { + if(saturated_constraint_set->pos == saturated_constraint_set->size) { // realloc the size + saturated_constraint_set->size *= 2; + saturated_constraint_set->data = realloc(saturated_constraint_set->data, (saturated_constraint_set->size) * sizeof(int)); + } + saturated_constraint_set->data[saturated_constraint_set->pos] = cnst_light_num; + saturated_constraint_set->pos++; } - XBT_OUT; } -static XBT_INLINE void saturated_variable_set_update(lmm_system_t sys) +static XBT_INLINE void saturated_variable_set_update( + s_lmm_constraint_light_t *cnst_light_tab, + dyn_light_t saturated_constraint_set, + lmm_system_t sys) { - lmm_constraint_t cnst = NULL; - xbt_swag_t cnst_list = NULL; + lmm_constraint_light_t cnst = NULL; lmm_element_t elem = NULL; xbt_swag_t elem_list = NULL; - - cnst_list = &(sys->saturated_constraint_set); - while ((cnst = xbt_swag_getFirst(cnst_list))) { - elem_list = &(cnst->active_element_set); + int i; + for(i = 0; i< saturated_constraint_set->pos; i++){ + cnst = &cnst_light_tab[saturated_constraint_set->data[i]]; + elem_list = &(cnst->cnst->active_element_set); xbt_swag_foreach(elem, elem_list) { if (elem->variable->weight <= 0) break; if ((elem->value > 0)) xbt_swag_insert(elem->variable, &(sys->saturated_variable_set)); } - xbt_swag_remove(cnst, cnst_list); } } @@ -423,11 +441,10 @@ void lmm_print(lmm_system_t sys) trace_buf = xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); - fprintf(stderr, "%s", trace_buf); - //DEBUG1("%20s", trace_buf); FIXME + XBT_DEBUG("%20s", trace_buf); trace_buf[0] = '\000'; - DEBUG0("Constraints"); + XBT_DEBUG("Constraints"); /* Printing Constraints */ cnst_list = &(sys->active_constraint_set); xbt_swag_foreach(cnst, cnst_list) { @@ -440,7 +457,7 @@ void lmm_print(lmm_system_t sys) sprintf(print_buf, "%s(",(cnst->shared)?"":"max"); trace_buf = xbt_realloc(trace_buf, - strlen(trace_buf) + strlen(print_buf) + 1); + strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); xbt_swag_foreach(elem, elem_list) { sprintf(print_buf, "%f.'%d'(%f) %s ", elem->value, @@ -450,9 +467,9 @@ void lmm_print(lmm_system_t sys) strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); if(cnst->shared) - sum += elem->value * elem->variable->value; + sum += elem->value * elem->variable->value; else - sum = MAX(sum,elem->value * elem->variable->value); + sum = MAX(sum,elem->value * elem->variable->value); } sprintf(print_buf, "0) <= %f ('%d')", cnst->bound, cnst->id_int); trace_buf = @@ -466,25 +483,24 @@ void lmm_print(lmm_system_t sys) strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); } - // DEBUG1("%s", trace_buf); - fprintf(stderr, "%s\n", trace_buf); + XBT_DEBUG("%s", trace_buf); trace_buf[0] = '\000'; - xbt_assert3(!double_positive(sum - cnst->bound), + xbt_assert(!double_positive(sum - cnst->bound), "Incorrect value (%f is not smaller than %f): %g", sum, cnst->bound, sum - cnst->bound); } - DEBUG0("Variables"); + XBT_DEBUG("Variables"); /* Printing Result */ xbt_swag_foreach(var, var_list) { if (var->bound > 0) { - DEBUG4("'%d'(%f) : %f (<=%f)", var->id_int, var->weight, var->value, + XBT_DEBUG("'%d'(%f) : %f (<=%f)", var->id_int, var->weight, var->value, var->bound); - xbt_assert2(!double_positive(var->value - var->bound), + xbt_assert(!double_positive(var->value - var->bound), "Incorrect value (%f is not smaller than %f", var->value, var->bound); } else { - DEBUG3("'%d'(%f) : %f", var->id_int, var->weight, var->value); + XBT_DEBUG("'%d'(%f) : %f", var->id_int, var->weight, var->value); } } @@ -495,6 +511,7 @@ void lmm_solve(lmm_system_t sys) { lmm_variable_t var = NULL; lmm_constraint_t cnst = NULL; + lmm_constraint_t cnst_next = NULL; lmm_element_t elem = NULL; xbt_swag_t cnst_list = NULL; xbt_swag_t var_list = NULL; @@ -505,7 +522,7 @@ void lmm_solve(lmm_system_t sys) if (!(sys->modified)) return; - XBT_IN1("(sys=%p)", sys); + XBT_IN("(sys=%p)", sys); /* * Compute Usage and store the variables that reach the maximum. @@ -515,11 +532,11 @@ void lmm_solve(lmm_system_t sys) selective_update_active ? &(sys->modified_constraint_set) : &(sys->active_constraint_set); - DEBUG1("Active constraints : %d", xbt_swag_size(cnst_list)); + XBT_DEBUG("Active constraints : %d", xbt_swag_size(cnst_list)); /* Init: Only modified code portions */ xbt_swag_foreach(cnst, cnst_list) { elem_list = &(cnst->element_set); - //DEBUG1("Variable set : %d", xbt_swag_size(elem_list)); + //XBT_DEBUG("Variable set : %d", xbt_swag_size(elem_list)); xbt_swag_foreach(elem, elem_list) { var = elem->variable; if (var->weight <= 0.0) @@ -528,7 +545,13 @@ void lmm_solve(lmm_system_t sys) } } - xbt_swag_foreach(cnst, cnst_list) { + 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)); + int cnst_light_num = 0; + dyn_light_t saturated_constraint_set = xbt_new0(s_dyn_light_t,1); + saturated_constraint_set->size = 5; + saturated_constraint_set->data = xbt_new0(int, saturated_constraint_set->size); + + xbt_swag_foreach_safe(cnst, cnst_next, cnst_list) { /* INIT */ cnst->remaining = cnst->bound; if (cnst->remaining == 0) @@ -546,16 +569,26 @@ void lmm_solve(lmm_system_t sys) cnst->usage = elem->value / elem->variable->weight; make_elem_active(elem); - if(keep_track){ - xbt_swag_insert((elem->variable)->id, keep_track); - } + if (sys->keep_track) + xbt_swag_insert(elem->variable->id, sys->keep_track); } } - DEBUG2("Constraint Usage '%d' : %f", cnst->id_int, cnst->usage); + XBT_DEBUG("Constraint Usage '%d' : %f", cnst->id_int, cnst->usage); /* Saturated constraints update */ - saturated_constraint_set_update(sys, cnst, &min_usage); + + if(cnst->usage > 0) { + cnst_light_tab[cnst_light_num].cnst = cnst; + cnst->cnst_light = &(cnst_light_tab[cnst_light_num]); + cnst_light_tab[cnst_light_num].remaining_over_usage = cnst->remaining / cnst->usage; + saturated_constraint_set_update(cnst_light_tab[cnst_light_num].remaining_over_usage, + cnst_light_num, saturated_constraint_set, &min_usage); + cnst_light_num++; + } } - saturated_variable_set_update(sys); + + saturated_variable_set_update( cnst_light_tab, + saturated_constraint_set, + sys); /* Saturated variables update */ @@ -568,7 +601,7 @@ void lmm_solve(lmm_system_t sys) DIE_IMPOSSIBLE; /* First check if some of these variables have reach their upper bound and update min_usage accordingly. */ - DEBUG5 + XBT_DEBUG ("var=%d, var->bound=%f, var->weight=%f, min_usage=%f, var->bound*var->weight=%f", var->id_int, var->bound, var->weight, min_usage, var->bound * var->weight); @@ -577,7 +610,7 @@ void lmm_solve(lmm_system_t sys) min_bound = var->bound; else min_bound = MIN(min_bound, var->bound); - DEBUG1("Updated min_bound=%f", min_bound); + XBT_DEBUG("Updated min_bound=%f", min_bound); } } @@ -595,7 +628,7 @@ void lmm_solve(lmm_system_t sys) continue; } } - DEBUG5("Min usage: %f, Var(%d)->weight: %f, Var(%d)->value: %f ", + XBT_DEBUG("Min usage: %f, Var(%d)->weight: %f, Var(%d)->value: %f ", min_usage, var->id_int, var->weight, var->id_int, var->value); @@ -607,23 +640,43 @@ void lmm_solve(lmm_system_t sys) if (cnst->shared) { double_update(&(cnst->remaining), elem->value * var->value); double_update(&(cnst->usage), elem->value / var->weight); + if(cnst->usage<=0 || cnst->remaining<=0) { + if (cnst->cnst_light) { + int index = (cnst->cnst_light-cnst_light_tab); + XBT_DEBUG("index: %d \t cnst_light_num: %d \t || \t cnst: %p \t cnst->cnst_light: %p \t cnst_light_tab: %p ", + index,cnst_light_num, cnst, cnst->cnst_light, cnst_light_tab); + 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--; + cnst->cnst_light = NULL; + } + } else { + cnst->cnst_light->remaining_over_usage = cnst->remaining / cnst->usage; + } make_elem_inactive(elem); - } else { /* FIXME one day: We recompute usage.... :( */ + } else { cnst->usage = 0.0; make_elem_inactive(elem); elem_list = &(cnst->element_set); xbt_swag_foreach(elem, elem_list) { - if (elem->variable->weight <= 0) - break; - if (elem->variable->value > 0) +// make_elem_active(elem); + if (elem->variable->weight <= 0 || elem->variable->value > 0) break; - if ((elem->value > 0)) { - cnst->usage = - MAX(cnst->usage, elem->value / elem->variable->weight); - DEBUG2("Constraint Usage %d : %f", cnst->id_int, - cnst->usage); - make_elem_active(elem); + if (elem->value > 0) + cnst->usage = MAX(cnst->usage, elem->value / elem->variable->weight); + } + if (cnst->usage<=0 || cnst->remaining<=0) { + if(cnst->cnst_light) { + int index = (cnst->cnst_light-cnst_light_tab); + XBT_DEBUG("index: %d \t cnst_light_num: %d \t || \t cnst: %p \t cnst->cnst_light: %p \t cnst_light_tab: %p ", + index,cnst_light_num, cnst, cnst->cnst_light, cnst_light_tab); + 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--; + cnst->cnst_light = NULL; } + } else { + cnst->cnst_light->remaining_over_usage = cnst->remaining / cnst->usage; } } } @@ -631,17 +684,22 @@ void lmm_solve(lmm_system_t sys) } /* Find out which variables reach the maximum */ - cnst_list = - sys->selective_update_active ? &(sys->modified_constraint_set) : - &(sys->active_constraint_set); min_usage = -1; min_bound = -1; - xbt_swag_foreach(cnst, cnst_list) { - saturated_constraint_set_update(sys, cnst, &min_usage); - } - saturated_variable_set_update(sys); + saturated_constraint_set->pos = 0; + int pos; + for(pos=0; possaturated_variable_set))); + saturated_variable_set_update( cnst_light_tab, + saturated_constraint_set, + sys); + + } while (cnst_light_num > 0); sys->modified = 0; if (sys->selective_update_active) @@ -650,7 +708,11 @@ void lmm_solve(lmm_system_t sys) if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) { lmm_print(sys); } - XBT_OUT; + + xbt_free(saturated_constraint_set->data); + xbt_free(saturated_constraint_set); + xbt_free(cnst_light_tab); + XBT_OUT(); } /* Not a O(1) function */ @@ -684,14 +746,11 @@ void lmm_update(lmm_system_t sys, lmm_constraint_t cnst, void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var, double bound) { - int i; - sys->modified = 1; var->bound = bound; - for (i = 0; i < var->cnsts_number; i++) - lmm_update_modified_set(sys, var->cnsts[i].constraint); - + if (var->cnsts_number) + lmm_update_modified_set(sys, var->cnsts[0].constraint); } @@ -703,7 +762,7 @@ void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, if (weight == var->weight) return; - XBT_IN3("(sys=%p, var=%p, weight=%f)", sys, var, weight); + XBT_IN("(sys=%p, var=%p, weight=%f)", sys, var, weight); sys->modified = 1; var->weight = weight; xbt_swag_remove(var, &(sys->variable_set)); @@ -720,12 +779,13 @@ void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, else xbt_swag_insert_at_tail(elem, &(elem->constraint->element_set)); - lmm_update_modified_set(sys, elem->constraint); + if (i == 0) + lmm_update_modified_set(sys, elem->constraint); } if (!weight) var->value = 0.0; - XBT_OUT; + XBT_OUT(); } XBT_INLINE double lmm_get_variable_weight(lmm_variable_t var) @@ -779,36 +839,36 @@ XBT_INLINE int lmm_is_variable_limited_by_latency(lmm_variable_t var) * constraints that have changed. Each constraint change is propagated * to the list of constraints for each variable. */ -static void lmm_update_modified_set(lmm_system_t sys, - lmm_constraint_t cnst) +static void lmm_update_modified_set_rec(lmm_system_t sys, + lmm_constraint_t cnst) { - lmm_element_t elem = NULL; - lmm_variable_t var = NULL; - xbt_swag_t elem_list = NULL; - int i; - - /* return if selective update isn't active */ - if (!sys->selective_update_active) - return; - - //DEBUG1("Updating modified constraint set with constraint %d", cnst->id_int); - - if (xbt_swag_belongs(cnst, &(sys->modified_constraint_set))) - return; - - //DEBUG1("Inserting into modified constraint set %d", cnst->id_int); - - /* add to modified set */ - xbt_swag_insert(cnst, &(sys->modified_constraint_set)); + lmm_element_t elem; - elem_list = &(cnst->element_set); - xbt_swag_foreach(elem, elem_list) { - var = elem->variable; - for (i = 0; i < var->cnsts_number; i++) - if (cnst != var->cnsts[i].constraint) { - //DEBUG2("Updating modified %d calling for %d", cnst->id_int, var->cnsts[i].constraint->id_int); - lmm_update_modified_set(sys, var->cnsts[i].constraint); + xbt_swag_foreach(elem, &cnst->element_set) { + lmm_variable_t var = elem->variable; + s_lmm_element_t *cnsts = var->cnsts; + int 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)) { + xbt_swag_insert(cnsts[i].constraint, &sys->modified_constraint_set); + lmm_update_modified_set_rec(sys, cnsts[i].constraint); } + } + var->visited = sys->visited_counter; + } +} + +static void lmm_update_modified_set(lmm_system_t sys, + lmm_constraint_t cnst) +{ + /* nothing to do if selective update isn't active */ + if (sys->selective_update_active + && !xbt_swag_belongs(cnst, &sys->modified_constraint_set)) { + xbt_swag_insert(cnst, &sys->modified_constraint_set); + lmm_update_modified_set_rec(sys, cnst); } } @@ -818,12 +878,11 @@ static void lmm_update_modified_set(lmm_system_t sys, */ static void lmm_remove_all_modified_set(lmm_system_t sys) { - lmm_element_t elem = NULL; - lmm_element_t elem_next = NULL; - xbt_swag_t elem_list = NULL; - - elem_list = &(sys->modified_constraint_set); - xbt_swag_foreach_safe(elem, elem_next, elem_list) { - xbt_swag_remove(elem, elem_list); + 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); }