}
/** @{ @ingroup SURF_lmm */
-/**
- * @brief Create a new Linear MaxMim system
- * @param selective_update whether we should do lazy updates
- */
-XBT_PUBLIC(lmm_system_t) lmm_system_new(bool selective_update);
-
-/**
- * @brief Free an existing Linear MaxMin system
- * @param sys The lmm system to free
- */
-XBT_PUBLIC(void) lmm_system_free(lmm_system_t sys);
-
-/**
- * @brief Create a new Linear MaxMin constraint
- * @param sys The system in which we add a constraint
- * @param id Data associated to the constraint (e.g.: a network link)
- * @param bound_value The bound value of the constraint
- */
-XBT_PUBLIC(lmm_constraint_t) lmm_constraint_new(lmm_system_t sys, void* id, double bound_value);
/**
* @brief Share a constraint
*/
XBT_PUBLIC(int) lmm_constraint_concurrency_maximum_get(lmm_constraint_t cnst);
-/**
- * @brief Create a new Linear MaxMin variable
- * @param sys The system in which we add a constaint
- * @param id Data associated to the variable (e.g.: a network communication)
- * @param weight_value The weight of the variable (0.0 if not used)
- * @param bound The maximum value of the variable (-1.0 if no maximum value)
- * @param number_of_constraints The maximum number of constraint to associate to the variable
- */
-XBT_PUBLIC(lmm_variable_t)
-lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, double weight_value, double bound,
- int number_of_constraints);
-/**
- * @brief Free a variable
- * @param sys The system associated to the variable
- * @param var The variable to free
- */
-XBT_PUBLIC(void) lmm_variable_free(lmm_system_t sys, lmm_variable_t var);
-
/**
* @brief Get the value of the variable after the last lmm solve
* @param var A variable
*/
XBT_PUBLIC(void) lmm_variable_concurrency_share_set(lmm_variable_t var, short int concurrency_share);
-/**
- * @brief Associate a variable to a constraint with a coefficient
- * @param sys A system
- * @param cnst A constraint
- * @param var A variable
- * @param value The coefficient associated to the variable in the constraint
- */
-XBT_PUBLIC(void) lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value);
-
-/**
- * @brief Add value to the coefficient between a constraint and a variable or create one
- * @param sys A system
- * @param cnst A constraint
- * @param var A variable
- * @param value The value to add to the coefficient associated to the variable in the constraint
- */
-XBT_PUBLIC(void) lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value);
-
/**
* @brief Get the numth constraint associated to the variable
* @param sys The system associated to the variable (not used)
*/
XBT_PUBLIC(void*) lmm_variable_id(lmm_variable_t var);
-/**
- * @brief Update the value of element linking the constraint and the variable
- * @param sys A system
- * @param cnst A constraint
- * @param var A variable
- * @param value The new value
- */
-XBT_PUBLIC(void) lmm_update(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value);
-
-/**
- * @brief Update the bound of a variable
- * @param sys A system
- * @param var A constraint
- * @param bound The new bound
- */
-XBT_PUBLIC(void) lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var, double bound);
-
-/**
- * @brief Update the weight of a variable
- * @param sys A system
- * @param var A variable
- * @param weight The new weight of the variable
- */
-XBT_PUBLIC(void) lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double weight);
-
/**
* @brief Get the weight of a variable
* @param var A variable
*/
XBT_PUBLIC(double) lmm_get_variable_weight(lmm_variable_t var);
-/**
- * @brief Update a constraint bound
- * @param sys A system
- * @param cnst A constraint
- * @param bound The new bound of the consrtaint
- */
-XBT_PUBLIC(void) lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, double bound);
-
-/**
- * @brief [brief description]
- * @param sys A system
- * @param cnst A constraint
- * @return [description]
- */
-XBT_PUBLIC(int) lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst);
-
-/**
- * @brief Print the lmm system
- * @param sys The lmm system to print
- */
-XBT_PUBLIC(void) lmm_print(lmm_system_t sys);
-
/**
* @brief Solve the lmm system
* @param sys The lmm system to solve
xbt_assert(cpu->model() == surf_cpu_model_vm);
lmm_system_t vcpu_system = cpu->model()->getMaxminSystem();
- lmm_update_constraint_bound(vcpu_system, cpu->constraint(), virt_overhead * solved_value);
+ vcpu_system->update_constraint_bound(cpu->constraint(), virt_overhead * solved_value);
}
/* 2. Calculate resource share at the virtual machine layer. */
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "StorageImpl.hpp"
+#include "maxmin_private.hpp"
#include "surf_private.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module");
StorageModel::StorageModel() : Model()
{
- maxminSystem_ = lmm_system_new(true /* lazy update */);
+ maxminSystem_ = new s_lmm_system_t(true /* lazy update */);
}
StorageModel::~StorageModel()
{
- lmm_system_free(maxminSystem_);
+ delete maxminSystem_;
surf_storage_model = nullptr;
}
StorageImpl::StorageImpl(Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite,
std::string type_id, std::string content_name, sg_size_t size, std::string attach)
- : Resource(model, name.c_str(), lmm_constraint_new(maxminSystem, this, std::max(bread, bwrite)))
+ : Resource(model, name.c_str(), maxminSystem->constraint_new(this, std::max(bread, bwrite)))
, piface_(this)
, typeId_(type_id)
, content_name(content_name)
{
StorageImpl::turnOn();
XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
- constraintRead_ = lmm_constraint_new(maxminSystem, this, bread);
- constraintWrite_ = lmm_constraint_new(maxminSystem, this, bwrite);
+ constraintRead_ = maxminSystem->constraint_new(this, bread);
+ constraintWrite_ = maxminSystem->constraint_new(this, bwrite);
storages->insert({name, this});
}
}
p_cpuRunningActionSetThatDoesNotNeedBeingChecked = new ActionList();
- maxminSystem_ = lmm_system_new(selectiveUpdate_);
+ maxminSystem_ = new s_lmm_system_t(selectiveUpdate_);
if (getUpdateMechanism() == UM_LAZY) {
modifiedSet_ = new ActionLmmList();
CpuCas01Model::~CpuCas01Model()
{
- lmm_system_free(maxminSystem_);
+ delete maxminSystem_;
maxminSystem_ = nullptr;
delete modifiedSet_;
/************
* Resource *
************/
-CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core)
-: Cpu(model, host, lmm_constraint_new(model->getMaxminSystem(), this, core * speedPerPstate->front()),
- speedPerPstate, core)
+CpuCas01::CpuCas01(CpuCas01Model* model, simgrid::s4u::Host* host, std::vector<double>* speedPerPstate, int core)
+ : Cpu(model, host, model->getMaxminSystem()->constraint_new(this, core * speedPerPstate->front()), speedPerPstate,
+ core)
{
}
bool CpuCas01::isUsed()
{
- return lmm_constraint_used(model()->getMaxminSystem(), constraint());
+ return model()->getMaxminSystem()->constraint_used(constraint());
}
/** @brief take into account changes of speed (either load or max) */
lmm_variable_t var = nullptr;
lmm_element_t elem = nullptr;
- lmm_update_constraint_bound(model()->getMaxminSystem(), constraint(), coresAmount_ * speed_.scale * speed_.peak);
+ model()->getMaxminSystem()->update_constraint_bound(constraint(), coresAmount_ * speed_.scale * speed_.peak);
while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), constraint(), &elem))) {
CpuCas01Action* action = static_cast<CpuCas01Action*>(lmm_variable_id(var));
- lmm_update_variable_bound(model()->getMaxminSystem(), action->getVariable(),
- action->requestedCore() * speed_.scale * speed_.peak);
+ model()->getMaxminSystem()->update_variable_bound(action->getVariable(),
+ action->requestedCore() * speed_.scale * speed_.peak);
}
Cpu::onSpeedChange();
action->getStateSet()->push_back(*action);
}
- lmm_update_variable_weight(model()->getMaxminSystem(), action->getVariable(), 0.0);
+ model()->getMaxminSystem()->update_variable_weight(action->getVariable(), 0.0);
if (model()->getUpdateMechanism() == UM_LAZY) { // remove action from the heap
action->heapRemove(model()->getActionHeap());
// this is necessary for a variable with weight 0 since such variables are ignored in lmm and we need to set its
CpuCas01Action::CpuCas01Action(Model* model, double cost, bool failed, double speed, lmm_constraint_t constraint,
int requestedCore)
: CpuAction(model, cost, failed,
- lmm_variable_new(model->getMaxminSystem(), this, 1.0 / requestedCore, requestedCore * speed, 1))
+ model->getMaxminSystem()->variable_new(this, 1.0 / requestedCore, requestedCore * speed, 1))
, requestedCore_(requestedCore)
{
if (model->getUpdateMechanism() == UM_LAZY) {
refreshLastUpdate();
setLastValue(0.0);
}
- lmm_expand(model->getMaxminSystem(), constraint, getVariable(), 1.0);
+ model->getMaxminSystem()->expand(constraint, getVariable(), 1.0);
}
CpuCas01Action::CpuCas01Action(Model* model, double cost, bool failed, double speed, lmm_constraint_t constraint)
do {
if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
XBT_DEBUG("Fair bottleneck done");
- lmm_print(sys);
+ sys->print();
}
XBT_DEBUG("******* Constraints to process: %d *******", xbt_swag_size(cnst_list));
xbt_swag_foreach_safe(_cnst, _cnst_next, cnst_list) {
sys->modified = 0;
if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
XBT_DEBUG("Fair bottleneck done");
- lmm_print(sys);
+ sys->print();
}
}
XBT_DEBUG("#### Minimum error tolerated (dichotomy) : %e", dichotomy_min_error);
if (XBT_LOG_ISENABLED(surf_lagrange, xbt_log_priority_debug)) {
- lmm_print(sys);
+ sys->print();
}
if (not sys->modified)
}
if (XBT_LOG_ISENABLED(surf_lagrange, xbt_log_priority_debug)) {
- lmm_print(sys);
+ sys->print();
}
}
double sg_surf_precision = 0.00001; /* Change this with --cfg=surf/precision:VALUE */
int sg_concurrency_limit = -1; /* Change this with --cfg=maxmin/concurrency-limit:VALUE */
-static void *lmm_variable_mallocator_new_f();
-static void lmm_variable_mallocator_free_f(void *var);
-#define lmm_variable_mallocator_reset_f ((void_f_pvoid_t)nullptr)
-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);
static int Global_debug_id = 1;
static int Global_const_debug_id = 1;
-static inline void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst);
-
-static void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr);
-static void lmm_enable_var(lmm_system_t sys, lmm_variable_t var);
static int lmm_can_enable_var(lmm_variable_t var);
-static void lmm_disable_var(lmm_system_t sys, lmm_variable_t var);
static int lmm_concurrency_slack(lmm_constraint_t cnstr);
static int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var);
"Concurrency limit overflow!");
}
-static void lmm_check_concurrency(lmm_system_t sys)
+void s_lmm_system_t::check_concurrency()
{
// These checks are very expensive, so do them only if we want to debug SURF LMM
if (not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug))
return;
void* cnstIt;
- xbt_swag_foreach(cnstIt, &(sys->constraint_set))
+ xbt_swag_foreach(cnstIt, &constraint_set)
{
lmm_constraint_t cnst = (lmm_constraint_t)cnstIt;
int concurrency = 0;
// Check that for each variable, all corresponding elements are in the same state (i.e. same element sets)
void* varIt;
- xbt_swag_foreach(varIt, &(sys->variable_set))
+ xbt_swag_foreach(varIt, &variable_set)
{
lmm_variable_t var = (lmm_variable_t)varIt;
}
}
-static void lmm_var_free(lmm_system_t sys, lmm_variable_t var)
+void s_lmm_system_t::var_free(lmm_variable_t var)
{
- XBT_IN("(sys=%p, var=%p)", sys, var);
- sys->modified = 1;
+ XBT_IN("(sys=%p, var=%p)", this, var);
+ modified = 1;
// TODOLATER Can do better than that by leaving only the variable in only one enabled_element_set, call
- // lmm_update_modified_set, and then remove it..
+ // update_modified_set, and then remove it..
if (not var->cnsts.empty())
- lmm_update_modified_set(sys, var->cnsts[0].constraint);
+ update_modified_set(var->cnsts[0].constraint);
for (s_lmm_element_t& elem : var->cnsts) {
if (var->sharing_weight > 0)
int nelements = xbt_swag_size(&(elem.constraint->enabled_element_set)) +
xbt_swag_size(&(elem.constraint->disabled_element_set));
if (nelements == 0)
- make_constraint_inactive(sys, elem.constraint);
+ make_constraint_inactive(elem.constraint);
else
- lmm_on_disabled_var(sys, elem.constraint);
+ on_disabled_var(elem.constraint);
}
var->cnsts.clear();
- lmm_check_concurrency(sys);
+ check_concurrency();
- xbt_mallocator_release(sys->variable_mallocator, var);
+ xbt_mallocator_release(variable_mallocator, var);
XBT_OUT();
}
-lmm_system_t lmm_system_new(bool selective_update)
+s_lmm_system_t::s_lmm_system_t(bool selective_update)
{
s_lmm_variable_t var;
s_lmm_constraint_t cnst;
- lmm_system_t l = new s_lmm_system_t();
-
- l->modified = 0;
- l->selective_update_active = selective_update;
- l->visited_counter = 1;
-
- XBT_DEBUG("Setting selective_update_active flag to %d", l->selective_update_active);
+ modified = 0;
+ selective_update_active = selective_update;
+ visited_counter = 1;
- xbt_swag_init(&(l->variable_set), xbt_swag_offset(var, variable_set_hookup));
- xbt_swag_init(&(l->constraint_set), xbt_swag_offset(cnst, constraint_set_hookup));
+ XBT_DEBUG("Setting selective_update_active flag to %d", selective_update_active);
- xbt_swag_init(&(l->active_constraint_set), xbt_swag_offset(cnst, active_constraint_set_hookup));
+ xbt_swag_init(&variable_set, xbt_swag_offset(var, variable_set_hookup));
+ xbt_swag_init(&constraint_set, xbt_swag_offset(cnst, constraint_set_hookup));
- xbt_swag_init(&(l->modified_constraint_set), xbt_swag_offset(cnst, modified_constraint_set_hookup));
- xbt_swag_init(&(l->saturated_variable_set), xbt_swag_offset(var, saturated_variable_set_hookup));
- xbt_swag_init(&(l->saturated_constraint_set), xbt_swag_offset(cnst, saturated_constraint_set_hookup));
+ xbt_swag_init(&active_constraint_set, xbt_swag_offset(cnst, active_constraint_set_hookup));
- l->variable_mallocator = xbt_mallocator_new(65536,
- lmm_variable_mallocator_new_f,
- lmm_variable_mallocator_free_f,
- lmm_variable_mallocator_reset_f);
+ xbt_swag_init(&modified_constraint_set, xbt_swag_offset(cnst, modified_constraint_set_hookup));
+ xbt_swag_init(&saturated_variable_set, xbt_swag_offset(var, saturated_variable_set_hookup));
+ xbt_swag_init(&saturated_constraint_set, xbt_swag_offset(cnst, saturated_constraint_set_hookup));
- l->solve_fun = &lmm_solve;
-
- return l;
+ keep_track = nullptr;
+ variable_mallocator = xbt_mallocator_new(65536, s_lmm_system_t::variable_mallocator_new_f,
+ s_lmm_system_t::variable_mallocator_free_f, nullptr);
+ solve_fun = &lmm_solve;
}
-void lmm_system_free(lmm_system_t sys)
+s_lmm_system_t::~s_lmm_system_t()
{
- lmm_variable_t var = nullptr;
- lmm_constraint_t cnst = nullptr;
+ lmm_variable_t var;
+ lmm_constraint_t cnst;
- if (sys == nullptr)
- return;
-
- while ((var = (lmm_variable_t) extract_variable(sys))) {
+ while ((var = extract_variable())) {
auto demangled = simgrid::xbt::demangle(typeid(*var->id).name());
XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled.get(),
var->id_int);
- lmm_var_free(sys, var);
+ var_free(var);
}
- while ((cnst = (lmm_constraint_t) extract_constraint(sys)))
- lmm_cnst_free(sys, cnst);
+ while ((cnst = extract_constraint()))
+ cnst_free(cnst);
- xbt_mallocator_free(sys->variable_mallocator);
- delete sys;
+ xbt_mallocator_free(variable_mallocator);
}
-static inline void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst)
+void s_lmm_system_t::cnst_free(lmm_constraint_t cnst)
{
- make_constraint_inactive(sys, cnst);
+ make_constraint_inactive(cnst);
delete cnst;
}
-lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id, double bound_value)
+lmm_constraint_t s_lmm_system_t::constraint_new(void* id, double bound_value)
{
lmm_constraint_t cnst = nullptr;
s_lmm_element_t elem;
cnst->concurrency_limit = sg_concurrency_limit;
cnst->usage = 0;
cnst->sharing_policy = 1; /* FIXME: don't hardcode the value */
- insert_constraint(sys, cnst);
+ insert_constraint(cnst);
return cnst;
}
return (cnst->sharing_policy);
}
-static void *lmm_variable_mallocator_new_f()
+void* s_lmm_system_t::variable_mallocator_new_f()
{
return new s_lmm_variable_t;
}
-static void lmm_variable_mallocator_free_f(void *var)
+void s_lmm_system_t::variable_mallocator_free_f(void* var)
{
delete static_cast<lmm_variable_t>(var);
}
-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 s_lmm_system_t::variable_new(simgrid::surf::Action* id, double sharing_weight, double bound,
+ int number_of_constraints)
{
- XBT_IN("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)", sys, id, sharing_weight, bound, number_of_constraints);
+ XBT_IN("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)", this, id, sharing_weight, bound, number_of_constraints);
- lmm_variable_t var = (lmm_variable_t)xbt_mallocator_get(sys->variable_mallocator);
+ lmm_variable_t var = (lmm_variable_t)xbt_mallocator_get(variable_mallocator);
var->id = id;
var->id_int = Global_debug_id++;
var->cnsts.reserve(number_of_constraints);
var->bound = bound;
var->concurrency_share = 1;
var->value = 0.0;
- var->visited = sys->visited_counter - 1;
+ var->visited = visited_counter - 1;
var->mu = 0.0;
var->new_mu = 0.0;
var->func_f = func_f_def;
var->saturated_variable_set_hookup.prev = nullptr;
if (sharing_weight)
- xbt_swag_insert_at_head(var, &(sys->variable_set));
+ xbt_swag_insert_at_head(var, &variable_set);
else
- xbt_swag_insert_at_tail(var, &(sys->variable_set));
+ xbt_swag_insert_at_tail(var, &variable_set);
XBT_OUT(" returns %p", var);
return var;
}
-void lmm_variable_free(lmm_system_t sys, lmm_variable_t var)
+void s_lmm_system_t::variable_free(lmm_variable_t var)
{
- remove_variable(sys, var);
- lmm_var_free(sys, var);
+ remove_variable(var);
+ var_free(var);
}
double lmm_variable_getvalue(lmm_variable_t var)
return (var->bound);
}
-void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double consumption_weight)
+void s_lmm_system_t::expand(lmm_constraint_t cnst, lmm_variable_t var, double consumption_weight)
{
- sys->modified = 1;
+ modified = 1;
//Check if this variable already has an active element in this constraint
//If it does, substract it from the required slack
//Check if we need to disable the variable
if (var->sharing_weight > 0 && var->concurrency_share - current_share > lmm_concurrency_slack(cnst)) {
double weight = var->sharing_weight;
- lmm_disable_var(sys,var);
+ disable_var(var);
for (s_lmm_element_t const& elem : var->cnsts)
- lmm_on_disabled_var(sys, elem.constraint);
+ on_disabled_var(elem.constraint);
consumption_weight = 0;
var->staged_weight=weight;
xbt_assert(not var->sharing_weight);
} else
xbt_swag_insert_at_tail(&elem, &(elem.constraint->disabled_element_set));
- if (not sys->selective_update_active) {
- make_constraint_active(sys, cnst);
+ if (not selective_update_active) {
+ make_constraint_active(cnst);
} else if (elem.consumption_weight > 0 || var->sharing_weight > 0) {
- make_constraint_active(sys, cnst);
- lmm_update_modified_set(sys, cnst);
+ make_constraint_active(cnst);
+ update_modified_set(cnst);
//TODOLATER: Why do we need this second call?
if (var->cnsts.size() > 1)
- lmm_update_modified_set(sys, var->cnsts[0].constraint);
+ update_modified_set(var->cnsts[0].constraint);
}
- lmm_check_concurrency(sys);
+ check_concurrency();
}
-void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value)
+void s_lmm_system_t::expand_add(lmm_constraint_t cnst, lmm_variable_t var, double value)
{
- sys->modified = 1;
+ modified = 1;
- lmm_check_concurrency(sys);
+ check_concurrency();
//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),
if (var->sharing_weight) {
if (lmm_concurrency_slack(cnst) < lmm_element_concurrency(&elem)) {
double weight = var->sharing_weight;
- lmm_disable_var(sys,var);
+ disable_var(var);
for (s_lmm_element_t const& elem2 : var->cnsts)
- lmm_on_disabled_var(sys, elem2.constraint);
+ on_disabled_var(elem2.constraint);
var->staged_weight=weight;
xbt_assert(not var->sharing_weight);
}
lmm_increase_concurrency(&elem);
}
- lmm_update_modified_set(sys, cnst);
+ update_modified_set(cnst);
} else
- lmm_expand(sys, cnst, var, value);
+ expand(cnst, var, value);
- lmm_check_concurrency(sys);
+ check_concurrency();
}
lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t /*sys*/, lmm_variable_t var, unsigned num)
}
}
-void lmm_print(lmm_system_t sys)
+void s_lmm_system_t::print()
{
std::string buf = std::string("MAX-MIN ( ");
void* _var;
/* Printing Objective */
- xbt_swag_t var_list = &(sys->variable_set);
+ xbt_swag_t var_list = &variable_set;
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) + ") ";
XBT_DEBUG("Constraints");
/* Printing Constraints */
void* _cnst;
- xbt_swag_t cnst_list = &(sys->active_constraint_set);
+ xbt_swag_t cnst_list = &active_constraint_set;
xbt_swag_foreach(_cnst, cnst_list) {
lmm_constraint_t cnst = (lmm_constraint_t)_cnst;
double sum = 0.0;
}
}
-void lmm_solve(lmm_system_t sys)
+void s_lmm_system_t::solve()
{
void* _cnst;
void* _cnst_next;
double min_usage = -1;
double min_bound = -1;
- if (not sys->modified)
+ if (not modified)
return;
- XBT_IN("(sys=%p)", sys);
+ XBT_IN("(sys=%p)", this);
/* Compute Usage and store the variables that reach the maximum. If selective_update_active is true, only constraints
* that changed are considered. Otherwise all constraints with active actions are considered.
*/
- xbt_swag_t cnst_list = sys->selective_update_active ? &(sys->modified_constraint_set) : &(sys->active_constraint_set);
+ xbt_swag_t cnst_list = selective_update_active ? &modified_constraint_set : &active_constraint_set;
XBT_DEBUG("Active constraints : %d", xbt_swag_size(cnst_list));
/* Init: Only modified code portions: reset the value of active variables */
make_elem_active(elem);
simgrid::surf::Action *action = static_cast<simgrid::surf::Action*>(elem->variable->id);
- if (sys->keep_track && not action->is_linked())
- sys->keep_track->push_back(*action);
+ if (keep_track && not action->is_linked())
+ keep_track->push_back(*action);
}
}
XBT_DEBUG("Constraint '%d' usage: %f remaining: %f concurrency: %i<=%i<=%i", cnst->id_int, cnst->usage,
}
}
- saturated_variable_set_update( cnst_light_tab, saturated_constraint_set, sys);
+ saturated_variable_set_update(cnst_light_tab, saturated_constraint_set, this);
/* Saturated variables update */
do {
/* Fix the variables that have to be */
- xbt_swag_t var_list = &(sys->saturated_variable_set);
+ xbt_swag_t var_list = &saturated_variable_set;
void* _var;
lmm_variable_t var = nullptr;
xbt_swag_foreach(_var, var_list) {
&min_usage);
}
- saturated_variable_set_update(cnst_light_tab, saturated_constraint_set, sys);
+ saturated_variable_set_update(cnst_light_tab, saturated_constraint_set, this);
} while (cnst_light_num > 0);
- sys->modified = 0;
- if (sys->selective_update_active)
- lmm_remove_all_modified_set(sys);
+ modified = 0;
+ if (selective_update_active)
+ remove_all_modified_set();
if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
- lmm_print(sys);
+ print();
}
- lmm_check_concurrency(sys);
+ check_concurrency();
delete[] cnst_light_tab;
XBT_OUT();
}
+void lmm_solve(lmm_system_t sys)
+{
+ sys->solve();
+}
+
/** \brief Attribute the value bound to var->bound.
*
* \param sys the lmm_system_t
* Makes var->bound equal to bound. Whenever this function is called a change is signed in the system. To
* avoid false system changing detection it is a good idea to test (bound != 0) before calling it.
*/
-void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var, double bound)
+void s_lmm_system_t::update_variable_bound(lmm_variable_t var, double bound)
{
- sys->modified = 1;
+ modified = 1;
var->bound = bound;
if (not var->cnsts.empty())
- lmm_update_modified_set(sys, var->cnsts[0].constraint);
+ update_modified_set(var->cnsts[0].constraint);
}
int lmm_concurrency_slack(lmm_constraint_t cnstr)
}
//Small remark: In this implementation of lmm_enable_var and lmm_disable_var, we will meet multiple times with var when
-// running lmm_update_modified_set.
-//A priori not a big performance issue, but we might do better by calling lmm_update_modified_set within the for loops
+// 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)
-void lmm_enable_var(lmm_system_t sys, lmm_variable_t var){
+void s_lmm_system_t::enable_var(lmm_variable_t var)
+{
xbt_assert(not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug) || lmm_can_enable_var(var));
var->sharing_weight = var->staged_weight;
var->staged_weight = 0;
- // Enabling the variable, move to var to list head. Subtlety is: here, we need to call lmm_update_modified_set AFTER
+ // 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.
- xbt_swag_remove(var, &(sys->variable_set));
- xbt_swag_insert_at_head(var, &(sys->variable_set));
+ xbt_swag_remove(var, &variable_set);
+ xbt_swag_insert_at_head(var, &variable_set);
for (s_lmm_element_t& elem : var->cnsts) {
xbt_swag_remove(&elem, &(elem.constraint->disabled_element_set));
xbt_swag_insert_at_head(&elem, &(elem.constraint->enabled_element_set));
lmm_increase_concurrency(&elem);
}
if (not var->cnsts.empty())
- lmm_update_modified_set(sys, var->cnsts[0].constraint);
+ update_modified_set(var->cnsts[0].constraint);
- //When used within lmm_on_disabled_var, we would get an assertion fail, because transiently there can be variables
+ // When used within on_disabled_var, we would get an assertion fail, because transiently there can be variables
// that are staged and could be activated.
- //Anyway, caller functions all call lmm_check_concurrency() in the end.
+ // Anyway, caller functions all call check_concurrency() in the end.
}
-void lmm_disable_var(lmm_system_t sys, lmm_variable_t var){
+void s_lmm_system_t::disable_var(lmm_variable_t var)
+{
xbt_assert(not var->staged_weight, "Staged weight should have been cleared");
- // Disabling the variable, move to var to list tail. Subtlety is: here, we need to call lmm_update_modified_set BEFORE
- // moving the last element of var.
- xbt_swag_remove(var, &(sys->variable_set));
- xbt_swag_insert_at_tail(var, &(sys->variable_set));
+ // Disabling the variable, move to var to list tail. Subtlety is: here, we need to call update_modified_set
+ // BEFORE moving the last element of var.
+ xbt_swag_remove(var, &variable_set);
+ xbt_swag_insert_at_tail(var, &variable_set);
if (not var->cnsts.empty())
- lmm_update_modified_set(sys, var->cnsts[0].constraint);
+ update_modified_set(var->cnsts[0].constraint);
for (s_lmm_element_t& elem : var->cnsts) {
xbt_swag_remove(&elem, &(elem.constraint->enabled_element_set));
xbt_swag_insert_at_tail(&elem, &(elem.constraint->disabled_element_set));
var->sharing_weight = 0.0;
var->staged_weight=0.0;
var->value = 0.0;
- lmm_check_concurrency(sys);
+ check_concurrency();
}
/* /brief Find variables that can be enabled and enable them.
* If yes, check that none of the constraints that this variable is involved in is at the limit of its concurrency
* And then add it to enabled variables
*/
-void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr){
-
+void s_lmm_system_t::on_disabled_var(lmm_constraint_t cnstr)
+{
if(cnstr->concurrency_limit<0)
return;
//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?
- lmm_enable_var(sys, elem->variable);
+ enable_var(elem->variable);
}
xbt_assert(cnstr->concurrency_current<=cnstr->concurrency_limit,"Concurrency overflow!");
//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 lmm_check_concurrency() in the end.
+ // Anyway, caller functions all call check_concurrency() in the end.
}
/* \brief update the weight of a variable, and enable/disable it.
* @return Returns whether a change was made
*/
-void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double weight)
+void s_lmm_system_t::update_variable_weight(lmm_variable_t var, double weight)
{
xbt_assert(weight>=0,"Variable weight should not be negative!");
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);
+ XBT_IN("(sys=%p, var=%p, weight=%f)", this, var, weight);
- sys->modified = 1;
+ modified = 1;
//Are we enabling this variable?
if (enabling_var){
return;
}
XBT_DEBUG("Enabling var with min concurrency slack %i", minslack);
- lmm_enable_var(sys,var);
+ enable_var(var);
} else if (disabling_var){
//Are we disabling this variable?
- lmm_disable_var(sys,var);
+ disable_var(var);
} else {
var->sharing_weight = weight;
}
- lmm_check_concurrency(sys);
+ check_concurrency();
XBT_OUT();
}
return var->sharing_weight;
}
-void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, double bound)
+void s_lmm_system_t::update_constraint_bound(lmm_constraint_t cnst, double bound)
{
- sys->modified = 1;
- lmm_update_modified_set(sys, cnst);
+ modified = 1;
+ update_modified_set(cnst);
cnst->bound = bound;
}
-int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst)
-{
- return xbt_swag_belongs(cnst, &(sys->active_constraint_set));
-}
-
/** \brief Update the constraint set propagating recursively to other constraints so the system should not be entirely
* computed.
*
* A recursive algorithm to optimize the system recalculation selecting only constraints that have changed. Each
* constraint change is propagated to the list of constraints for each variable.
*/
-static void lmm_update_modified_set_rec(lmm_system_t sys, lmm_constraint_t cnst)
+void s_lmm_system_t::update_modified_set_rec(lmm_constraint_t cnst)
{
void* _elem;
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 == sys->visited_counter)
+ if (var->visited == visited_counter)
break;
- if (elem.constraint != cnst && not xbt_swag_belongs(elem.constraint, &sys->modified_constraint_set)) {
- xbt_swag_insert(elem.constraint, &sys->modified_constraint_set);
- lmm_update_modified_set_rec(sys, elem.constraint);
+ if (elem.constraint != cnst && not xbt_swag_belongs(elem.constraint, &modified_constraint_set)) {
+ xbt_swag_insert(elem.constraint, &modified_constraint_set);
+ update_modified_set_rec(elem.constraint);
}
}
//var will be ignored in later visits as long as sys->visited_counter does not move
- var->visited = sys->visited_counter;
+ var->visited = visited_counter;
}
}
-static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst)
+void s_lmm_system_t::update_modified_set(lmm_constraint_t cnst)
{
/* nothing to do if selective update isn't active */
- if (sys->selective_update_active && not xbt_swag_belongs(cnst, &sys->modified_constraint_set)) {
- xbt_swag_insert(cnst, &sys->modified_constraint_set);
- lmm_update_modified_set_rec(sys, cnst);
+ if (selective_update_active && not xbt_swag_belongs(cnst, &modified_constraint_set)) {
+ xbt_swag_insert(cnst, &modified_constraint_set);
+ update_modified_set_rec(cnst);
}
}
-/** \brief Remove all constraints of the modified_constraint_set.
- *
- * \param sys the lmm_system_t
- */
-static void lmm_remove_all_modified_set(lmm_system_t sys)
+void s_lmm_system_t::remove_all_modified_set()
{
- // We cleverly un-flag all variables just by incrementing sys->visited_counter
- // In effect, the var->visited value will no more be equal to sys->visited counter
+ // We cleverly un-flag all variables just by incrementing visited_counter
+ // In effect, the var->visited value will no more be equal to visited counter
// To be clean, when visited counter has wrapped around, we force these var->visited values so that variables that
// were in the modified a long long time ago are not wrongly skipped here, which would lead to very nasty bugs
// (i.e. not readibily reproducible, and requiring a lot of run time before happening).
- if (++sys->visited_counter == 1) {
+ if (++visited_counter == 1) {
/* the counter wrapped around, reset each variable->visited */
- void *_var;
- xbt_swag_foreach(_var, &sys->variable_set)
+ void *_var;
+ xbt_swag_foreach(_var, &variable_set)
((lmm_variable_t)_var)->visited = 0;
}
- xbt_swag_reset(&sys->modified_constraint_set);
+ xbt_swag_reset(&modified_constraint_set);
}
/**
/** @ingroup SURF_lmm
* @brief LMM system
*/
-struct s_lmm_system_t {
+class s_lmm_system_t {
+public:
+ /**
+ * @brief Create a new Linear MaxMim system
+ * @param selective_update whether we should do lazy updates
+ */
+ s_lmm_system_t(bool selective_update);
+ /** @brief Free an existing Linear MaxMin system */
+ ~s_lmm_system_t();
+
+ /**
+ * @brief Create a new Linear MaxMin constraint
+ * @param id Data associated to the constraint (e.g.: a network link)
+ * @param bound_value The bound value of the constraint
+ */
+ lmm_constraint_t constraint_new(void* id, double bound_value);
+
+ /**
+ * @brief Create a new Linear MaxMin variable
+ * @param id Data associated to the variable (e.g.: a network communication)
+ * @param weight_value The weight of the variable (0.0 if not used)
+ * @param bound The maximum value of the variable (-1.0 if no maximum value)
+ * @param number_of_constraints The maximum number of constraint to associate to the variable
+ */
+ lmm_variable_t variable_new(simgrid::surf::Action* id, double weight_value, double bound, int number_of_constraints);
+
+ /**
+ * @brief Free a variable
+ * @param var The variable to free
+ */
+ void variable_free(lmm_variable_t var);
+
+ /**
+ * @brief Associate a variable to a constraint with a coefficient
+ * @param cnst A constraint
+ * @param var A variable
+ * @param value The coefficient associated to the variable in the constraint
+ */
+ void expand(lmm_constraint_t cnst, lmm_variable_t var, double value);
+
+ /**
+ * @brief Add value to the coefficient between a constraint and a variable or create one
+ * @param cnst A constraint
+ * @param var A variable
+ * @param value The value to add to the coefficient associated to the variable in the constraint
+ */
+ void expand_add(lmm_constraint_t cnst, lmm_variable_t var, double value);
+
+ /**
+ * @brief Update the bound of a variable
+ * @param var A constraint
+ * @param bound The new bound
+ */
+ void update_variable_bound(lmm_variable_t var, double bound);
+
+ /**
+ * @brief Update the weight of a variable
+ * @param var A variable
+ * @param weight The new weight of the variable
+ */
+ void update_variable_weight(lmm_variable_t var, double weight);
+
+ /**
+ * @brief Update a constraint bound
+ * @param cnst A constraint
+ * @param bound The new bound of the consrtaint
+ */
+ void update_constraint_bound(lmm_constraint_t cnst, double bound);
+
+ /**
+ * @brief [brief description]
+ * @param cnst A constraint
+ * @return [description]
+ */
+ int constraint_used(lmm_constraint_t cnst) { return xbt_swag_belongs(cnst, &active_constraint_set); }
+
+ /** @brief Print the lmm system */
+ void print();
+
+ /** @brief Solve the lmm system */
+ void solve();
+
+private:
+ static void* variable_mallocator_new_f();
+ static void variable_mallocator_free_f(void* var);
+
+ void var_free(lmm_variable_t var);
+ void cnst_free(lmm_constraint_t cnst);
+ lmm_variable_t extract_variable() { return static_cast<lmm_variable_t>(xbt_swag_extract(&variable_set)); }
+ lmm_constraint_t extract_constraint() { return static_cast<lmm_constraint_t>(xbt_swag_extract(&constraint_set)); }
+ void insert_constraint(lmm_constraint_t cnst) { xbt_swag_insert(cnst, &constraint_set); }
+ void remove_variable(lmm_variable_t var)
+ {
+ xbt_swag_remove(var, &variable_set);
+ xbt_swag_remove(var, &saturated_variable_set);
+ }
+ void remove_constraint(lmm_constraint_t cnst) // FIXME: unused
+ {
+ xbt_swag_remove(cnst, &constraint_set);
+ xbt_swag_remove(cnst, &saturated_constraint_set);
+ }
+ void make_constraint_active(lmm_constraint_t cnst) { xbt_swag_insert(cnst, &active_constraint_set); }
+ void make_constraint_inactive(lmm_constraint_t cnst)
+ {
+ xbt_swag_remove(cnst, &active_constraint_set);
+ xbt_swag_remove(cnst, &modified_constraint_set);
+ }
+
+ void enable_var(lmm_variable_t var);
+ void disable_var(lmm_variable_t var);
+ void on_disabled_var(lmm_constraint_t cnstr);
+
+ /**
+ * @brief Update the value of element linking the constraint and the variable
+ * @param cnst A constraint
+ * @param var A variable
+ * @param value The new value
+ */
+ void update(lmm_constraint_t cnst, lmm_variable_t var, double value);
+
+ void update_modified_set(lmm_constraint_t cnst);
+ void update_modified_set_rec(lmm_constraint_t cnst);
+
+ /** @brief Remove all constraints of the modified_constraint_set. */
+ void remove_all_modified_set();
+ void check_concurrency();
+
+public:
int modified;
- bool selective_update_active; /* flag to update partially the system only selecting changed portions */
- unsigned visited_counter; /* used by lmm_update_modified_set and lmm_remove_modified_set to cleverly (un-)flag the constraints (more details in these functions)*/
s_xbt_swag_t variable_set; /* a list of lmm_variable_t */
- s_xbt_swag_t constraint_set; /* a list of lmm_constraint_t */
-
s_xbt_swag_t active_constraint_set; /* a list of lmm_constraint_t */
- s_xbt_swag_t modified_constraint_set; /* a list of modified lmm_constraint_t */
-
s_xbt_swag_t saturated_variable_set; /* a list of lmm_variable_t */
s_xbt_swag_t saturated_constraint_set; /* a list of lmm_constraint_t_t */
simgrid::surf::ActionLmmListPtr keep_track;
- xbt_mallocator_t variable_mallocator;
-
void (*solve_fun)(lmm_system_t self);
-};
-#define extract_variable(sys) xbt_swag_extract(&((sys)->variable_set))
-#define extract_constraint(sys) xbt_swag_extract(&((sys)->constraint_set))
-#define insert_constraint(sys, cnst) xbt_swag_insert((cnst), &((sys)->constraint_set))
-#define remove_variable(sys, var) \
- do { \
- xbt_swag_remove(var, &((sys)->variable_set)); \
- xbt_swag_remove(var, &((sys)->saturated_variable_set)); \
- } while (0)
-#define remove_constraint(sys, cnst) \
- do { \
- xbt_swag_remove((cnst), &((sys)->constraint_set)); \
- xbt_swag_remove((cnst), &((sys)->saturated_constraint_set)); \
- } while (0)
-#define make_constraint_active(sys, cnst) xbt_swag_insert((cnst), &((sys)->active_constraint_set))
-#define make_constraint_inactive(sys, cnst) \
- do { \
- xbt_swag_remove((cnst), &(sys)->active_constraint_set); \
- xbt_swag_remove((cnst), &(sys)->modified_constraint_set); \
- } while (0)
-
-/** @ingroup SURF_lmm
- * @brief Print information about a lmm system
- *
- * @param sys A lmm system
- */
-//XBT_PRIVATE void lmm_print(lmm_system_t sys);
+private:
+ bool selective_update_active; /* flag to update partially the system only selecting changed portions */
+ unsigned visited_counter; /* used by lmm_update_modified_set and lmm_remove_modified_set to cleverly (un-)flag the
+ * constraints (more details in these functions) */
+ s_xbt_swag_t constraint_set; /* a list of lmm_constraint_t */
+ s_xbt_swag_t modified_constraint_set; /* a list of modified lmm_constraint_t */
+ xbt_mallocator_t variable_mallocator;
+};
extern XBT_PRIVATE double (*func_f_def) (lmm_variable_t, double);
extern XBT_PRIVATE double (*func_fp_def) (lmm_variable_t, double);
xbt_die("Unsupported optimization (%s) for this model. Accepted: Full, Lazy.", optim.c_str());
}
- maxminSystem_ = lmm_system_new(selectiveUpdate_);
+ maxminSystem_ = new s_lmm_system_t(selectiveUpdate_);
loopback_ = NetworkCm02Model::createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE);
if (getUpdateMechanism() == UM_LAZY) {
// if I am wearing a latency hat
if (action->getHat() == LATENCY) {
XBT_DEBUG("Latency paid for action %p. Activating", action);
- lmm_update_variable_weight(maxminSystem_, action->getVariable(), action->weight_);
+ maxminSystem_->update_variable_weight(action->getVariable(), action->weight_);
action->heapRemove(getActionHeap());
action->refreshLastUpdate();
action.latency_ = 0.0;
}
if (action.latency_ <= 0.0 && not action.isSuspended())
- lmm_update_variable_weight(maxminSystem_, action.getVariable(), action.weight_);
+ maxminSystem_->update_variable_weight(action.getVariable(), action.weight_);
}
if (TRACE_is_enabled()) {
int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action.getVariable());
constraints_per_variable += back_route.size();
if (action->latency_ > 0) {
- action->setVariable(lmm_variable_new(maxminSystem_, action, 0.0, -1.0, constraints_per_variable));
+ action->setVariable(maxminSystem_->variable_new(action, 0.0, -1.0, constraints_per_variable));
if (getUpdateMechanism() == UM_LAZY) {
// add to the heap the event when the latency is payed
XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency_ + action->getLastUpdate());
action->heapInsert(getActionHeap(), action->latency_ + action->getLastUpdate(), route.empty() ? NORMAL : LATENCY);
}
} else
- action->setVariable(lmm_variable_new(maxminSystem_, action, 1.0, -1.0, constraints_per_variable));
+ action->setVariable(maxminSystem_->variable_new(action, 1.0, -1.0, constraints_per_variable));
if (action->rate_ < 0) {
- lmm_update_variable_bound(maxminSystem_, action->getVariable(), (action->latCurrent_ > 0) ? sg_tcp_gamma / (2.0 * action->latCurrent_) : -1.0);
+ maxminSystem_->update_variable_bound(action->getVariable(),
+ (action->latCurrent_ > 0) ? sg_tcp_gamma / (2.0 * action->latCurrent_) : -1.0);
} else {
- lmm_update_variable_bound(maxminSystem_, action->getVariable(), (action->latCurrent_ > 0) ? std::min(action->rate_, sg_tcp_gamma / (2.0 * action->latCurrent_)) : action->rate_);
+ maxminSystem_->update_variable_bound(action->getVariable(),
+ (action->latCurrent_ > 0)
+ ? std::min(action->rate_, sg_tcp_gamma / (2.0 * action->latCurrent_))
+ : action->rate_);
}
for (auto const& link : route)
- lmm_expand(maxminSystem_, link->constraint(), action->getVariable(), 1.0);
+ maxminSystem_->expand(link->constraint(), action->getVariable(), 1.0);
if (not back_route.empty()) { // sg_network_crosstraffic was activated
XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
for (auto const& link : back_route)
- lmm_expand(maxminSystem_, link->constraint(), action->getVariable(), .05);
+ maxminSystem_->expand(link->constraint(), action->getVariable(), .05);
//Change concurrency_share here, if you want that cross-traffic is included in the SURF concurrency
//(You would also have to change lmm_element_concurrency())
************/
NetworkCm02Link::NetworkCm02Link(NetworkCm02Model* model, const std::string& name, double bandwidth, double latency,
e_surf_link_sharing_policy_t policy, lmm_system_t system)
- : LinkImpl(model, name, lmm_constraint_new(system, this, sg_bandwidth_factor * bandwidth))
+ : LinkImpl(model, name, system->constraint_new(this, sg_bandwidth_factor * bandwidth))
{
bandwidth_.scale = 1.0;
bandwidth_.peak = bandwidth;
void NetworkCm02Link::setBandwidth(double value)
{
-
bandwidth_.peak = value;
- lmm_update_constraint_bound(model()->getMaxminSystem(), constraint(),
- sg_bandwidth_factor * (bandwidth_.peak * bandwidth_.scale));
+ model()->getMaxminSystem()->update_constraint_bound(constraint(),
+ sg_bandwidth_factor * (bandwidth_.peak * bandwidth_.scale));
TRACE_surf_link_set_bandwidth(surf_get_clock(), getCname(), sg_bandwidth_factor * bandwidth_.peak * bandwidth_.scale);
if (sg_weight_S_parameter > 0) {
NetworkCm02Action *action = static_cast<NetworkCm02Action*>(lmm_variable_id(var));
action->weight_ += delta;
if (not action->isSuspended())
- lmm_update_variable_weight(model()->getMaxminSystem(), action->getVariable(), action->weight_);
+ model()->getMaxminSystem()->update_variable_weight(action->getVariable(), action->weight_);
}
}
}
action->latCurrent_ += delta;
action->weight_ += delta;
if (action->rate_ < 0)
- lmm_update_variable_bound(model()->getMaxminSystem(), action->getVariable(),
- sg_tcp_gamma / (2.0 * action->latCurrent_));
+ model()->getMaxminSystem()->update_variable_bound(action->getVariable(),
+ sg_tcp_gamma / (2.0 * action->latCurrent_));
else {
- lmm_update_variable_bound(model()->getMaxminSystem(), action->getVariable(),
- std::min(action->rate_, sg_tcp_gamma / (2.0 * action->latCurrent_)));
+ model()->getMaxminSystem()->update_variable_bound(
+ action->getVariable(), std::min(action->rate_, sg_tcp_gamma / (2.0 * action->latCurrent_)));
if (action->rate_ < sg_tcp_gamma / (2.0 * action->latCurrent_)) {
XBT_INFO("Flow is limited BYBANDWIDTH");
}
}
if (not action->isSuspended())
- lmm_update_variable_weight(model()->getMaxminSystem(), action->getVariable(), action->weight_);
+ model()->getMaxminSystem()->update_variable_weight(action->getVariable(), action->weight_);
}
}
if (not double_equals(penalized_bw, rate_before_update, sg_surf_precision)) {
XBT_DEBUG("%d->%d action %p penalty updated : bw now %f, before %f , initial rate %f", root->id,
(*it)->destination->id, (*it)->action, penalized_bw, (*it)->action->getBound(), (*it)->init_rate);
- lmm_update_variable_bound(maxminSystem_, (*it)->action->getVariable(), penalized_bw);
+ maxminSystem_->update_variable_bound((*it)->action->getVariable(), penalized_bw);
} else {
XBT_DEBUG("%d->%d action %p penalty not updated : bw %f, initial rate %f", root->id, (*it)->destination->id,
(*it)->action, penalized_bw, (*it)->init_rate);
#include <algorithm>
+#include "maxmin_private.hpp"
#include "network_interface.hpp"
#include "simgrid/sg_config.h"
NetworkModel::~NetworkModel()
{
- lmm_system_free(maxminSystem_);
+ delete maxminSystem_;
delete modifiedSet_;
}
bool LinkImpl::isUsed()
{
- return lmm_constraint_used(model()->getMaxminSystem(), constraint());
+ return model()->getMaxminSystem()->constraint_used(constraint());
}
double LinkImpl::latency()
namespace surf {
HostL07Model::HostL07Model() : HostModel() {
- maxminSystem_ = lmm_system_new(true /* lazy */);
+ maxminSystem_ = new s_lmm_system_t(true /* lazy */);
maxminSystem_->solve_fun = &bottleneck_solve;
surf_network_model = new NetworkL07Model(this,maxminSystem_);
surf_cpu_model_pm = new CpuL07Model(this,maxminSystem_);
HostL07Model::~HostL07Model()
{
- lmm_system_free(maxminSystem_);
+ delete maxminSystem_;
maxminSystem_ = nullptr;
delete surf_network_model;
delete surf_cpu_model_pm;
}
if ((action.latency_ <= 0.0) && (action.isSuspended() == 0)) {
action.updateBound();
- lmm_update_variable_weight(maxminSystem_, action.getVariable(), 1.0);
+ maxminSystem_->update_variable_weight(action.getVariable(), 1.0);
}
}
XBT_DEBUG("Action (%p) : remains (%g) updated by %g.", &action, action.getRemains(),
XBT_DEBUG("Creating a parallel task (%p) with %d hosts and %d unique links.", this, host_nb, nb_link);
latency_ = latency;
- setVariable(lmm_variable_new(model->getMaxminSystem(), this, 1.0, (rate > 0 ? rate : -1.0), host_nb + nb_link));
+ setVariable(model->getMaxminSystem()->variable_new(this, 1.0, (rate > 0 ? rate : -1.0), host_nb + nb_link));
if (latency_ > 0)
- lmm_update_variable_weight(model->getMaxminSystem(), getVariable(), 0.0);
+ model->getMaxminSystem()->update_variable_weight(getVariable(), 0.0);
for (int i = 0; i < host_nb; i++)
- lmm_expand(model->getMaxminSystem(), host_list[i]->pimpl_cpu->constraint(), getVariable(), flops_amount[i]);
+ model->getMaxminSystem()->expand(host_list[i]->pimpl_cpu->constraint(), getVariable(), flops_amount[i]);
if(bytes_amount != nullptr) {
for (int i = 0; i < host_nb; i++) {
hostList_->at(i)->routeTo(hostList_->at(j), route, nullptr);
for (auto const& link : route)
- lmm_expand_add(model->getMaxminSystem(), link->constraint(), this->getVariable(),
- bytes_amount[i * host_nb + j]);
+ model->getMaxminSystem()->expand_add(link->constraint(), this->getVariable(),
+ bytes_amount[i * host_nb + j]);
}
}
}
************/
CpuL07::CpuL07(CpuL07Model* model, simgrid::s4u::Host* host, std::vector<double>* speedPerPstate, int core)
- : Cpu(model, host, lmm_constraint_new(model->getMaxminSystem(), this, speedPerPstate->front()), speedPerPstate,
- core)
+ : Cpu(model, host, model->getMaxminSystem()->constraint_new(this, speedPerPstate->front()), speedPerPstate, core)
{
}
LinkL07::LinkL07(NetworkL07Model* model, const std::string& name, double bandwidth, double latency,
e_surf_link_sharing_policy_t policy)
- : LinkImpl(model, name, lmm_constraint_new(model->getMaxminSystem(), this, bandwidth))
+ : LinkImpl(model, name, model->getMaxminSystem()->constraint_new(this, bandwidth))
{
bandwidth_.peak = bandwidth;
latency_.peak = latency;
L07Action *action = static_cast<L07Action*>(execution_start(1.0));
action->setMaxDuration(duration);
action->suspended_ = 2;
- lmm_update_variable_weight(model()->getMaxminSystem(), action->getVariable(), 0.0);
+ model()->getMaxminSystem()->update_variable_weight(action->getVariable(), 0.0);
return action;
}
bool CpuL07::isUsed(){
- return lmm_constraint_used(model()->getMaxminSystem(), constraint());
+ return model()->getMaxminSystem()->constraint_used(constraint());
}
/** @brief take into account changes of speed (either load or max) */
lmm_variable_t var = nullptr;
lmm_element_t elem = nullptr;
- lmm_update_constraint_bound(model()->getMaxminSystem(), constraint(), speed_.peak * speed_.scale);
+ model()->getMaxminSystem()->update_constraint_bound(constraint(), speed_.peak * speed_.scale);
while ((var = lmm_get_var_from_cnst(model()->getMaxminSystem(), constraint(), &elem))) {
Action* action = static_cast<Action*>(lmm_variable_id(var));
- lmm_update_variable_bound(model()->getMaxminSystem(), action->getVariable(), speed_.scale * speed_.peak);
+ model()->getMaxminSystem()->update_variable_bound(action->getVariable(), speed_.scale * speed_.peak);
}
Cpu::onSpeedChange();
bool LinkL07::isUsed(){
- return lmm_constraint_used(model()->getMaxminSystem(), constraint());
+ return model()->getMaxminSystem()->constraint_used(constraint());
}
void CpuL07::apply_event(tmgr_trace_event_t triggered, double value)
void LinkL07::setBandwidth(double value)
{
bandwidth_.peak = value;
- lmm_update_constraint_bound(model()->getMaxminSystem(), constraint(), bandwidth_.peak * bandwidth_.scale);
+ model()->getMaxminSystem()->update_constraint_bound(constraint(), bandwidth_.peak * bandwidth_.scale);
}
void LinkL07::setLatency(double value)
XBT_DEBUG("action (%p) : lat_bound = %g", this, lat_bound);
if ((latency_ <= 0.0) && (suspended_ == 0)) {
if (rate_ < 0)
- lmm_update_variable_bound(getModel()->getMaxminSystem(), getVariable(), lat_bound);
+ getModel()->getMaxminSystem()->update_variable_bound(getVariable(), lat_bound);
else
- lmm_update_variable_bound(getModel()->getMaxminSystem(), getVariable(), std::min(rate_, lat_bound));
+ getModel()->getMaxminSystem()->update_variable_bound(getVariable(), std::min(rate_, lat_bound));
}
}
if (action_hook.is_linked())
stateSet_->erase(stateSet_->iterator_to(*this));
if (getVariable())
- lmm_variable_free(getModel()->getMaxminSystem(), getVariable());
+ getModel()->getMaxminSystem()->variable_free(getVariable());
delete this;
return 1;
}
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "storage_n11.hpp"
+#include "maxmin_private.hpp"
#include "simgrid/s4u/Engine.hpp"
#include "src/kernel/routing/NetPoint.hpp"
#include <cmath> /*ceil*/
StorageN11Action::StorageN11Action(Model* model, double cost, bool failed, StorageImpl* storage,
e_surf_action_storage_type_t type)
- : StorageAction(model, cost, failed, lmm_variable_new(model->getMaxminSystem(), this, 1.0, -1.0, 3), storage, type)
+ : StorageAction(model, cost, failed, model->getMaxminSystem()->variable_new(this, 1.0, -1.0, 3), storage, type)
{
XBT_IN("(%s,%g", storage->getCname(), cost);
// Must be less than the max bandwidth for all actions
- lmm_expand(model->getMaxminSystem(), storage->constraint(), getVariable(), 1.0);
+ model->getMaxminSystem()->expand(storage->constraint(), getVariable(), 1.0);
switch(type) {
case READ:
- lmm_expand(model->getMaxminSystem(), storage->constraintRead_, getVariable(), 1.0);
+ model->getMaxminSystem()->expand(storage->constraintRead_, getVariable(), 1.0);
break;
case WRITE:
- lmm_expand(model->getMaxminSystem(), storage->constraintWrite_, getVariable(), 1.0);
+ model->getMaxminSystem()->expand(storage->constraintWrite_, getVariable(), 1.0);
break;
default:
THROW_UNIMPLEMENTED;
if (action_hook.is_linked())
stateSet_->erase(stateSet_->iterator_to(*this));
if (getVariable())
- lmm_variable_free(getModel()->getMaxminSystem(), getVariable());
+ getModel()->getMaxminSystem()->variable_free(getVariable());
xbt_free(getCategory());
delete this;
return 1;
{
XBT_IN("(%p)", this);
if (suspended_ != 2) {
- lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0);
+ getModel()->getMaxminSystem()->update_variable_weight(getVariable(), 0.0);
suspended_ = 1;
}
XBT_OUT();
{
XBT_IN("(%p,%g)", this, bound);
if (variable_)
- lmm_update_variable_bound(getModel()->getMaxminSystem(), variable_, bound);
+ getModel()->getMaxminSystem()->update_variable_bound(variable_, bound);
if (getModel()->getUpdateMechanism() == UM_LAZY && getLastUpdate() != surf_get_clock())
heapRemove(getModel()->getActionHeap());
{
XBT_IN("(%p,%g)", this, weight);
sharingWeight_ = weight;
- lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), weight);
+ getModel()->getMaxminSystem()->update_variable_weight(getVariable(), weight);
if (getModel()->getUpdateMechanism() == UM_LAZY)
heapRemove(getModel()->getActionHeap());
if (action_hook.is_linked())
stateSet_->erase(stateSet_->iterator_to(*this));
if (getVariable())
- lmm_variable_free(getModel()->getMaxminSystem(), getVariable());
+ getModel()->getMaxminSystem()->variable_free(getVariable());
if (getModel()->getUpdateMechanism() == UM_LAZY) {
/* remove from heap */
heapRemove(getModel()->getActionHeap());
{
XBT_IN("(%p)", this);
if (suspended_ != 2) {
- lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0);
+ getModel()->getMaxminSystem()->update_variable_weight(getVariable(), 0.0);
if (getModel()->getUpdateMechanism() == UM_LAZY){
heapRemove(getModel()->getActionHeap());
if (getModel()->getUpdateMechanism() == UM_LAZY && stateSet_ == getModel()->getRunningActionSet() &&
{
XBT_IN("(%p)", this);
if (suspended_ != 2) {
- lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), getPriority());
+ getModel()->getMaxminSystem()->update_variable_weight(getVariable(), getPriority());
suspended_ = 0;
if (getModel()->getUpdateMechanism() == UM_LAZY)
heapRemove(getModel()->getActionHeap());
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/msg.h"
+#include "src/surf/maxmin_private.hpp"
#include "src/surf/surf_interface.hpp"
#include "surf/maxmin.hpp"
#include "xbt/log.h"
else if (method == LAGRANGE_RENO)
lmm_set_default_protocol_function(func_reno_f, func_reno_fpi, func_reno_fpi);
- lmm_system_t Sys = lmm_system_new(1);
- lmm_constraint_t L1 = lmm_constraint_new(Sys, nullptr, a);
- lmm_constraint_t L2 = lmm_constraint_new(Sys, nullptr, b);
- lmm_constraint_t L3 = lmm_constraint_new(Sys, nullptr, a);
+ lmm_system_t Sys = new s_lmm_system_t(true);
+ lmm_constraint_t L1 = Sys->constraint_new(nullptr, a);
+ lmm_constraint_t L2 = Sys->constraint_new(nullptr, b);
+ lmm_constraint_t L3 = Sys->constraint_new(nullptr, a);
- lmm_variable_t R_1_2_3 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 3);
- lmm_variable_t R_1 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 1);
- lmm_variable_t R_2 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 1);
- lmm_variable_t R_3 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 1);
+ lmm_variable_t R_1_2_3 = Sys->variable_new(nullptr, 1.0, -1.0, 3);
+ lmm_variable_t R_1 = Sys->variable_new(nullptr, 1.0, -1.0, 1);
+ lmm_variable_t R_2 = Sys->variable_new(nullptr, 1.0, -1.0, 1);
+ lmm_variable_t R_3 = Sys->variable_new(nullptr, 1.0, -1.0, 1);
- lmm_update_variable_weight(Sys, R_1_2_3, 1.0);
- lmm_update_variable_weight(Sys, R_1, 1.0);
- lmm_update_variable_weight(Sys, R_2, 1.0);
- lmm_update_variable_weight(Sys, R_3, 1.0);
+ Sys->update_variable_weight(R_1_2_3, 1.0);
+ Sys->update_variable_weight(R_1, 1.0);
+ Sys->update_variable_weight(R_2, 1.0);
+ Sys->update_variable_weight(R_3, 1.0);
- lmm_expand(Sys, L1, R_1_2_3, 1.0);
- lmm_expand(Sys, L2, R_1_2_3, 1.0);
- lmm_expand(Sys, L3, R_1_2_3, 1.0);
+ Sys->expand(L1, R_1_2_3, 1.0);
+ Sys->expand(L2, R_1_2_3, 1.0);
+ Sys->expand(L3, R_1_2_3, 1.0);
- lmm_expand(Sys, L1, R_1, 1.0);
- lmm_expand(Sys, L2, R_2, 1.0);
- lmm_expand(Sys, L3, R_3, 1.0);
+ Sys->expand(L1, R_1, 1.0);
+ Sys->expand(L2, R_2, 1.0);
+ Sys->expand(L3, R_3, 1.0);
if (method == MAXMIN) {
lmm_solve(Sys);
PRINT_VAR(R_2);
PRINT_VAR(R_3);
- lmm_variable_free(Sys, R_1_2_3);
- lmm_variable_free(Sys, R_1);
- lmm_variable_free(Sys, R_2);
- lmm_variable_free(Sys, R_3);
- lmm_system_free(Sys);
+ Sys->variable_free(R_1_2_3);
+ Sys->variable_free(R_1);
+ Sys->variable_free(R_2);
+ Sys->variable_free(R_3);
+ delete Sys;
}
static void test2(method_t method)
if (method == LAGRANGE_RENO)
lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
- lmm_system_t Sys = lmm_system_new(1);
- lmm_constraint_t CPU1 = lmm_constraint_new(Sys, nullptr, 200.0);
- lmm_constraint_t CPU2 = lmm_constraint_new(Sys, nullptr, 100.0);
+ lmm_system_t Sys = new s_lmm_system_t(true);
+ lmm_constraint_t CPU1 = Sys->constraint_new(nullptr, 200.0);
+ lmm_constraint_t CPU2 = Sys->constraint_new(nullptr, 100.0);
- lmm_variable_t T1 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 1);
- lmm_variable_t T2 = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 1);
+ lmm_variable_t T1 = Sys->variable_new(nullptr, 1.0, -1.0, 1);
+ lmm_variable_t T2 = Sys->variable_new(nullptr, 1.0, -1.0, 1);
- lmm_update_variable_weight(Sys, T1, 1.0);
- lmm_update_variable_weight(Sys, T2, 1.0);
+ Sys->update_variable_weight(T1, 1.0);
+ Sys->update_variable_weight(T2, 1.0);
- lmm_expand(Sys, CPU1, T1, 1.0);
- lmm_expand(Sys, CPU2, T2, 1.0);
+ Sys->expand(CPU1, T1, 1.0);
+ Sys->expand(CPU2, T2, 1.0);
if (method == MAXMIN) {
lmm_solve(Sys);
PRINT_VAR(T1);
PRINT_VAR(T2);
- lmm_variable_free(Sys, T1);
- lmm_variable_free(Sys, T2);
- lmm_system_free(Sys);
+ Sys->variable_free(T1);
+ Sys->variable_free(T2);
+ delete Sys;
}
static void test3(method_t method)
if (method == LAGRANGE_RENO)
lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
- lmm_system_t Sys = lmm_system_new(1);
+ lmm_system_t Sys = new s_lmm_system_t(true);
/* Creates the constraints */
lmm_constraint_t* tmp_cnst = new lmm_constraint_t[15];
for (int i = 0; i < 15; i++)
- tmp_cnst[i] = lmm_constraint_new(Sys, nullptr, B[i]);
+ tmp_cnst[i] = Sys->constraint_new(nullptr, B[i]);
/* Creates the variables */
lmm_variable_t* tmp_var = new lmm_variable_t[16];
for (int j = 0; j < 16; j++) {
- tmp_var[j] = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 15);
- lmm_update_variable_weight(Sys, tmp_var[j], 1.0);
+ tmp_var[j] = Sys->variable_new(nullptr, 1.0, -1.0, 15);
+ Sys->update_variable_weight(tmp_var[j], 1.0);
}
/* Link constraints and variables */
for (int i = 0; i < 15; i++)
for (int j = 0; j < 16; j++)
if (A[i][j])
- lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0);
+ Sys->expand(tmp_cnst[i], tmp_var[j], 1.0);
if (method == MAXMIN) {
lmm_solve(Sys);
PRINT_VAR(tmp_var[j]);
for (int j = 0; j < 16; j++)
- lmm_variable_free(Sys, tmp_var[j]);
+ Sys->variable_free(tmp_var[j]);
delete[] tmp_var;
delete[] tmp_cnst;
- lmm_system_free(Sys);
+ delete Sys;
for (int i = 0; i < links + 5; i++)
delete[] A[i];
delete[] A;
#include "surf/maxmin.hpp"
#include "simgrid/msg.h"
+#include "src/surf/maxmin_private.hpp"
#include "xbt/module.h"
#include "xbt/sysdep.h" /* time manipulation for benchmarking */
#include "xbt/xbt_os_time.h"
lmm_variable_t var[nb_var];
int used[nb_cnst];
- lmm_system_t Sys = lmm_system_new(1);
+ lmm_system_t Sys = new s_lmm_system_t(true);
for (int i = 0; i < nb_cnst; i++) {
- cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
+ cnst[i] = Sys->constraint_new(NULL, float_random(10.0));
int l;
if(rate_no_limit>float_random(1.0))
//Look at what happens when there is no concurrency limit
}
for (int i = 0; i < nb_var; i++) {
- var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
+ var[i] = Sys->variable_new(NULL, 1.0, -1.0, nb_elem);
//Have a few variables with a concurrency share of two (e.g. cross-traffic in some cases)
int concurrency_share = 1 + int_random(max_share);
lmm_variable_concurrency_share_set(var[i],concurrency_share);
j--;
continue;
}
- lmm_expand(Sys, cnst[k], var[i], float_random(1.5));
- lmm_expand_add(Sys, cnst[k], var[i], float_random(1.5));
+ Sys->expand(cnst[k], var[i], float_random(1.5));
+ Sys->expand_add(cnst[k], var[i], float_random(1.5));
used[k]++;
}
}
}
fprintf(stderr,"\nTotal maximum concurrency is %i\n",l);
- lmm_print(Sys);
+ Sys->print();
}
for (int i = 0; i < nb_var; i++)
- lmm_variable_free(Sys, var[i]);
- lmm_system_free(Sys);
+ Sys->variable_free(var[i]);
+ delete Sys;
}
unsigned int TestClasses [][4]=