#include <cstdlib>
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_maxmin);
-#define SHOW_EXPR_G(expr) XBT_DEBUG(#expr " = %g",expr);
-#define SHOW_EXPR_D(expr) XBT_DEBUG(#expr " = %d",expr);
-#define SHOW_EXPR_P(expr) XBT_DEBUG(#expr " = %p",expr);
+#define SHOW_EXPR_G(expr) XBT_DEBUG(#expr " = %g", expr);
+#define SHOW_EXPR_D(expr) XBT_DEBUG(#expr " = %d", expr);
+#define SHOW_EXPR_P(expr) XBT_DEBUG(#expr " = %p", expr);
void simgrid::surf::bottleneck_solve(lmm_system_t sys)
{
- void *_var;
- void *_var_next;
- void *_cnst;
- void *_cnst_next;
- void *_elem;
- lmm_variable_t var = nullptr;
+ void* _var;
+ void* _var_next;
+ void* _cnst;
+ void* _cnst_next;
+ void* _elem;
+ lmm_variable_t var = nullptr;
lmm_constraint_t cnst = nullptr;
s_lmm_constraint_t s_cnst;
- lmm_element_t elem = nullptr;
+ lmm_element_t elem = nullptr;
xbt_swag_t cnst_list = nullptr;
- xbt_swag_t var_list = nullptr;
+ xbt_swag_t var_list = nullptr;
xbt_swag_t elem_list = nullptr;
static s_xbt_swag_t cnst_to_update;
var_list = &(sys->variable_set);
XBT_DEBUG("Variable set : %d", xbt_swag_size(var_list));
- xbt_swag_foreach(_var, var_list) {
- var = static_cast<lmm_variable_t>(_var);
+ xbt_swag_foreach(_var, var_list)
+ {
+ var = static_cast<lmm_variable_t>(_var);
var->value = 0.0;
XBT_DEBUG("Handling variable %p", var);
xbt_swag_insert(var, &(sys->saturated_variable_set));
cnst_list = &(sys->active_constraint_set);
XBT_DEBUG("Active constraints : %d", xbt_swag_size(cnst_list));
- xbt_swag_foreach(_cnst, cnst_list) {
+ xbt_swag_foreach(_cnst, cnst_list)
+ {
cnst = static_cast<lmm_constraint_t>(_cnst);
xbt_swag_insert(cnst, &(sys->saturated_constraint_set));
}
cnst_list = &(sys->saturated_constraint_set);
- xbt_swag_foreach(_cnst, cnst_list) {
- cnst = static_cast<lmm_constraint_t>(_cnst);
+ xbt_swag_foreach(_cnst, cnst_list)
+ {
+ cnst = static_cast<lmm_constraint_t>(_cnst);
cnst->remaining = cnst->bound;
- cnst->usage = 0.0;
+ cnst->usage = 0.0;
}
XBT_DEBUG("Fair bottleneck Initialized");
sys->print();
}
XBT_DEBUG("******* Constraints to process: %d *******", xbt_swag_size(cnst_list));
- xbt_swag_foreach_safe(_cnst, _cnst_next, cnst_list) {
- cnst = static_cast<lmm_constraint_t>(_cnst);
+ xbt_swag_foreach_safe(_cnst, _cnst_next, cnst_list)
+ {
+ cnst = static_cast<lmm_constraint_t>(_cnst);
int nb = 0;
XBT_DEBUG("Processing cnst %p ", cnst);
- elem_list = &(cnst->enabled_element_set);
+ elem_list = &(cnst->enabled_element_set);
cnst->usage = 0.0;
- xbt_swag_foreach(_elem, elem_list) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
elem = static_cast<lmm_element_t>(_elem);
xbt_assert(elem->variable->sharing_weight > 0);
if ((elem->consumption_weight > 0) && xbt_swag_belongs(elem->variable, var_list))
nb = 1;
if (not nb) {
cnst->remaining = 0.0;
- cnst->usage = cnst->remaining;
+ cnst->usage = cnst->remaining;
xbt_swag_remove(cnst, cnst_list);
continue;
}
XBT_DEBUG("\tConstraint Usage %p : %f with %d variables", cnst, cnst->usage, nb);
}
- xbt_swag_foreach_safe(_var, _var_next, var_list) {
- var = static_cast<lmm_variable_t>(_var);
+ xbt_swag_foreach_safe(_var, _var_next, var_list)
+ {
+ var = static_cast<lmm_variable_t>(_var);
double min_inc = DBL_MAX;
for (s_lmm_element_t const& elm : var->cnsts) {
if (elm.consumption_weight > 0)
}
if (var->bound > 0)
min_inc = std::min(min_inc, var->bound - var->value);
- var->mu = min_inc;
+ var->mu = min_inc;
XBT_DEBUG("Updating variable %p maximum increment: %g", var, var->mu);
var->value += var->mu;
if (var->value == var->bound) {
}
}
- xbt_swag_foreach_safe(_cnst, _cnst_next, cnst_list) {
+ xbt_swag_foreach_safe(_cnst, _cnst_next, cnst_list)
+ {
cnst = static_cast<lmm_constraint_t>(_cnst);
XBT_DEBUG("Updating cnst %p ", cnst);
elem_list = &(cnst->enabled_element_set);
- xbt_swag_foreach(_elem, elem_list) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
elem = static_cast<lmm_element_t>(_elem);
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);
+ elem->variable->mu);
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);
+ 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 = std::min(cnst->usage, elem->consumption_weight * elem->variable->mu);
}
}
XBT_DEBUG("\tGet rid of constraint %p", cnst);
xbt_swag_remove(cnst, cnst_list);
- xbt_swag_foreach(_elem, elem_list) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
elem = static_cast<lmm_element_t>(_elem);
if (elem->variable->sharing_weight <= 0)
break;
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_lagrange, surf, "Logging specific to SURF (lagrange)");
XBT_LOG_NEW_SUBCATEGORY(surf_lagrange_dichotomy, surf_lagrange, "Logging specific to SURF (lagrange dichotomy)");
-#define SHOW_EXPR(expr) XBT_CDEBUG(surf_lagrange,#expr " = %g",expr);
+#define SHOW_EXPR(expr) XBT_CDEBUG(surf_lagrange, #expr " = %g", expr);
#define VEGAS_SCALING 1000.0
#define RENO_SCALING 1.0
#define RENO2_SCALING 1.0
namespace simgrid {
namespace surf {
-double (*func_f_def) (lmm_variable_t, double);
-double (*func_fp_def) (lmm_variable_t, double);
-double (*func_fpi_def) (lmm_variable_t, double);
+double (*func_f_def)(lmm_variable_t, double);
+double (*func_fp_def)(lmm_variable_t, double);
+double (*func_fpi_def)(lmm_variable_t, double);
/*
* Local prototypes to implement the Lagrangian optimization with optimal step, also called dichotomy.
*/
-//solves the proportional fairness using a Lagrangian optimization with dichotomy step
+// solves the proportional fairness using a Lagrangian optimization with dichotomy step
void lagrange_solve(lmm_system_t sys);
-//computes the value of the dichotomy using a initial values, init, with a specific variable or constraint
-static double dichotomy(double init, double diff(double, void *), void *var_cnst, double min_error);
-//computes the value of the differential of constraint param_cnst applied to lambda
-static double partial_diff_lambda(double lambda, void *param_cnst);
+// computes the value of the dichotomy using a initial values, init, with a specific variable or constraint
+static double dichotomy(double init, double diff(double, void*), void* var_cnst, double min_error);
+// computes the value of the differential of constraint param_cnst applied to lambda
+static double partial_diff_lambda(double lambda, void* param_cnst);
static int __check_feasible(xbt_swag_t cnst_list, xbt_swag_t var_list, int warn)
{
void* _cnst;
void* _elem;
void* _var;
- xbt_swag_t elem_list = nullptr;
- lmm_element_t elem = nullptr;
+ xbt_swag_t elem_list = nullptr;
+ lmm_element_t elem = nullptr;
lmm_constraint_t cnst = nullptr;
- lmm_variable_t var = nullptr;
+ lmm_variable_t var = nullptr;
- xbt_swag_foreach(_cnst, cnst_list) {
+ xbt_swag_foreach(_cnst, cnst_list)
+ {
cnst = static_cast<lmm_constraint_t>(_cnst);
double tmp = 0;
- elem_list = &(cnst->enabled_element_set);
- xbt_swag_foreach(_elem, elem_list) {
+ elem_list = &(cnst->enabled_element_set);
+ xbt_swag_foreach(_elem, elem_list)
+ {
elem = static_cast<lmm_element_t>(_elem);
- var = elem->variable;
+ var = elem->variable;
xbt_assert(var->sharing_weight > 0);
tmp += var->value;
}
if (double_positive(tmp - cnst->bound, sg_maxmin_precision)) {
if (warn)
- XBT_WARN ("The link (%p) is over-used. Expected less than %f and got %f", cnst, cnst->bound, tmp);
+ XBT_WARN("The link (%p) is over-used. Expected less than %f and got %f", cnst, cnst->bound, tmp);
return 0;
}
- XBT_DEBUG ("Checking feasability for constraint (%p): sat = %f, lambda = %f ", cnst, tmp - cnst->bound,
- cnst->lambda);
+ XBT_DEBUG("Checking feasability for constraint (%p): sat = %f, lambda = %f ", cnst, tmp - cnst->bound,
+ cnst->lambda);
}
- xbt_swag_foreach(_var, var_list) {
+ xbt_swag_foreach(_var, var_list)
+ {
var = static_cast<lmm_variable_t>(_var);
if (not var->sharing_weight)
break;
if (double_positive(var->value - var->bound, sg_maxmin_precision)) {
if (warn)
- XBT_WARN ("The variable (%p) is too large. Expected less than %f and got %f", var, var->bound, var->value);
+ XBT_WARN("The variable (%p) is too large. Expected less than %f and got %f", var, var->bound, var->value);
return 0;
}
}
if (var->bound > 0)
tmp += var->mu;
XBT_DEBUG("\t Working on var (%p). cost = %e; Weight = %e", var, tmp, var->sharing_weight);
- //uses the partial differential inverse function
+ // uses the partial differential inverse function
return var->func_fpi(var, tmp);
}
static double new_mu(lmm_variable_t var)
{
- double mu_i = 0.0;
+ double mu_i = 0.0;
double sigma_i = 0.0;
for (s_lmm_element_t const& elem : var->cnsts) {
static double dual_objective(xbt_swag_t var_list, xbt_swag_t cnst_list)
{
- void *_cnst;
- void *_var;
+ void* _cnst;
+ void* _var;
lmm_constraint_t cnst = nullptr;
- lmm_variable_t var = nullptr;
+ lmm_variable_t var = nullptr;
double obj = 0.0;
- xbt_swag_foreach(_var, var_list) {
- var = static_cast<lmm_variable_t>(_var);
+ xbt_swag_foreach(_var, var_list)
+ {
+ var = static_cast<lmm_variable_t>(_var);
double sigma_i = 0.0;
if (not var->sharing_weight)
obj += var->mu * var->bound;
}
- xbt_swag_foreach(_cnst, cnst_list) {
+ xbt_swag_foreach(_cnst, cnst_list)
+ {
cnst = static_cast<lmm_constraint_t>(_cnst);
obj += cnst->lambda * cnst->bound;
}
void lagrange_solve(lmm_system_t sys)
{
/* Lagrange Variables. */
- int max_iterations = 100;
- double epsilon_min_error = 0.00001; /* this is the precision on the objective function so it's none of the configurable values and this value is the legacy one */
- double dichotomy_min_error = 1e-14;
+ int max_iterations = 100;
+ double epsilon_min_error = 0.00001; /* this is the precision on the objective function so it's none of the
+ configurable values and this value is the legacy one */
+ double dichotomy_min_error = 1e-14;
double overall_modification = 1;
XBT_DEBUG("Iterative method configuration snapshot =====>");
/* Initialize lambda. */
xbt_swag_t cnst_list = &(sys->active_constraint_set);
void* _cnst;
- xbt_swag_foreach(_cnst, cnst_list) {
+ xbt_swag_foreach(_cnst, cnst_list)
+ {
lmm_constraint_t cnst = (lmm_constraint_t)_cnst;
- cnst->lambda = 1.0;
- cnst->new_lambda = 2.0;
+ cnst->lambda = 1.0;
+ cnst->new_lambda = 2.0;
XBT_DEBUG("#### cnst(%p)->lambda : %e", cnst, cnst->lambda);
}
*/
xbt_swag_t var_list = &(sys->variable_set);
void* _var;
- xbt_swag_foreach(_var, var_list) {
+ xbt_swag_foreach(_var, var_list)
+ {
lmm_variable_t var = static_cast<lmm_variable_t>(_var);
if (not var->sharing_weight)
var->value = 0.0;
else {
if (var->bound < 0.0) {
XBT_DEBUG("#### NOTE var(%p) is a boundless variable", var);
- var->mu = -1.0;
+ var->mu = -1.0;
} else {
var->mu = 1.0;
var->new_mu = 2.0;
XBT_DEBUG("-------------- Gradient Descent ----------");
/* Improve the value of mu_i */
- xbt_swag_foreach(_var, var_list) {
+ xbt_swag_foreach(_var, var_list)
+ {
lmm_variable_t var = static_cast<lmm_variable_t>(_var);
if (var->sharing_weight && var->bound >= 0) {
XBT_DEBUG("Working on var (%p)", var);
}
/* Improve the value of lambda_i */
- xbt_swag_foreach(_cnst, cnst_list) {
+ xbt_swag_foreach(_cnst, cnst_list)
+ {
lmm_constraint_t cnst = static_cast<lmm_constraint_t>(_cnst);
XBT_DEBUG("Working on cnst (%p)", cnst);
cnst->new_lambda = dichotomy(cnst->lambda, partial_diff_lambda, cnst, dichotomy_min_error);
/* Now computes the values of each variable (\rho) based on the values of \lambda and \mu. */
XBT_DEBUG("-------------- Check convergence ----------");
overall_modification = 0;
- xbt_swag_foreach(_var, var_list) {
+ xbt_swag_foreach(_var, var_list)
+ {
lmm_variable_t var = static_cast<lmm_variable_t>(_var);
if (var->sharing_weight <= 0)
var->value = 0.0;
XBT_DEBUG("The method converges in %d iterations.", iteration);
}
if (iteration >= max_iterations) {
- XBT_DEBUG ("Method reach %d iterations, which is the maximum number of iterations allowed.", iteration);
+ XBT_DEBUG("Method reach %d iterations, which is the maximum number of iterations allowed.", iteration);
}
if (XBT_LOG_ISENABLED(surf_lagrange, xbt_log_priority_debug)) {
*
* @return a double corresponding to the result of the dichotomy process
*/
-static double dichotomy(double init, double diff(double, void *), void *var_cnst, double min_error)
+static double dichotomy(double init, double diff(double, void*), void* var_cnst, double min_error)
{
- double min =init;
- double max= init;
+ double min = init;
+ double max = init;
double overall_error;
double middle;
double middle_diff;
double max_diff = diff(max, var_cnst);
while (overall_error > min_error) {
- XBT_CDEBUG(surf_lagrange_dichotomy, "[min, max] = [%1.20f, %1.20f] || diffmin, diffmax = %1.20f, %1.20f",
- min, max, min_diff, max_diff);
+ XBT_CDEBUG(surf_lagrange_dichotomy, "[min, max] = [%1.20f, %1.20f] || diffmin, diffmax = %1.20f, %1.20f", min, max,
+ min_diff, max_diff);
if (min_diff > 0 && max_diff > 0) {
if (min == max) {
XBT_CDEBUG(surf_lagrange_dichotomy, "Decreasing min");
- min = min / 2.0;
+ min = min / 2.0;
min_diff = diff(min, var_cnst);
} else {
XBT_CDEBUG(surf_lagrange_dichotomy, "Decreasing max");
- max = min;
+ max = min;
max_diff = min_diff;
}
} else if (min_diff < 0 && max_diff < 0) {
if (min == max) {
XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing max");
- max = max * 2.0;
+ max = max * 2.0;
max_diff = diff(max, var_cnst);
} else {
XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing min");
- min = max;
+ min = max;
min_diff = max_diff;
}
} else if (min_diff < 0 && max_diff > 0) {
middle = (max + min) / 2.0;
XBT_CDEBUG(surf_lagrange_dichotomy, "Trying (max+min)/2 : %1.20f", middle);
- if ((fabs(min - middle) < 1e-20) || (fabs(max - middle) < 1e-20)){
- XBT_CWARN(surf_lagrange_dichotomy, "Cannot improve the convergence! min=max=middle=%1.20f, diff = %1.20f."
+ if ((fabs(min - middle) < 1e-20) || (fabs(max - middle) < 1e-20)) {
+ XBT_CWARN(surf_lagrange_dichotomy,
+ "Cannot improve the convergence! min=max=middle=%1.20f, diff = %1.20f."
" Reaching the 'double' limits. Maybe scaling your function would help ([%1.20f,%1.20f]).",
min, max - min, min_diff, max_diff);
break;
if (middle_diff < 0) {
XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing min");
- min = middle;
+ min = middle;
overall_error = max_diff - middle_diff;
- min_diff = middle_diff;
+ min_diff = middle_diff;
} else if (middle_diff > 0) {
XBT_CDEBUG(surf_lagrange_dichotomy, "Decreasing max");
- max = middle;
+ max = middle;
overall_error = max_diff - middle_diff;
- max_diff = middle_diff;
+ max_diff = middle_diff;
} else {
overall_error = 0;
}
} else if (fabs(min_diff) < 1e-20) {
- max = min;
+ max = min;
overall_error = 0;
} else if (fabs(max_diff) < 1e-20) {
- min = max;
+ min = max;
overall_error = 0;
} else if (min_diff > 0 && max_diff < 0) {
XBT_CWARN(surf_lagrange_dichotomy, "The impossible happened, partial_diff(min) > 0 && partial_diff(max) < 0");
xbt_abort();
} else {
XBT_CWARN(surf_lagrange_dichotomy,
- "diffmin (%1.20f) or diffmax (%1.20f) are something I don't know, taking no action.",
- min_diff, max_diff);
+ "diffmin (%1.20f) or diffmax (%1.20f) are something I don't know, taking no action.", min_diff,
+ max_diff);
xbt_abort();
}
}
return ((min + max) / 2.0);
}
-static double partial_diff_lambda(double lambda, void *param_cnst)
+static double partial_diff_lambda(double lambda, void* param_cnst)
{
lmm_constraint_t cnst = static_cast<lmm_constraint_t>(param_cnst);
- double diff = 0.0;
+ double diff = 0.0;
XBT_IN();
xbt_swag_t elem_list = &(cnst->enabled_element_set);
void* _elem;
- xbt_swag_foreach(_elem, elem_list) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
lmm_element_t elem = static_cast<lmm_element_t>(_elem);
lmm_variable_t var = elem->variable;
xbt_assert(var->sharing_weight > 0);
sigma_i += elem.constraint->lambda;
}
- //add mu_i if this flow has a RTT constraint associated
+ // add mu_i if this flow has a RTT constraint associated
if (var->bound > 0)
sigma_i += var->mu;
- //replace value of cnst->lambda by the value of parameter lambda
+ // replace value of cnst->lambda by the value of parameter lambda
sigma_i = (sigma_i - cnst->lambda) + lambda;
diff += -var->func_fpi(var, sigma_i);
* programming.
*
*/
-void lmm_set_default_protocol_function(double (*func_f) (lmm_variable_t var, double x),
- double (*func_fp) (lmm_variable_t var, double x),
- double (*func_fpi) (lmm_variable_t var, double x))
+void lmm_set_default_protocol_function(double (*func_f)(lmm_variable_t var, double x),
+ double (*func_fp)(lmm_variable_t var, double x),
+ double (*func_fpi)(lmm_variable_t var, double x))
{
- func_f_def = func_f;
- func_fp_def = func_fp;
+ func_f_def = func_f;
+ func_fp_def = func_fp;
func_fpi_def = func_fpi;
}
int s_lmm_element_t::get_concurrency() const
{
- //Ignore element with weight less than one (e.g. cross-traffic)
+ // Ignore element with weight less than one (e.g. cross-traffic)
return (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.
- //Potential examples are:
- //return (elem->weight>0)?1:0;//Include element as soon as weight is non-zero
- //return (int)ceil(elem->weight);//Include element as the rounded-up integer value of the element weight
+ // 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.
+ // Potential examples are:
+ // return (elem->weight>0)?1:0;//Include element as soon as weight is non-zero
+ // return (int)ceil(elem->weight);//Include element as the rounded-up integer value of the element weight
}
void s_lmm_element_t::decrease_concurrency()
s_lmm_variable_t var;
s_lmm_constraint_t cnst;
- modified = false;
- visited_counter = 1;
+ modified = false;
+ visited_counter = 1;
XBT_DEBUG("Setting selective_update_active flag to %d", selective_update_active);
{
modified = true;
- //Check if this variable already has an active element in this constraint
- //If it does, substract it from the required slack
+ // Check if this variable already has an active element in this constraint
+ // If it does, substract it from the required slack
int current_share = 0;
- if(var->concurrency_share>1){
+ if (var->concurrency_share > 1) {
for (s_lmm_element_t& elem : var->cnsts) {
if (elem.constraint == cnst && xbt_swag_belongs(&elem, &(elem.constraint->enabled_element_set)))
current_share += elem.get_concurrency();
}
}
- //Check if we need to disable the variable
+ // Check if we need to disable the variable
if (var->sharing_weight > 0 && var->concurrency_share - current_share > cnst->get_concurrency_slack()) {
double weight = var->sharing_weight;
disable_var(var);
for (s_lmm_element_t const& elem : var->cnsts)
on_disabled_var(elem.constraint);
consumption_weight = 0;
- var->staged_weight=weight;
+ var->staged_weight = weight;
xbt_assert(not var->sharing_weight);
}
} else if (elem.consumption_weight > 0 || var->sharing_weight > 0) {
make_constraint_active(cnst);
update_modified_set(cnst);
- //TODOLATER: Why do we need this second call?
+ // TODOLATER: Why do we need this second call?
if (var->cnsts.size() > 1)
update_modified_set(var->cnsts[0].constraint);
}
check_concurrency();
- //BEWARE: In case you have multiple elements in one constraint, this will always add value to the first element.
+ // BEWARE: In case you have multiple elements in one constraint, this will always add value to the first element.
auto elem_it = std::find_if(begin(var->cnsts), end(var->cnsts),
[&cnst](s_lmm_element_t const& x) { return x.constraint == cnst; });
if (elem_it != end(var->cnsts)) {
else
elem.consumption_weight = std::max(elem.consumption_weight, value);
- //We need to check that increasing value of the element does not cross the concurrency limit
+ // We need to check that increasing value of the element does not cross the concurrency limit
if (var->sharing_weight) {
if (cnst->get_concurrency_slack() < elem.get_concurrency()) {
double weight = var->sharing_weight;
disable_var(var);
for (s_lmm_element_t const& elem2 : var->cnsts)
on_disabled_var(elem2.constraint);
- var->staged_weight=weight;
+ var->staged_weight = weight;
xbt_assert(not var->sharing_weight);
}
elem.increase_concurrency();
if (*elem == nullptr)
*elem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set);
} else {
- //elem is not null, so we carry on
+ // elem is not null, so we carry on
if (xbt_swag_belongs(*elem, &enabled_element_set)) {
- //Look at enabled_element_set, and jump to disabled_element_set when finished
+ // Look at enabled_element_set, and jump to disabled_element_set when finished
*elem = (lmm_element_t)xbt_swag_getNext(*elem, enabled_element_set.offset);
if (*elem == nullptr)
*elem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set);
return nullptr;
}
-//if we modify the swag between calls, normal version may loop forever
-//this safe version ensures that we browse the swag elements only once
+// 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 s_lmm_constraint_t::get_variable_safe(lmm_element_t* elem, lmm_element_t* nextelem, int* numelem) const
{
if (*elem == nullptr) {
*numelem = xbt_swag_size(&enabled_element_set) + xbt_swag_size(&disabled_element_set) - 1;
if (*elem == nullptr)
*elem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set);
- }else{
+ } else {
*elem = *nextelem;
- if(*numelem>0){
- (*numelem) --;
- }else
+ if (*numelem > 0) {
+ (*numelem)--;
+ } else
return nullptr;
}
- if (*elem){
- //elem is not null, so we carry on
+ if (*elem) {
+ // elem is not null, so we carry on
if (xbt_swag_belongs(*elem, &enabled_element_set)) {
- //Look at enabled_element_set, and jump to disabled_element_set when finished
+ // Look at enabled_element_set, and jump to disabled_element_set when finished
*nextelem = (lmm_element_t)xbt_swag_getNext(*elem, enabled_element_set.offset);
if (*nextelem == nullptr)
*nextelem = (lmm_element_t)xbt_swag_getFirst(&disabled_element_set);
*nextelem = (lmm_element_t)xbt_swag_getNext(*elem, disabled_element_set.offset);
}
return (*elem)->variable;
- }else
+ } else
return nullptr;
}
static inline void saturated_constraints_update(double usage, int cnst_light_num, dyn_light_t& saturated_constraints,
double* min_usage)
{
- xbt_assert(usage > 0,"Impossible");
+ xbt_assert(usage > 0, "Impossible");
if (*min_usage < 0 || *min_usage > usage) {
*min_usage = usage;
static inline void saturated_variable_set_update(s_lmm_constraint_light_t* cnst_light_tab,
const dyn_light_t& saturated_constraints, lmm_system_t sys)
{
- /* Add active variables (i.e. variables that need to be set) from the set of constraints to saturate (cnst_light_tab)*/
+ /* Add active variables (i.e. variables that need to be set) from the set of constraints to saturate
+ * (cnst_light_tab)*/
for (int const& saturated_cnst : saturated_constraints) {
lmm_constraint_light_t cnst = &cnst_light_tab[saturated_cnst];
void* _elem;
xbt_swag_t elem_list = &(cnst->cnst->active_element_set);
- xbt_swag_foreach(_elem, elem_list) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
lmm_element_t elem = (lmm_element_t)_elem;
- //Visiting active_element_set, so, by construction, should never get a zero weight, correct?
+ // Visiting active_element_set, so, by construction, should never get a zero weight, correct?
xbt_assert(elem->variable->sharing_weight > 0);
if (elem->consumption_weight > 0)
xbt_swag_insert(elem->variable, &(sys->saturated_variable_set));
void s_lmm_system_t::print()
{
- std::string buf = std::string("MAX-MIN ( ");
+ std::string buf = std::string("MAX-MIN ( ");
void* _var;
/* Printing Objective */
xbt_swag_t var_list = &variable_set;
- xbt_swag_foreach(_var, var_list) {
+ xbt_swag_foreach(_var, var_list)
+ {
lmm_variable_t var = (lmm_variable_t)_var;
- buf = buf + "'" + std::to_string(var->id_int) + "'(" + std::to_string(var->sharing_weight) + ") ";
+ buf = buf + "'" + std::to_string(var->id_int) + "'(" + std::to_string(var->sharing_weight) + ") ";
}
buf += ")";
XBT_DEBUG("%20s", buf.c_str());
/* Printing Constraints */
void* _cnst;
xbt_swag_t cnst_list = &active_constraint_set;
- xbt_swag_foreach(_cnst, cnst_list) {
+ xbt_swag_foreach(_cnst, cnst_list)
+ {
lmm_constraint_t cnst = (lmm_constraint_t)_cnst;
- double sum = 0.0;
- //Show the enabled variables
+ double sum = 0.0;
+ // Show the enabled variables
void* _elem;
xbt_swag_t elem_list = &(cnst->enabled_element_set);
buf += "\t";
buf += ((cnst->sharing_policy) ? "(" : "max(");
- xbt_swag_foreach(_elem, elem_list) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
lmm_element_t elem = (lmm_element_t)_elem;
- buf = buf + std::to_string(elem->consumption_weight) + ".'" + 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)
+ if (cnst->sharing_policy)
sum += elem->consumption_weight * elem->variable->value;
else
sum = std::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?
+ // 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) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
lmm_element_t elem = (lmm_element_t)_elem;
- buf = buf + std::to_string(elem->consumption_weight) + ".'" + 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)
+ if (cnst->sharing_policy)
sum += elem->consumption_weight * elem->variable->value;
else
sum = std::max(sum, elem->consumption_weight * elem->variable->value);
XBT_DEBUG("Variables");
/* Printing Result */
- xbt_swag_foreach(_var, var_list) {
+ xbt_swag_foreach(_var, var_list)
+ {
lmm_variable_t var = (lmm_variable_t)_var;
if (var->bound > 0) {
XBT_DEBUG("'%d'(%f) : %f (<=%f)", var->id_int, var->sharing_weight, var->value, var->bound);
XBT_DEBUG("Active constraints : %d", xbt_swag_size(cnst_list));
/* Init: Only modified code portions: reset the value of active variables */
- xbt_swag_foreach(_cnst, cnst_list) {
+ xbt_swag_foreach(_cnst, cnst_list)
+ {
lmm_constraint_t cnst = (lmm_constraint_t)_cnst;
xbt_swag_t elem_list = &(cnst->enabled_element_set);
- xbt_swag_foreach(_elem, elem_list) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
lmm_variable_t var = ((lmm_element_t)_elem)->variable;
xbt_assert(var->sharing_weight > 0.0);
var->value = 0.0;
}
s_lmm_constraint_light_t* cnst_light_tab = new s_lmm_constraint_light_t[xbt_swag_size(cnst_list)]();
- int cnst_light_num = 0;
+ int cnst_light_num = 0;
dyn_light_t saturated_constraints;
- xbt_swag_foreach_safe(_cnst, _cnst_next, cnst_list) {
+ xbt_swag_foreach_safe(_cnst, _cnst_next, cnst_list)
+ {
lmm_constraint_t cnst = (lmm_constraint_t)_cnst;
/* INIT: Collect constraints that actually need to be saturated (i.e remaining and usage are strictly positive)
* into cnst_light_tab. */
cnst->remaining = cnst->bound;
if (not double_positive(cnst->remaining, cnst->bound * sg_maxmin_precision))
continue;
- cnst->usage = 0;
+ cnst->usage = 0;
xbt_swag_t elem_list = &(cnst->enabled_element_set);
- xbt_swag_foreach(_elem, elem_list) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
lmm_element_t elem = (lmm_element_t)_elem;
xbt_assert(elem->variable->sharing_weight > 0);
if (elem->consumption_weight > 0) {
cnst->usage = elem->consumption_weight / elem->variable->sharing_weight;
elem->make_active();
- simgrid::surf::Action *action = static_cast<simgrid::surf::Action*>(elem->variable->id);
+ simgrid::surf::Action* action = static_cast<simgrid::surf::Action*>(elem->variable->id);
if (keep_track && not action->is_linked())
keep_track->push_back(*action);
}
cnst->remaining, cnst->concurrency_current, cnst->concurrency_maximum, cnst->get_concurrency_limit());
/* Saturated constraints update */
- if(cnst->usage > 0) {
- cnst_light_tab[cnst_light_num].cnst = cnst;
- cnst->cnst_light = &(cnst_light_tab[cnst_light_num]);
+ 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_constraints_update(cnst_light_tab[cnst_light_num].remaining_over_usage, cnst_light_num,
saturated_constraints, &min_usage);
- xbt_assert(cnst->active_element_set.count>0, "There is no sense adding a constraint that has no active element!");
+ xbt_assert(cnst->active_element_set.count > 0,
+ "There is no sense adding a constraint that has no active element!");
cnst_light_num++;
}
}
xbt_swag_t var_list = &saturated_variable_set;
void* _var;
lmm_variable_t var = nullptr;
- xbt_swag_foreach(_var, var_list) {
+ xbt_swag_foreach(_var, var_list)
+ {
var = (lmm_variable_t)_var;
if (var->sharing_weight <= 0.0)
DIE_IMPOSSIBLE;
while ((var = (lmm_variable_t)xbt_swag_getFirst(var_list))) {
if (min_bound < 0) {
- //If no variable could reach its bound, deal iteratively the constraints usage ( at worst one constraint is
+ // 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->sharing_weight;
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->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);
- xbt_swag_remove(var, var_list);
- continue;
- }
+ // 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->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);
+ xbt_swag_remove(var, var_list);
+ continue;
+ }
}
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);
if (not double_positive(cnst->usage, sg_maxmin_precision) ||
not double_positive(cnst->remaining, cnst->bound * sg_maxmin_precision)) {
if (cnst->cnst_light) {
- int index = (cnst->cnst_light-cnst_light_tab);
- XBT_DEBUG("index: %d \t cnst_light_num: %d \t || usage: %f remaining: %f bound: %f ",
- index,cnst_light_num, cnst->usage, cnst->remaining, cnst->bound);
- cnst_light_tab[index]=cnst_light_tab[cnst_light_num-1];
+ int index = (cnst->cnst_light - cnst_light_tab);
+ XBT_DEBUG("index: %d \t cnst_light_num: %d \t || usage: %f remaining: %f bound: %f ", index,
+ cnst_light_num, cnst->usage, cnst->remaining, cnst->bound);
+ 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 = nullptr;
cnst->usage = 0.0;
elem.make_inactive();
xbt_swag_t elem_list = &(cnst->enabled_element_set);
- xbt_swag_foreach(_elem, elem_list) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
lmm_element_t elem2 = static_cast<lmm_element_t>(_elem);
xbt_assert(elem2->variable->sharing_weight > 0);
if (elem2->variable->value > 0)
if (elem2->consumption_weight > 0)
cnst->usage = std::max(cnst->usage, elem2->consumption_weight / elem2->variable->sharing_weight);
}
- //If the constraint is saturated, remove it from the set of active constraints (light_tab)
+ // 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)) {
- if(cnst->cnst_light) {
- int index = (cnst->cnst_light-cnst_light_tab);
+ 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 usage: %f remaining: %f bound: %f ", index,cnst_light_num, cnst,
- cnst->cnst_light, cnst_light_tab, cnst->usage, cnst->remaining, cnst->bound);
- cnst_light_tab[index]=cnst_light_tab[cnst_light_num-1];
+ "\t cnst_light_tab: %p usage: %f remaining: %f bound: %f ",
+ index, cnst_light_num, cnst, cnst->cnst_light, cnst_light_tab, cnst->usage, cnst->remaining,
+ cnst->bound);
+ 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 = nullptr;
}
} else {
cnst->cnst_light->remaining_over_usage = cnst->remaining / cnst->usage;
- xbt_assert(cnst->active_element_set.count>0, "Should not keep a maximum constraint that has no active"
- " element! You want to check the maxmin precision and possible rounding effects." );
+ xbt_assert(cnst->active_element_set.count > 0,
+ "Should not keep a maximum constraint that has no active"
+ " element! You want to check the maxmin precision and possible rounding effects.");
}
}
}
min_bound = -1;
saturated_constraints.clear();
int pos;
- for(pos=0; pos<cnst_light_num; pos++){
- xbt_assert(cnst_light_tab[pos].cnst->active_element_set.count>0, "Cannot saturate more a constraint that has"
+ for (pos = 0; pos < cnst_light_num; pos++) {
+ 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:<new_value>)"
" 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);
+ cnst_light_tab[pos].cnst->usage, sg_maxmin_precision, cnst_light_tab[pos - 1].cnst->usage);
saturated_constraints_update(cnst_light_tab[pos].remaining_over_usage, pos, saturated_constraints, &min_usage);
}
return minslack;
}
-//Small remark: In this implementation of lmm_enable_var and lmm_disable_var, we will meet multiple times with var when
+// Small remark: In this implementation of lmm_enable_var and lmm_disable_var, we will meet multiple times with var when
// running sys->update_modified_set.
// A priori not a big performance issue, but we might do better by calling sys->update_modified_set within the for loops
// (after doing the first for enabling==1, and before doing the last for disabling==1)
xbt_assert(not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug) || var->can_enable());
var->sharing_weight = var->staged_weight;
- var->staged_weight = 0;
+ var->staged_weight = 0;
// Enabling the variable, move to var to list head. Subtlety is: here, we need to call update_modified_set AFTER
// moving at least one element of var.
}
var->sharing_weight = 0.0;
- var->staged_weight=0.0;
- var->value = 0.0;
+ var->staged_weight = 0.0;
+ var->value = 0.0;
check_concurrency();
}
lmm_element_t elem = (lmm_element_t)xbt_swag_getFirst(&(cnstr->disabled_element_set));
- //Cannot use xbt_swag_foreach, because lmm_enable_var will modify disabled_element_set.. within the loop
+ // Cannot use xbt_swag_foreach, because lmm_enable_var will modify disabled_element_set.. within the loop
while (numelem-- && elem) {
lmm_element_t nextelem = (lmm_element_t)xbt_swag_getNext(elem, cnstr->disabled_element_set.offset);
if (elem->variable->staged_weight > 0 && elem->variable->can_enable()) {
- //Found a staged variable
- //TODOLATER: Add random timing function to model reservation protocol fuzziness? Then how to make sure that
- //staged variables will eventually be called?
+ // Found a staged variable
+ // TODOLATER: Add random timing function to model reservation protocol fuzziness? Then how to make sure that
+ // staged variables will eventually be called?
enable_var(elem->variable);
}
elem = nextelem;
}
- //We could get an assertion fail, because transiently there can be variables that are staged and could be activated.
- //And we need to go through all constraints of the disabled var before getting back a coherent state.
+ // We could get an assertion fail, because transiently there can be variables that are staged and could be activated.
+ // And we need to go through all constraints of the disabled var before getting back a coherent state.
// Anyway, caller functions all call check_concurrency() in the end.
}
*/
void s_lmm_system_t::update_variable_weight(lmm_variable_t var, double weight)
{
- xbt_assert(weight>=0,"Variable weight should not be negative!");
+ xbt_assert(weight >= 0, "Variable weight should not be negative!");
if (weight == var->sharing_weight)
return;
modified = true;
- //Are we enabling this variable?
- if (enabling_var){
+ // Are we enabling this variable?
+ if (enabling_var) {
var->staged_weight = weight;
int minslack = var->get_min_concurrency_slack();
if (minslack < var->concurrency_share) {
XBT_DEBUG("Staging var (instead of enabling) because min concurrency slack %i, with weight %f and concurrency"
- " share %i", minslack, weight, var->concurrency_share);
+ " share %i",
+ minslack, weight, var->concurrency_share);
return;
}
XBT_DEBUG("Enabling var with min concurrency slack %i", minslack);
enable_var(var);
- } else if (disabling_var){
- //Are we disabling this variable?
+ } else if (disabling_var) {
+ // Are we disabling this variable?
disable_var(var);
} else {
var->sharing_weight = weight;
{
void* _elem;
- xbt_swag_foreach(_elem, &cnst->enabled_element_set) {
+ xbt_swag_foreach(_elem, &cnst->enabled_element_set)
+ {
lmm_variable_t var = ((lmm_element_t)_elem)->variable;
for (s_lmm_element_t const& elem : var->cnsts) {
if (var->visited == visited_counter)
update_modified_set_rec(elem.constraint);
}
}
- //var will be ignored in later visits as long as sys->visited_counter does not move
+ // var will be ignored in later visits as long as sys->visited_counter does not move
var->visited = visited_counter;
}
}
// (i.e. not readibily reproducible, and requiring a lot of run time before happening).
if (++visited_counter == 1) {
/* the counter wrapped around, reset each variable->visited */
- void *_var;
- xbt_swag_foreach(_var, &variable_set)
- ((lmm_variable_t)_var)->visited = 0;
+ void* _var;
+ xbt_swag_foreach(_var, &variable_set)((lmm_variable_t)_var)->visited = 0;
}
xbt_swag_reset(&modified_constraint_set);
}
{
int result = 0;
const_xbt_swag_t elem_list = &enabled_element_set;
- void *_elem;
+ void* _elem;
- xbt_swag_foreach(_elem, elem_list) {
+ xbt_swag_foreach(_elem, elem_list)
+ {
lmm_element_t elem = (lmm_element_t)_elem;
if (elem->consumption_weight > 0)
result++;