X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/976ee462f4626798ebf76ca46d13f53e10e0e28d..75e8415d3b5fbec784b77b485da05ccbd0256d93:/src/surf/maxmin.c diff --git a/src/surf/maxmin.c b/src/surf/maxmin.c index 37d53c716c..c35b51936f 100644 --- a/src/surf/maxmin.c +++ b/src/surf/maxmin.c @@ -1,6 +1,5 @@ -/* $Id$ */ - -/* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */ +/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -21,7 +20,7 @@ static void lmm_variable_mallocator_free_f(void *var); static void lmm_variable_mallocator_reset_f(void *var); 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 = 0; +int sg_maxmin_selective_update = 1; static int Global_debug_id = 1; static int Global_const_debug_id = 1; lmm_system_t lmm_system_new(void) @@ -53,9 +52,6 @@ lmm_system_t lmm_system_new(void) xbt_swag_init(&(l->saturated_constraint_set), xbt_swag_offset(cnst, saturated_constraint_set_hookup)); - xbt_swag_init(&(l->modified_variable_set), - xbt_swag_offset(var, modified_variable_set_hookup)); - l->variable_mallocator = xbt_mallocator_new(64, lmm_variable_mallocator_new_f, lmm_variable_mallocator_free_f, @@ -69,8 +65,11 @@ void lmm_system_free(lmm_system_t sys) lmm_variable_t var = NULL; lmm_constraint_t cnst = NULL; - while ((var = extract_variable(sys))) + while ((var = extract_variable(sys))) { + WARN2("Variable %p (%d) still in LMM system when freing it: this may be a bug", + var,var->id_int); lmm_var_free(sys, var); + } while ((cnst = extract_constraint(sys))) lmm_cnst_free(sys, cnst); @@ -79,7 +78,7 @@ void lmm_system_free(lmm_system_t sys) free(sys); } -void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var) +XBT_INLINE void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var) { int i; lmm_element_t elem = NULL; @@ -108,7 +107,7 @@ static void lmm_var_free(lmm_system_t sys, lmm_variable_t var) xbt_mallocator_release(sys->variable_mallocator, var); } -static void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst) +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!"); */ @@ -138,17 +137,17 @@ lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id, return cnst; } -void lmm_constraint_shared(lmm_constraint_t cnst) +XBT_INLINE void lmm_constraint_shared(lmm_constraint_t cnst) { cnst->shared = 0; } -int lmm_constraint_is_shared(lmm_constraint_t cnst) +XBT_INLINE int lmm_constraint_is_shared(lmm_constraint_t cnst) { return (cnst->shared); } -void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst) +XBT_INLINE void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst) { remove_constraint(sys, cnst); lmm_cnst_free(sys, cnst); @@ -221,12 +220,12 @@ void lmm_variable_free(lmm_system_t sys, lmm_variable_t var) lmm_var_free(sys, var); } -double lmm_variable_getvalue(lmm_variable_t var) +XBT_INLINE double lmm_variable_getvalue(lmm_variable_t var) { return (var->value); } -double lmm_variable_getbound(lmm_variable_t var) +XBT_INLINE double lmm_variable_getbound(lmm_variable_t var) { return (var->bound); } @@ -292,7 +291,7 @@ void lmm_elem_set_value(lmm_system_t sys, lmm_constraint_t cnst, DIE_IMPOSSIBLE; } -lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, +XBT_INLINE lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, lmm_variable_t var, int num) { if (num < var->cnsts_number) @@ -301,7 +300,7 @@ lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, return NULL; } -int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var) +XBT_INLINE int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var) { return (var->cnsts_number); } @@ -320,17 +319,17 @@ lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys, return NULL; } -void *lmm_constraint_id(lmm_constraint_t cnst) +XBT_INLINE void *lmm_constraint_id(lmm_constraint_t cnst) { return cnst->id; } -void *lmm_variable_id(lmm_variable_t var) +XBT_INLINE void *lmm_variable_id(lmm_variable_t var) { return var->id; } -static void saturated_constraint_set_update(lmm_system_t sys, +static XBT_INLINE void saturated_constraint_set_update(lmm_system_t sys, lmm_constraint_t cnst, double *min_usage) { @@ -361,7 +360,7 @@ static void saturated_constraint_set_update(lmm_system_t sys, XBT_OUT; } -static void saturated_variable_set_update(lmm_system_t sys) +static XBT_INLINE void saturated_variable_set_update(lmm_system_t sys) { lmm_constraint_t cnst = NULL; xbt_swag_t cnst_list = NULL; @@ -494,38 +493,20 @@ void lmm_solve(lmm_system_t sys) //DEBUG1("Variable set : %d", xbt_swag_size(elem_list)); xbt_swag_foreach(elem, elem_list) { var = elem->variable; - xbt_swag_insert(var, &(sys->modified_variable_set)); - /* FIXME: modified this test because we need all actions in cpu_im */ if (var->weight <= 0.0) - //break; - continue; + break; var->value = 0.0; } } - /* Init: special case where all constraints are 0 */ - var_list = &(sys->variable_set); - DEBUG1("Variable set : %d", xbt_swag_size(var_list)); - xbt_swag_foreach(var, var_list) { - int nb = 0; - int i; - if (var->weight <= 0.0) - break; - for (i = 0; i < var->cnsts_number; i++) { - if (var->cnsts[i].value == 0.0) - nb++; - } - if ((nb == var->cnsts_number) && (var->weight > 0.0)) - var->value = 1.0; - } - DEBUG1("Active constraints : %d", xbt_swag_size(cnst_list)); xbt_swag_foreach(cnst, cnst_list) { /* INIT */ cnst->remaining = cnst->bound; + if (cnst->remaining == 0) + continue; cnst->usage = 0; elem_list = &(cnst->element_set); - cnst->usage = 0.0; xbt_swag_foreach(elem, elem_list) { /* 0-weighted elements (ie, sleep actions) are at the end of the swag and we don't want to consider them */ if (elem->variable->weight <= 0) @@ -572,7 +553,6 @@ void lmm_solve(lmm_system_t sys) while ((var = xbt_swag_getFirst(var_list))) { int i; - xbt_swag_insert(var, &(sys->modified_variable_set)); if (min_bound < 0) { var->value = min_usage / var->weight; @@ -600,14 +580,14 @@ void lmm_solve(lmm_system_t sys) } else { /* FIXME one day: We recompute usage.... :( */ 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) break; if ((elem->value > 0)) { - if (cnst->usage < elem->value / elem->variable->weight) - cnst->usage = elem->value / elem->variable->weight; + cnst->usage=MAX(cnst->usage,elem->value / elem->variable->weight); DEBUG2("Constraint Usage %d : %f", cnst->id_int, cnst->usage); make_elem_active(elem); } @@ -619,8 +599,7 @@ 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->selective_update_active ? &(sys->modified_constraint_set) : &(sys->active_constraint_set); min_usage = -1; min_bound = -1; @@ -715,12 +694,12 @@ void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, XBT_OUT; } -double lmm_get_variable_weight(lmm_variable_t var) +XBT_INLINE double lmm_get_variable_weight(lmm_variable_t var) { return var->weight; } -void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, +XBT_INLINE void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, double bound) { sys->modified = 1; @@ -728,22 +707,28 @@ void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, cnst->bound = bound; } -int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst) +XBT_INLINE int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst) { return xbt_swag_belongs(cnst, &(sys->active_constraint_set)); } -lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys) +XBT_INLINE lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys) { return xbt_swag_getFirst(&(sys->active_constraint_set)); } -lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys, +XBT_INLINE lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys, lmm_constraint_t cnst) { return xbt_swag_getNext(cnst, (sys->active_constraint_set).offset); } +XBT_INLINE int lmm_is_variable_limited_by_latency(lmm_variable_t var) +{ + return (double_equals(var->bound, var->value)); +} + + /** \brief Update the constraint set propagating recursively to * other constraints so the system should not be entirely computed. * @@ -801,12 +786,3 @@ static void lmm_remove_all_modified_set(lmm_system_t sys) xbt_swag_remove(elem, elem_list); } } - -void *lmm_extract_modified_variable(lmm_system_t sys) -{ - lmm_variable_t var; - var = xbt_swag_extract(&(sys->modified_variable_set)); - if (var) - return var->id; - return NULL; -}