X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4be1b32b731cc2a3a6e8bef09d782a19280d6ddf..93b7899156ac9fee75c4a6a8b65b92b265d61d4f:/src/surf/maxmin.cpp diff --git a/src/surf/maxmin.cpp b/src/surf/maxmin.cpp index d30d207aee..3af832b7a0 100644 --- a/src/surf/maxmin.cpp +++ b/src/surf/maxmin.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2004-2014. The SimGrid Team. +/* Copyright (c) 2004-2015. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -20,8 +20,8 @@ typedef struct s_dyn_light { int size; } s_dyn_light_t, *dyn_light_t; -XBT_EXPORT_NO_IMPORT(double) sg_maxmin_precision = 0.00001; -XBT_EXPORT_NO_IMPORT(double) sg_surf_precision = 0.00001; +double sg_maxmin_precision = 0.00001; +double sg_surf_precision = 0.00001; static void *lmm_variable_mallocator_new_f(void); static void lmm_variable_mallocator_free_f(void *var); @@ -48,7 +48,7 @@ lmm_system_t lmm_system_new(int selective_update) l->selective_update_active = selective_update; l->visited_counter = 1; - XBT_DEBUG("Setting selective_update_active flag to %d\n", + XBT_DEBUG("Setting selective_update_active flag to %d", l->selective_update_active); xbt_swag_init(&(l->variable_set), @@ -157,7 +157,7 @@ lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id, cnst->bound = bound_value; cnst->usage = 0; - cnst->shared = 1; + cnst->sharing_policy = 1; /* FIXME: don't hardcode the value */ insert_constraint(sys, cnst); return cnst; @@ -165,12 +165,13 @@ lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id, void lmm_constraint_shared(lmm_constraint_t cnst) { - cnst->shared = 0; + cnst->sharing_policy = 0; } -int lmm_constraint_is_shared(lmm_constraint_t cnst) +/** Return true if the constraint is shared, and false if it's FATPIPE */ +int lmm_constraint_sharing_policy(lmm_constraint_t cnst) { - return (cnst->shared); + return (cnst->sharing_policy); } XBT_INLINE void lmm_constraint_free(lmm_system_t sys, @@ -382,7 +383,7 @@ void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, break; if (i < var->cnsts_number) { - if (cnst->shared) + if (cnst->sharing_policy) var->cnsts[i].value += value; else var->cnsts[i].value = MAX(var->cnsts[i].value, value); @@ -431,6 +432,31 @@ lmm_variable_t lmm_get_var_from_cnst(lmm_system_t /*sys*/, return NULL; } +//if we modify the swag between calls, normal version may loop forever +//this safe version ensures that we browse the swag elements only once +lmm_variable_t lmm_get_var_from_cnst_safe(lmm_system_t /*sys*/, + lmm_constraint_t cnst, + lmm_element_t * elem, + lmm_element_t * nextelem, + int * numelem) +{ + if (!(*elem)){ + *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->element_set)); + *numelem = xbt_swag_size(&(cnst->element_set))-1; + }else{ + *elem = *nextelem; + if(*numelem>0){ + (*numelem) --; + }else + return NULL; + } + if (*elem){ + *nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->element_set.offset); + return (*elem)->variable; + }else + return NULL; +} + void *lmm_constraint_id(lmm_constraint_t cnst) { return cnst->id; @@ -531,7 +557,7 @@ void lmm_print(lmm_system_t sys) trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); - sprintf(print_buf, "%s(",(cnst->shared)?"":"max"); + sprintf(print_buf, "%s(",(cnst->sharing_policy)?"":"max"); trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); @@ -539,22 +565,22 @@ void lmm_print(lmm_system_t sys) xbt_swag_foreach(_elem, elem_list) { elem = (lmm_element_t)_elem; sprintf(print_buf, "%f.'%d'(%f) %s ", elem->value, - elem->variable->id_int, elem->variable->value,(cnst->shared)?"+":","); + elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":","); trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); - if(cnst->shared) - sum += elem->value * elem->variable->value; + if(cnst->sharing_policy) + 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 = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); - if (!cnst->shared) { + if (!cnst->sharing_policy) { sprintf(print_buf, " [MAX-Constraint]"); trace_buf = (char*) xbt_realloc(trace_buf, @@ -645,13 +671,13 @@ void lmm_solve(lmm_system_t sys) if (elem->variable->weight <= 0) break; if ((elem->value > 0)) { - if (cnst->shared) + if (cnst->sharing_policy) cnst->usage += elem->value / elem->variable->weight; else if (cnst->usage < elem->value / elem->variable->weight) cnst->usage = elem->value / elem->variable->weight; make_elem_active(elem); - ActionPtr action = static_cast(elem->variable->id); + simgrid::surf::Action *action = static_cast(elem->variable->id); if (sys->keep_track && !action->is_linked()) sys->keep_track->push_back(*action); } @@ -692,9 +718,9 @@ void lmm_solve(lmm_system_t sys) var->bound * var->weight); if ((var->bound > 0) && (var->bound * var->weight < min_usage)) { if (min_bound < 0) - min_bound = var->bound; + min_bound = var->bound*var->weight; else - min_bound = MIN(min_bound, var->bound); + min_bound = MIN(min_bound, (var->bound*var->weight)); XBT_DEBUG("Updated min_bound=%f", min_bound); } } @@ -709,7 +735,7 @@ void lmm_solve(lmm_system_t sys) XBT_DEBUG("Setting %p (%d) value to %f\n", var, var->id_int, var->value); } else { //If there exist a variable that can reach its bound, only update it (and other with the same bound) for now. - if (min_bound == var->bound) { + if (double_equals(min_bound, var->bound*var->weight, sg_maxmin_precision)){ var->value = var->bound; XBT_DEBUG("Setting %p (%d) value to %f\n", var, var->id_int, var->value); } @@ -728,7 +754,7 @@ void lmm_solve(lmm_system_t sys) for (i = 0; i < var->cnsts_number; i++) { elem = &var->cnsts[i]; cnst = elem->constraint; - if (cnst->shared) { + if (cnst->sharing_policy) { //Remember: shared constraints require that sum(elem->value * var->value) < cnst->bound double_update(&(cnst->remaining), elem->value * var->value, cnst->bound*sg_maxmin_precision); double_update(&(cnst->usage), elem->value / var->weight, sg_maxmin_precision); @@ -785,7 +811,7 @@ void lmm_solve(lmm_system_t sys) saturated_constraint_set->pos = 0; int pos; for(pos=0; posactive_element_set.count>0, "Cannot saturate more a constraint that has no active element! You want to check the maxmin precision and possible rounding effects." ); + xbt_assert(cnst_light_tab[pos].cnst->active_element_set.count>0, "Cannot saturate more a constraint that has no active element! You may want to change the maxmin precision (--cfg=maxmin/precision:) because of possible rounding effects.\n\tFor the record, the usage of this constraint is %g while the maxmin precision to which it is compared is %g.\n\tThe usage of the previous constraint is %g.", cnst_light_tab[pos].cnst->usage, sg_maxmin_precision, cnst_light_tab[pos-1].cnst->usage); saturated_constraint_set_update( cnst_light_tab[pos].remaining_over_usage, pos, @@ -1003,7 +1029,7 @@ double lmm_constraint_get_usage(lmm_constraint_t cnst) { if (elem->variable->weight <= 0) break; if ((elem->value > 0)) { - if (cnst->shared) + if (cnst->sharing_policy) usage += elem->value * elem->variable->value; else if (usage < elem->value * elem->variable->value) usage = elem->value * elem->variable->value;