1 /* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/kernel/lmm/maxmin.hpp"
8 #include "xbt/sysdep.h"
13 #include <xbt/utility.hpp>
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_maxmin);
16 #define SHOW_EXPR_G(expr) XBT_DEBUG(#expr " = %g", expr);
17 #define SHOW_EXPR_D(expr) XBT_DEBUG(#expr " = %d", expr);
18 #define SHOW_EXPR_P(expr) XBT_DEBUG(#expr " = %p", expr);
20 simgrid::kernel::lmm::System* simgrid::kernel::lmm::make_new_fair_bottleneck_system(bool selective_update)
22 return new simgrid::kernel::lmm::FairBottleneck(selective_update);
25 void simgrid::kernel::lmm::FairBottleneck::bottleneck_solve()
30 XBT_DEBUG("Variable set : %zu", variable_set.size());
31 for (Variable& var : variable_set) {
33 XBT_DEBUG("Handling variable %p", &var);
34 if (var.sharing_weight > 0.0 && std::find_if(begin(var.cnsts), end(var.cnsts), [](Element const& x) {
35 return x.consumption_weight != 0.0;
36 }) != end(var.cnsts)) {
37 saturated_variable_set.push_back(var);
39 XBT_DEBUG("Err, finally, there is no need to take care of variable %p", &var);
40 if (var.sharing_weight > 0.0)
45 XBT_DEBUG("Active constraints : %zu", active_constraint_set.size());
46 for (Constraint& cnst : active_constraint_set) {
47 saturated_constraint_set.push_back(cnst);
49 for (Constraint& cnst : saturated_constraint_set) {
50 cnst.remaining = cnst.bound;
54 XBT_DEBUG("Fair bottleneck Initialized");
57 * Compute Usage and store the variables that reach the maximum.
59 auto& var_list = saturated_variable_set;
60 auto& cnst_list = saturated_constraint_set;
62 if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
63 XBT_DEBUG("Fair bottleneck done");
66 XBT_DEBUG("******* Constraints to process: %zu *******", cnst_list.size());
67 for (auto iter = std::begin(cnst_list); iter != std::end(cnst_list);) {
68 Constraint& cnst = *iter;
70 XBT_DEBUG("Processing cnst %p ", &cnst);
72 for (Element& elem : cnst.enabled_element_set) {
73 xbt_assert(elem.variable->sharing_weight > 0);
74 if (elem.consumption_weight > 0 && elem.variable->saturated_variable_set_hook.is_linked())
77 XBT_DEBUG("\tThere are %d variables", nb);
78 if (nb > 0 && not cnst.sharing_policy)
83 iter = cnst_list.erase(iter);
85 cnst.usage = cnst.remaining / nb;
86 XBT_DEBUG("\tConstraint Usage %p : %f with %d variables", &cnst, cnst.usage, nb);
91 for (auto iter = std::begin(var_list); iter != std::end(var_list);) {
92 Variable& var = *iter;
93 double min_inc = DBL_MAX;
94 for (Element const& elm : var.cnsts) {
95 if (elm.consumption_weight > 0)
96 min_inc = std::min(min_inc, elm.constraint->usage / elm.consumption_weight);
99 min_inc = std::min(min_inc, var.bound - var.value);
101 XBT_DEBUG("Updating variable %p maximum increment: %g", &var, var.mu);
103 if (var.value == var.bound)
104 iter = var_list.erase(iter);
109 for (auto iter = std::begin(cnst_list); iter != std::end(cnst_list);) {
110 Constraint& cnst = *iter;
111 XBT_DEBUG("Updating cnst %p ", &cnst);
112 if (cnst.sharing_policy) {
113 for (Element& elem : cnst.enabled_element_set) {
114 xbt_assert(elem.variable->sharing_weight > 0);
115 XBT_DEBUG("\tUpdate constraint %p (%g) with variable %p by %g", &cnst, cnst.remaining, elem.variable,
117 double_update(&cnst.remaining, elem.consumption_weight * elem.variable->mu, sg_maxmin_precision);
120 for (Element& elem : cnst.enabled_element_set) {
121 xbt_assert(elem.variable->sharing_weight > 0);
122 XBT_DEBUG("\tNon-Shared variable. Update constraint usage of %p (%g) with variable %p by %g", &cnst,
123 cnst.usage, elem.variable, elem.variable->mu);
124 cnst.usage = std::min(cnst.usage, elem.consumption_weight * elem.variable->mu);
126 XBT_DEBUG("\tUpdate constraint %p (%g) by %g", &cnst, cnst.remaining, cnst.usage);
127 double_update(&cnst.remaining, cnst.usage, sg_maxmin_precision);
130 XBT_DEBUG("\tRemaining for %p : %g", &cnst, cnst.remaining);
131 if (cnst.remaining <= 0.0) {
132 XBT_DEBUG("\tGet rid of constraint %p", &cnst);
134 iter = cnst_list.erase(iter);
135 for (Element& elem : cnst.enabled_element_set) {
136 if (elem.variable->sharing_weight <= 0)
138 if (elem.consumption_weight > 0 && elem.variable->saturated_variable_set_hook.is_linked()) {
139 XBT_DEBUG("\t\tGet rid of variable %p", elem.variable);
140 simgrid::xbt::intrusive_erase(var_list, *elem.variable);
147 } while (not var_list.empty());
151 if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
152 XBT_DEBUG("Fair bottleneck done");