From 276cb878829b90c459527e9cc5649e662e8e3484 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 4 Jul 2017 11:42:01 +0200 Subject: [PATCH] maxmin: rename a variable for clarity --- src/surf/fair_bottleneck.cpp | 24 +++--- src/surf/lagrange.cpp | 48 ++++++------ src/surf/maxmin.cpp | 146 +++++++++++++++++------------------ src/surf/maxmin_private.hpp | 12 ++- 4 files changed, 120 insertions(+), 110 deletions(-) diff --git a/src/surf/fair_bottleneck.cpp b/src/surf/fair_bottleneck.cpp index 30b45e290d..2f44bdb53e 100644 --- a/src/surf/fair_bottleneck.cpp +++ b/src/surf/fair_bottleneck.cpp @@ -48,15 +48,15 @@ void bottleneck_solve(lmm_system_t sys) XBT_DEBUG("Handling variable %p", var); xbt_swag_insert(var, &(sys->saturated_variable_set)); for (int i = 0; i < var->cnsts_number; i++) { - if (var->cnsts[i].value == 0.0) + if (var->cnsts[i].consumption_weight == 0.0) nb++; } - if ((nb == var->cnsts_number) && (var->weight > 0.0)) { + if ((nb == var->cnsts_number) && (var->sharing_weight > 0.0)) { XBT_DEBUG("Err, finally, there is no need to take care of variable %p", var); xbt_swag_remove(var, &(sys->saturated_variable_set)); var->value = 1.0; } - if (var->weight <= 0.0) { + if (var->sharing_weight <= 0.0) { XBT_DEBUG("Err, finally, there is no need to take care of variable %p", var); xbt_swag_remove(var, &(sys->saturated_variable_set)); } @@ -95,8 +95,8 @@ void bottleneck_solve(lmm_system_t sys) cnst->usage = 0.0; xbt_swag_foreach(_elem, elem_list) { elem = static_cast(_elem); - xbt_assert(elem->variable->weight > 0); - if ((elem->value > 0) && xbt_swag_belongs(elem->variable, var_list)) + xbt_assert(elem->variable->sharing_weight > 0); + if ((elem->consumption_weight > 0) && xbt_swag_belongs(elem->variable, var_list)) nb++; } XBT_DEBUG("\tThere are %d variables", nb); @@ -117,8 +117,8 @@ void bottleneck_solve(lmm_system_t sys) double min_inc = DBL_MAX; for (int i = 0; i < var->cnsts_number; i++) { lmm_element_t elm = &var->cnsts[i]; - if (elm->value > 0) - min_inc = MIN(min_inc, elm->constraint->usage / elm->value); + if (elm->consumption_weight > 0) + min_inc = MIN(min_inc, elm->constraint->usage / elm->consumption_weight); } if (var->bound > 0) min_inc = MIN(min_inc, var->bound - var->value); @@ -136,15 +136,15 @@ void bottleneck_solve(lmm_system_t sys) elem_list = &(cnst->enabled_element_set); xbt_swag_foreach(_elem, elem_list) { elem = static_cast(_elem); - xbt_assert(elem->variable->weight > 0); + xbt_assert(elem->variable->sharing_weight > 0); if (cnst->sharing_policy) { XBT_DEBUG("\tUpdate constraint %p (%g) with variable %p by %g", cnst, cnst->remaining, elem->variable, elem->variable->mu); - double_update(&(cnst->remaining), elem->value * elem->variable->mu, sg_maxmin_precision); + double_update(&(cnst->remaining), elem->consumption_weight * elem->variable->mu, sg_maxmin_precision); } else { XBT_DEBUG("\tNon-Shared variable. Update constraint usage of %p (%g) with variable %p by %g", cnst, cnst->usage, elem->variable, elem->variable->mu); - cnst->usage = MIN(cnst->usage, elem->value * elem->variable->mu); + cnst->usage = MIN(cnst->usage, elem->consumption_weight * elem->variable->mu); } } if (not cnst->sharing_policy) { @@ -160,9 +160,9 @@ void bottleneck_solve(lmm_system_t sys) xbt_swag_remove(cnst, cnst_list); xbt_swag_foreach(_elem, elem_list) { elem = static_cast(_elem); - if (elem->variable->weight <= 0) + if (elem->variable->sharing_weight <= 0) break; - if (elem->value > 0) { + if (elem->consumption_weight > 0) { XBT_DEBUG("\t\tGet rid of variable %p", elem->variable); xbt_swag_remove(elem->variable, var_list); } diff --git a/src/surf/lagrange.cpp b/src/surf/lagrange.cpp index 4ad25edeb0..dc52269d89 100644 --- a/src/surf/lagrange.cpp +++ b/src/surf/lagrange.cpp @@ -50,7 +50,7 @@ static int __check_feasible(xbt_swag_t cnst_list, xbt_swag_t var_list, int warn) xbt_swag_foreach(_elem, elem_list) { elem = static_cast(_elem); var = elem->variable; - xbt_assert(var->weight > 0); + xbt_assert(var->sharing_weight > 0); tmp += var->value; } @@ -65,7 +65,7 @@ static int __check_feasible(xbt_swag_t cnst_list, xbt_swag_t var_list, int warn) xbt_swag_foreach(_var, var_list) { var = static_cast(_var); - if (not var->weight) + if (not var->sharing_weight) break; if (var->bound < 0) continue; @@ -89,7 +89,7 @@ static double new_value(lmm_variable_t var) } if (var->bound > 0) tmp += var->mu; - XBT_DEBUG("\t Working on var (%p). cost = %e; Weight = %e", var, tmp, var->weight); + XBT_DEBUG("\t Working on var (%p). cost = %e; Weight = %e", var, tmp, var->sharing_weight); //uses the partial differential inverse function return var->func_fpi(var, tmp); } @@ -121,7 +121,7 @@ static double dual_objective(xbt_swag_t var_list, xbt_swag_t cnst_list) var = static_cast(_var); double sigma_i = 0.0; - if (not var->weight) + if (not var->sharing_weight) break; for (int j = 0; j < var->cnsts_number; j++) @@ -199,7 +199,7 @@ void lagrange_solve(lmm_system_t sys) i = 0; xbt_swag_foreach(_var, var_list) { var = static_cast(_var); - if (not var->weight) + if (not var->sharing_weight) var->value = 0.0; else { int nb = 0; @@ -212,12 +212,12 @@ void lagrange_solve(lmm_system_t sys) var->new_mu = 2.0; var->value = new_value(var); } - XBT_DEBUG("#### var(%p) ->weight : %e", var, var->weight); + XBT_DEBUG("#### var(%p) ->weight : %e", var, var->sharing_weight); XBT_DEBUG("#### var(%p) ->mu : %e", var, var->mu); - XBT_DEBUG("#### var(%p) ->weight: %e", var, var->weight); + XBT_DEBUG("#### var(%p) ->weight: %e", var, var->sharing_weight); XBT_DEBUG("#### var(%p) ->bound: %e", var, var->bound); for (i = 0; i < var->cnsts_number; i++) { - if (var->cnsts[i].value == 0.0) + if (var->cnsts[i].consumption_weight == 0.0) nb++; } if (nb == var->cnsts_number) @@ -237,7 +237,7 @@ void lagrange_solve(lmm_system_t sys) /* Improve the value of mu_i */ xbt_swag_foreach(_var, var_list) { var = static_cast(_var); - if (not var->weight) + if (not var->sharing_weight) break; if (var->bound >= 0) { XBT_DEBUG("Working on var (%p)", var); @@ -275,7 +275,7 @@ void lagrange_solve(lmm_system_t sys) overall_modification = 0; xbt_swag_foreach(_var, var_list) { var = static_cast(_var); - if (var->weight <= 0) + if (var->sharing_weight <= 0) var->value = 0.0; else { tmp = new_value(var); @@ -440,7 +440,7 @@ static double partial_diff_lambda(double lambda, void *param_cnst) xbt_swag_foreach(_elem, elem_list) { lmm_element_t elem = static_cast(_elem); lmm_variable_t var = elem->variable; - xbt_assert(var->weight > 0); + xbt_assert(var->sharing_weight > 0); XBT_CDEBUG(surf_lagrange_dichotomy, "Computing sigma_i for var (%p)", var); // Initialize the summation variable double sigma_i = 0.0; @@ -497,19 +497,19 @@ void lmm_set_default_protocol_function(double (*func_f) (lmm_variable_t var, dou double func_vegas_f(lmm_variable_t var, double x) { xbt_assert(x > 0.0, "Don't call me with stupid values! (%1.20f)", x); - return VEGAS_SCALING * var->weight * log(x); + return VEGAS_SCALING * var->sharing_weight * log(x); } double func_vegas_fp(lmm_variable_t var, double x) { xbt_assert(x > 0.0, "Don't call me with stupid values! (%1.20f)", x); - return VEGAS_SCALING * var->weight / x; + return VEGAS_SCALING * var->sharing_weight / x; } double func_vegas_fpi(lmm_variable_t var, double x) { xbt_assert(x > 0.0, "Don't call me with stupid values! (%1.20f)", x); - return var->weight / (x / VEGAS_SCALING); + return var->sharing_weight / (x / VEGAS_SCALING); } /* @@ -520,24 +520,25 @@ double func_vegas_fpi(lmm_variable_t var, double x) #define RENO_SCALING 1.0 double func_reno_f(lmm_variable_t var, double x) { - xbt_assert(var->weight > 0.0, "Don't call me with stupid values!"); + xbt_assert(var->sharing_weight > 0.0, "Don't call me with stupid values!"); - return RENO_SCALING * sqrt(3.0 / 2.0) / var->weight * atan(sqrt(3.0 / 2.0) * var->weight * x); + return RENO_SCALING * sqrt(3.0 / 2.0) / var->sharing_weight * atan(sqrt(3.0 / 2.0) * var->sharing_weight * x); } double func_reno_fp(lmm_variable_t var, double x) { - return RENO_SCALING * 3.0 / (3.0 * var->weight * var->weight * x * x + 2.0); + return RENO_SCALING * 3.0 / (3.0 * var->sharing_weight * var->sharing_weight * x * x + 2.0); } double func_reno_fpi(lmm_variable_t var, double x) { double res_fpi; - xbt_assert(var->weight > 0.0, "Don't call me with stupid values!"); + xbt_assert(var->sharing_weight > 0.0, "Don't call me with stupid values!"); xbt_assert(x > 0.0, "Don't call me with stupid values!"); - res_fpi = 1.0 / (var->weight * var->weight * (x / RENO_SCALING)) - 2.0 / (3.0 * var->weight * var->weight); + res_fpi = 1.0 / (var->sharing_weight * var->sharing_weight * (x / RENO_SCALING)) - + 2.0 / (3.0 * var->sharing_weight * var->sharing_weight); if (res_fpi <= 0.0) return 0.0; /* xbt_assert(res_fpi>0.0,"Don't call me with stupid values!"); */ @@ -552,19 +553,20 @@ double func_reno_fpi(lmm_variable_t var, double x) #define RENO2_SCALING 1.0 double func_reno2_f(lmm_variable_t var, double x) { - xbt_assert(var->weight > 0.0, "Don't call me with stupid values!"); - return RENO2_SCALING * (1.0 / var->weight) * log((x * var->weight) / (2.0 * x * var->weight + 3.0)); + xbt_assert(var->sharing_weight > 0.0, "Don't call me with stupid values!"); + return RENO2_SCALING * (1.0 / var->sharing_weight) * + log((x * var->sharing_weight) / (2.0 * x * var->sharing_weight + 3.0)); } double func_reno2_fp(lmm_variable_t var, double x) { - return RENO2_SCALING * 3.0 / (var->weight * x * (2.0 * var->weight * x + 3.0)); + return RENO2_SCALING * 3.0 / (var->sharing_weight * x * (2.0 * var->sharing_weight * x + 3.0)); } double func_reno2_fpi(lmm_variable_t var, double x) { xbt_assert(x > 0.0, "Don't call me with stupid values!"); - double tmp = x * var->weight * var->weight; + double tmp = x * var->sharing_weight * var->sharing_weight; double res_fpi = tmp * (9.0 * x + 24.0); if (res_fpi <= 0.0) diff --git a/src/surf/maxmin.cpp b/src/surf/maxmin.cpp index 5876ad7d40..f6dfe9a836 100644 --- a/src/surf/maxmin.cpp +++ b/src/surf/maxmin.cpp @@ -49,7 +49,7 @@ static void lmm_check_concurrency(lmm_system_t sys); inline int lmm_element_concurrency(lmm_element_t elem) { //Ignore element with weight less than one (e.g. cross-traffic) - return (elem->value>=1)?1:0; + return (elem->consumption_weight >= 1) ? 1 : 0; //There are other alternatives, but they will change the behaviour of the model.. //So do not use it unless you want to make a new model. //If you do, remember to change the variables concurrency share to reflect it. @@ -148,8 +148,8 @@ static inline void lmm_variable_remove(lmm_system_t sys, lmm_variable_t var) for (i = 0; i < var->cnsts_number; i++) { elem = &var->cnsts[i]; - if(var->weight>0) - lmm_decrease_concurrency(elem); + if (var->sharing_weight > 0) + lmm_decrease_concurrency(elem); xbt_swag_remove(elem, &(elem->constraint->enabled_element_set)); xbt_swag_remove(elem, &(elem->constraint->disabled_element_set)); xbt_swag_remove(elem, &(elem->constraint->active_element_set)); @@ -275,13 +275,13 @@ static void lmm_variable_mallocator_free_f(void *var) xbt_free(var); } -lmm_variable_t lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, double weight, double bound, +lmm_variable_t lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, double sharing_weight, double bound, int number_of_constraints) { lmm_variable_t var = nullptr; int i; - XBT_IN("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)", sys, id, weight, bound, number_of_constraints); + XBT_IN("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)", sys, id, sharing_weight, bound, number_of_constraints); var = (lmm_variable_t) xbt_mallocator_get(sys->variable_mallocator); var->id = id; @@ -296,11 +296,11 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, dou var->cnsts[i].active_element_set_hookup.prev = nullptr; var->cnsts[i].constraint = nullptr; var->cnsts[i].variable = nullptr; - var->cnsts[i].value = 0.0; + var->cnsts[i].consumption_weight = 0.0; } var->cnsts_size = number_of_constraints; var->cnsts_number = 0; - var->weight = weight; + var->sharing_weight = sharing_weight; var->staged_weight = 0.0; var->bound = bound; var->concurrency_share = 1; @@ -317,7 +317,7 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, dou var->saturated_variable_set_hookup.next = nullptr; var->saturated_variable_set_hookup.prev = nullptr; - if (weight) + if (sharing_weight) xbt_swag_insert_at_head(var, &(sys->variable_set)); else xbt_swag_insert_at_tail(var, &(sys->variable_set)); @@ -368,7 +368,8 @@ void lmm_shrink(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var) sys->modified = 1; - XBT_DEBUG("remove elem(value %f, cnst %p, var %p) in var %p", elem->value, elem->constraint, elem->variable, var); + XBT_DEBUG("remove elem(value %f, cnst %p, var %p) in var %p", elem->consumption_weight, elem->constraint, + elem->variable, var); /* We are going to change the constraint object and the variable object. * Propagate this change to other objects. Calling here before removing variable from not active elements @@ -385,7 +386,7 @@ void lmm_shrink(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var) xbt_swag_remove(elem, &(elem->constraint->active_element_set)); elem->constraint = nullptr; elem->variable = nullptr; - elem->value = 0; + elem->consumption_weight = 0; var->cnsts_number -= 1; @@ -400,7 +401,7 @@ void lmm_shrink(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var) lmm_check_concurrency(sys); } -void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value) +void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double consumption_weight) { lmm_element_t elem = nullptr; int i,current_share; @@ -419,25 +420,25 @@ void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, dou } //Check if we need to disable the variable - if(var->weight>0 && var->concurrency_share-current_share>lmm_concurrency_slack(cnst)) { - double weight = var->weight; + if (var->sharing_weight > 0 && var->concurrency_share - current_share > lmm_concurrency_slack(cnst)) { + double weight = var->sharing_weight; lmm_disable_var(sys,var); for (i = 0; i < var->cnsts_number; i++) lmm_on_disabled_var(sys,var->cnsts[i].constraint); - value=0; + consumption_weight = 0; var->staged_weight=weight; - xbt_assert(not var->weight); + xbt_assert(not var->sharing_weight); } xbt_assert(var->cnsts_number < var->cnsts_size, "Too much constraints"); elem = &(var->cnsts[var->cnsts_number++]); - elem->value = value; + elem->consumption_weight = consumption_weight; elem->constraint = cnst; elem->variable = var; - if (var->weight){ + if (var->sharing_weight) { xbt_swag_insert_at_head(elem, &(elem->constraint->enabled_element_set)); lmm_increase_concurrency(elem); } else @@ -445,7 +446,7 @@ void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, dou if (not sys->selective_update_active) { make_constraint_active(sys, cnst); - } else if(elem->value>0 || var->weight >0) { + } else if (elem->consumption_weight > 0 || var->sharing_weight > 0) { make_constraint_active(sys, cnst); lmm_update_modified_set(sys, cnst); //TODOLATER: Why do we need this second call? @@ -470,23 +471,23 @@ void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, break; if (i < var->cnsts_number) { - if (var->weight) + if (var->sharing_weight) lmm_decrease_concurrency(&var->cnsts[i]); if (cnst->sharing_policy) - var->cnsts[i].value += value; + var->cnsts[i].consumption_weight += value; else - var->cnsts[i].value = MAX(var->cnsts[i].value, value); + var->cnsts[i].consumption_weight = MAX(var->cnsts[i].consumption_weight, value); //We need to check that increasing value of the element does not cross the concurrency limit - if (var->weight){ + if (var->sharing_weight) { if(lmm_concurrency_slack(cnst)cnsts[i])){ - weight=var->weight; + weight = var->sharing_weight; lmm_disable_var(sys,var); for (int j = 0; j < var->cnsts_number; j++) lmm_on_disabled_var(sys,var->cnsts[j].constraint); var->staged_weight=weight; - xbt_assert(not var->weight); + xbt_assert(not var->sharing_weight); } lmm_increase_concurrency(&var->cnsts[i]); } @@ -508,7 +509,7 @@ lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t /*sys*/, lmm_variable_t var, 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); + return (var->cnsts[num].consumption_weight); else return 0.0; } @@ -621,8 +622,8 @@ static inline void saturated_variable_set_update(s_lmm_constraint_light_t *cnst_ xbt_swag_foreach(_elem, elem_list) { elem = (lmm_element_t)_elem; //Visiting active_element_set, so, by construction, should never get a zero weight, correct? - xbt_assert(elem->variable->weight > 0); - if ((elem->value > 0)) + xbt_assert(elem->variable->sharing_weight > 0); + if ((elem->consumption_weight > 0)) xbt_swag_insert(elem->variable, &(sys->saturated_variable_set)); } } @@ -645,7 +646,7 @@ void lmm_print(lmm_system_t sys) var_list = &(sys->variable_set); xbt_swag_foreach(_var, var_list) { var = (lmm_variable_t)_var; - buf = buf + "'" + std::to_string(var->id_int) + "'(" + std::to_string(var->weight) + ") "; + buf = buf + "'" + std::to_string(var->id_int) + "'(" + std::to_string(var->sharing_weight) + ") "; } buf += ")"; XBT_DEBUG("%20s", buf.c_str()); @@ -663,23 +664,23 @@ void lmm_print(lmm_system_t sys) buf += ((cnst->sharing_policy) ? "(" : "max("); xbt_swag_foreach(_elem, elem_list) { elem = (lmm_element_t)_elem; - buf = buf + std::to_string(elem->value) + ".'" + std::to_string(elem->variable->id_int) + "'(" + + buf = buf + std::to_string(elem->consumption_weight) + ".'" + std::to_string(elem->variable->id_int) + "'(" + std::to_string(elem->variable->value) + ")" + ((cnst->sharing_policy) ? " + " : " , "); if(cnst->sharing_policy) - sum += elem->value * elem->variable->value; + sum += elem->consumption_weight * elem->variable->value; else - sum = MAX(sum,elem->value * elem->variable->value); + sum = MAX(sum, elem->consumption_weight * elem->variable->value); } //TODO: Adding disabled elements only for test compatibility, but do we really want them to be printed? elem_list = &(cnst->disabled_element_set); xbt_swag_foreach(_elem, elem_list) { elem = (lmm_element_t)_elem; - buf = buf + std::to_string(elem->value) + ".'" + std::to_string(elem->variable->id_int) + "'(" + + buf = buf + std::to_string(elem->consumption_weight) + ".'" + std::to_string(elem->variable->id_int) + "'(" + std::to_string(elem->variable->value) + ")" + ((cnst->sharing_policy) ? " + " : " , "); if(cnst->sharing_policy) - sum += elem->value * elem->variable->value; + sum += elem->consumption_weight * elem->variable->value; else - sum = MAX(sum,elem->value * elem->variable->value); + sum = MAX(sum, elem->consumption_weight * elem->variable->value); } buf = buf + "0) <= " + std::to_string(cnst->bound) + " ('" + std::to_string(cnst->id_int) + "')"; @@ -700,11 +701,11 @@ void lmm_print(lmm_system_t sys) xbt_swag_foreach(_var, var_list) { var = (lmm_variable_t)_var; if (var->bound > 0) { - XBT_DEBUG("'%d'(%f) : %f (<=%f)", var->id_int, var->weight, var->value, var->bound); + XBT_DEBUG("'%d'(%f) : %f (<=%f)", var->id_int, var->sharing_weight, var->value, var->bound); xbt_assert(not double_positive(var->value - var->bound, var->bound * sg_maxmin_precision), "Incorrect value (%f is not smaller than %f", var->value, var->bound); } else { - XBT_DEBUG("'%d'(%f) : %f", var->id_int, var->weight, var->value); + XBT_DEBUG("'%d'(%f) : %f", var->id_int, var->sharing_weight, var->value); } } } @@ -739,7 +740,7 @@ void lmm_solve(lmm_system_t sys) //XBT_DEBUG("Variable set : %d", xbt_swag_size(elem_list)); xbt_swag_foreach(_elem, elem_list) { var = ((lmm_element_t)_elem)->variable; - xbt_assert(var->weight > 0.0); + xbt_assert(var->sharing_weight > 0.0); var->value = 0.0; } } @@ -762,12 +763,12 @@ void lmm_solve(lmm_system_t sys) elem_list = &(cnst->enabled_element_set); xbt_swag_foreach(_elem, elem_list) { elem = (lmm_element_t)_elem; - xbt_assert(elem->variable->weight > 0); - if ((elem->value > 0)) { + xbt_assert(elem->variable->sharing_weight > 0); + if ((elem->consumption_weight > 0)) { 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; + cnst->usage += elem->consumption_weight / elem->variable->sharing_weight; + else if (cnst->usage < elem->consumption_weight / elem->variable->sharing_weight) + cnst->usage = elem->consumption_weight / elem->variable->sharing_weight; make_elem_active(elem); simgrid::surf::Action *action = static_cast(elem->variable->id); @@ -799,17 +800,16 @@ void lmm_solve(lmm_system_t sys) xbt_swag_foreach(_var, var_list) { var = (lmm_variable_t)_var; - if (var->weight <= 0.0) + if (var->sharing_weight <= 0.0) DIE_IMPOSSIBLE; /* First check if some of these variables could reach their upper bound and update min_bound accordingly. */ - 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); - if ((var->bound > 0) && (var->bound * var->weight < min_usage)) { + XBT_DEBUG("var=%d, var->bound=%f, var->weight=%f, min_usage=%f, var->bound*var->weight=%f", var->id_int, + var->bound, var->sharing_weight, min_usage, var->bound * var->sharing_weight); + if ((var->bound > 0) && (var->bound * var->sharing_weight < min_usage)) { if (min_bound < 0) - min_bound = var->bound*var->weight; + min_bound = var->bound * var->sharing_weight; else - min_bound = MIN(min_bound, (var->bound*var->weight)); + min_bound = MIN(min_bound, (var->bound * var->sharing_weight)); XBT_DEBUG("Updated min_bound=%f", min_bound); } } @@ -820,14 +820,14 @@ void lmm_solve(lmm_system_t sys) if (min_bound < 0) { //If no variable could reach its bound, deal iteratively the constraints usage ( at worst one constraint is // saturated at each cycle) - var->value = min_usage / var->weight; + var->value = min_usage / var->sharing_weight; // XBT_DEBUG("Setting %p (%d) value to %f\n", var, var->id_int, var->value); XBT_DEBUG("Setting var (%d) value to %f\n", 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 (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); + if (double_equals(min_bound, var->bound * var->sharing_weight, sg_maxmin_precision)) { + var->value = var->bound; + XBT_DEBUG("Setting %p (%d) value to %f\n", var, var->id_int, var->value); } else { // Variables which bound is different are not considered for this cycle, but they will be afterwards. XBT_DEBUG("Do not consider %p (%d) \n", var, var->id_int); @@ -835,8 +835,8 @@ void lmm_solve(lmm_system_t sys) continue; } } - 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); + XBT_DEBUG("Min usage: %f, Var(%d)->weight: %f, Var(%d)->value: %f ", min_usage, var->id_int, var->sharing_weight, + var->id_int, var->value); /* Update the usage of contraints where this variable is involved */ for (i = 0; i < var->cnsts_number; i++) { @@ -844,8 +844,8 @@ void lmm_solve(lmm_system_t sys) cnst = elem->constraint; 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); + double_update(&(cnst->remaining), elem->consumption_weight * var->value, cnst->bound * sg_maxmin_precision); + double_update(&(cnst->usage), elem->consumption_weight / var->sharing_weight, sg_maxmin_precision); //If the constraint is saturated, remove it from the set of active constraints (light_tab) if (not double_positive(cnst->usage, sg_maxmin_precision) || not double_positive(cnst->remaining, cnst->bound * sg_maxmin_precision)) { @@ -872,10 +872,10 @@ void lmm_solve(lmm_system_t sys) elem_list = &(cnst->enabled_element_set); xbt_swag_foreach(_elem, elem_list) { elem = (lmm_element_t)_elem; - xbt_assert(elem->variable->weight > 0); + xbt_assert(elem->variable->sharing_weight > 0); if (elem->variable->value > 0) continue; - if (elem->value > 0) - cnst->usage = MAX(cnst->usage, elem->value / elem->variable->weight); + if (elem->consumption_weight > 0) + cnst->usage = MAX(cnst->usage, elem->consumption_weight / elem->variable->sharing_weight); } //If the constraint is saturated, remove it from the set of active constraints (light_tab) if (not double_positive(cnst->usage, sg_maxmin_precision) || @@ -997,7 +997,7 @@ void lmm_enable_var(lmm_system_t sys, lmm_variable_t var){ xbt_assert(lmm_can_enable_var(var)); - var->weight = var->staged_weight; + var->sharing_weight = var->staged_weight; var->staged_weight = 0; //Enabling the variable, move to var to list head. Subtility is: here, we need to call lmm_update_modified_set AFTER @@ -1041,7 +1041,7 @@ void lmm_disable_var(lmm_system_t sys, lmm_variable_t var){ lmm_decrease_concurrency(elem); } - var->weight=0.0; + var->sharing_weight = 0.0; var->staged_weight=0.0; var->value = 0.0; lmm_check_concurrency(sys); @@ -1100,11 +1100,11 @@ void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double wei xbt_assert(weight>=0,"Variable weight should not be negative!"); - if (weight == var->weight) + if (weight == var->sharing_weight) return; - int enabling_var= (weight>0 && var->weight<=0); - int disabling_var= (weight<=0 && var->weight>0); + int enabling_var = (weight > 0 && var->sharing_weight <= 0); + int disabling_var = (weight <= 0 && var->sharing_weight > 0); XBT_IN("(sys=%p, var=%p, weight=%f)", sys, var, weight); @@ -1125,7 +1125,7 @@ void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double wei //Are we disabling this variable? lmm_disable_var(sys,var); } else { - var->weight=weight; + var->sharing_weight = weight; } lmm_check_concurrency(sys); @@ -1135,7 +1135,7 @@ void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double wei double lmm_get_variable_weight(lmm_variable_t var) { - return var->weight; + return var->sharing_weight; } void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, double bound) @@ -1236,11 +1236,11 @@ double lmm_constraint_get_usage(lmm_constraint_t cnst) { xbt_swag_foreach(_elem, elem_list) { lmm_element_t elem = (lmm_element_t)_elem; - if (elem->value > 0) { + if (elem->consumption_weight > 0) { if (cnst->sharing_policy) - usage += elem->value * elem->variable->value; - else if (usage < elem->value * elem->variable->value) - usage = std::max(usage, elem->value * elem->variable->value); + usage += elem->consumption_weight * elem->variable->value; + else if (usage < elem->consumption_weight * elem->variable->value) + usage = std::max(usage, elem->consumption_weight * elem->variable->value); } } return usage; @@ -1252,7 +1252,7 @@ int lmm_constraint_get_variable_amount(lmm_constraint_t cnst) { xbt_swag_foreach(_elem, elem_list) { lmm_element_t elem = (lmm_element_t)_elem; - if (elem->value > 0) + if (elem->consumption_weight > 0) usage++; } return usage; @@ -1270,7 +1270,7 @@ void lmm_check_concurrency(lmm_system_t sys){ xbt_swag_foreach(elemIt, &(cnst->enabled_element_set)) { lmm_element_t elem = (lmm_element_t)elemIt; - xbt_assert(elem->variable->weight > 0); + xbt_assert(elem->variable->sharing_weight > 0); concurrency+=lmm_element_concurrency(elem); } diff --git a/src/surf/maxmin_private.hpp b/src/surf/maxmin_private.hpp index f0c93fb14d..c4e3f9cfc0 100644 --- a/src/surf/maxmin_private.hpp +++ b/src/surf/maxmin_private.hpp @@ -25,7 +25,11 @@ typedef struct lmm_element { lmm_constraint_t constraint; lmm_variable_t variable; - double value; + + // consumption_weight: impact of 1 byte or flop of your application onto the resource (in byte or flop) + // - if CPU, then probably 1. + // - If network, then 1 in forward direction and 0.05 backward for the ACKs + double consumption_weight; } s_lmm_element_t; #define make_elem_active(elem) xbt_swag_insert_at_head(elem,&(elem->constraint->active_element_set)) #define make_elem_inactive(elem) xbt_swag_remove(elem,&(elem->constraint->active_element_set)) @@ -82,7 +86,11 @@ typedef struct lmm_variable { s_lmm_element_t *cnsts; int cnsts_size; int cnsts_number; - double weight; /* weight > 0 means variable is considered by LMM, weight == 0 means variable is not considered by LMM*/ + // sharing_weight: variable's impact on the resource during the sharing + // if == 0, the variable is not considered by LMM + // on CPU, actions with N threads have a sharing of N + // on network, the actions with higher latency have a lesser sharing_weight + double sharing_weight; /* weight == 0 -> not considered by LMM; */ double staged_weight; /* If non-zero, variable is staged for addition as soon as maxconcurrency constraints will be met */ double bound; double value; -- 2.20.1