-/* Copyright (c) 2004-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* \file callbacks.h */
-#include "xbt/sysdep.h"
+#include "maxmin_private.hpp"
#include "xbt/log.h"
-#include "xbt/strbuff.h"
#include "xbt/mallocator.h"
-#include "maxmin_private.hpp"
-#include <stdlib.h>
-#include <stdio.h> /* sprintf */
+#include "xbt/sysdep.h"
+#include <cxxabi.h>
+#include <limits>
#include <math.h>
+#include <stdio.h> /* sprintf */
+#include <stdlib.h>
+
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf, "Logging specific to SURF (maxmin)");
typedef struct s_dyn_light {
int size;
} s_dyn_light_t, *dyn_light_t;
-double sg_maxmin_precision = 0.00001;
-double sg_surf_precision = 0.00001;
-int sg_concurrency_limit= 100;
+double sg_maxmin_precision = 0.00001; /* Change this with --cfg=maxmin/precision:VALUE */
+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);
"Concurrency limit overflow!");
}
-lmm_system_t lmm_system_new(int selective_update)
+lmm_system_t lmm_system_new(bool selective_update)
{
lmm_system_t l = nullptr;
s_lmm_variable_t var;
lmm_variable_mallocator_free_f,
lmm_variable_mallocator_reset_f);
+ l->solve_fun = &lmm_solve;
+
return l;
}
lmm_variable_t var = nullptr;
lmm_constraint_t cnst = nullptr;
- if (!sys)
+ if (sys == nullptr)
return;
while ((var = (lmm_variable_t) extract_variable(sys))) {
- XBT_WARN("Variable %d still in system when freing it: this may be a bug", var->id_int);
+ int status;
+ char* demangled = abi::__cxa_demangle(typeid(*var->id).name(), 0, 0, &status);
+
+ XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled,
+ var->id_int);
+ xbt_free(demangled);
lmm_var_free(sys, var);
}
while ((cnst = (lmm_constraint_t) extract_constraint(sys)))
static inline void lmm_variable_remove(lmm_system_t sys, lmm_variable_t var)
{
int i;
- int nelements;
lmm_element_t elem = nullptr;
xbt_swag_remove(elem, &(elem->constraint->enabled_element_set));
xbt_swag_remove(elem, &(elem->constraint->disabled_element_set));
xbt_swag_remove(elem, &(elem->constraint->active_element_set));
- nelements=xbt_swag_size(&(elem->constraint->enabled_element_set)) +
- xbt_swag_size(&(elem->constraint->disabled_element_set));
- if (!nelements)
+ 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);
else
lmm_on_disabled_var(sys,elem->constraint);
cnst->bound = bound_value;
cnst->concurrency_maximum=0;
cnst->concurrency_current=0;
- cnst->concurrency_limit=sg_concurrency_limit;
+ cnst->concurrency_limit = sg_concurrency_limit;
cnst->usage = 0;
cnst->sharing_policy = 1; /* FIXME: don't hardcode the value */
insert_constraint(sys, cnst);
return (cnst->sharing_policy);
}
-/* @brief Remove a constraint
+/* @brief Remove a constraint
* Currently this is dead code, but it is exposed in maxmin.h
- * Apparently, this call was designed assuming that constraint would no more have elements in it.
+ * Apparently, this call was designed assuming that constraint would no more have elements in it.
* If not the case, assertion will fail, and you need to add calls e.g. to lmm_shrink before effectively removing it.
*/
inline void lmm_constraint_free(lmm_system_t sys,lmm_constraint_t cnst)
{
- xbt_assert(!xbt_swag_size(&(cnst->active_element_set)),"Removing constraint but it still has active elements");
- xbt_assert(!xbt_swag_size(&(cnst->enabled_element_set)),"Removing constraint but it still has enabled elements");
- xbt_assert(!xbt_swag_size(&(cnst->disabled_element_set)),"Removing constraint but it still has disabled elements");
+ xbt_assert(not xbt_swag_size(&(cnst->active_element_set)), "Removing constraint but it still has active elements");
+ xbt_assert(not xbt_swag_size(&(cnst->enabled_element_set)), "Removing constraint but it still has enabled elements");
+ xbt_assert(not xbt_swag_size(&(cnst->disabled_element_set)),
+ "Removing constraint but it still has disabled elements");
remove_constraint(sys, cnst);
lmm_cnst_free(sys, cnst);
}
xbt_free(var);
}
-lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id, double weight, double bound, int number_of_constraints)
+lmm_variable_t lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, double weight, double bound,
+ int number_of_constraints)
{
lmm_variable_t var = nullptr;
int i;
}
}
- if (!found) {
+ if (not found) {
XBT_DEBUG("cnst %p is not found in var %p", cnst, var);
return;
}
make_constraint_inactive(sys, cnst);
else {
//Check maxconcurrency to see if we can enable new variables
- lmm_on_disabled_var(sys,elem->constraint);
+ lmm_on_disabled_var(sys,elem->constraint);
}
lmm_check_concurrency(sys);
void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value)
{
lmm_element_t elem = nullptr;
- double weight;
int i,current_share;
sys->modified = 1;
}
}
- //Check if we need to disable the variable
+ //Check if we need to disable the variable
if(var->weight>0 && var->concurrency_share-current_share>lmm_concurrency_slack(cnst)) {
- weight=var->weight;
+ double weight = var->weight;
lmm_disable_var(sys,var);
for (i = 0; i < var->cnsts_number; i++)
lmm_on_disabled_var(sys,var->cnsts[i].constraint);
value=0;
var->staged_weight=weight;
- xbt_assert(!var->weight);
+ xbt_assert(not var->weight);
}
xbt_assert(var->cnsts_number < var->cnsts_size, "Too much constraints");
} else
xbt_swag_insert_at_tail(elem, &(elem->constraint->disabled_element_set));
- if(!sys->selective_update_active) {
+ if (not sys->selective_update_active) {
make_constraint_active(sys, cnst);
} else if(elem->value>0 || var->weight >0) {
make_constraint_active(sys, cnst);
void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value)
{
- int i,j;
+ int i;
double weight;
sys->modified = 1;
if(lmm_concurrency_slack(cnst)<lmm_element_concurrency(&var->cnsts[i])){
weight=var->weight;
lmm_disable_var(sys,var);
- for (j = 0; j < var->cnsts_number; j++)
+ for (int j = 0; j < var->cnsts_number; j++)
lmm_on_disabled_var(sys,var->cnsts[j].constraint);
var->staged_weight=weight;
- xbt_assert(!var->weight);
+ xbt_assert(not var->weight);
}
lmm_increase_concurrency(&var->cnsts[i]);
}
lmm_variable_t lmm_get_var_from_cnst(lmm_system_t /*sys*/, lmm_constraint_t cnst, lmm_element_t * elem)
{
- if (!(*elem)) {
+ if (*elem == nullptr) {
// That is the first call, pick the first element among enabled_element_set (or disabled_element_set if
// enabled_element_set is empty)
*elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->enabled_element_set));
- if (!(*elem))
+ if (*elem == nullptr)
*elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
} else {
//elem is not null, so we carry on
if(xbt_swag_belongs(*elem,&(cnst->enabled_element_set))){
//Look at enabled_element_set, and jump to disabled_element_set when finished
*elem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->enabled_element_set.offset);
- if (!(*elem))
+ if (*elem == nullptr)
*elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
} else {
- *elem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->disabled_element_set.offset);
+ *elem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->disabled_element_set.offset);
}
}
if (*elem)
lmm_variable_t lmm_get_var_from_cnst_safe(lmm_system_t /*sys*/, lmm_constraint_t cnst, lmm_element_t * elem,
lmm_element_t * nextelem, int * numelem)
{
- if (!(*elem)){
+ if (*elem == nullptr) {
*elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->enabled_element_set));
*numelem = xbt_swag_size(&(cnst->enabled_element_set))+xbt_swag_size(&(cnst->disabled_element_set))-1;
- if (!(*elem))
+ if (*elem == nullptr)
*elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
}else{
*elem = *nextelem;
if(xbt_swag_belongs(*elem,&(cnst->enabled_element_set))){
//Look at enabled_element_set, and jump to disabled_element_set when finished
*nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->enabled_element_set.offset);
- if (!(*nextelem))
+ if (*nextelem == nullptr)
*nextelem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
} else {
- *nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->disabled_element_set.offset);
+ *nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->disabled_element_set.offset);
}
return (*elem)->variable;
}else
static inline void saturated_variable_set_update(s_lmm_constraint_light_t *cnst_light_tab,
dyn_light_t saturated_constraint_set, 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)*/
lmm_constraint_light_t cnst = nullptr;
void *_elem;
lmm_element_t elem = nullptr;
void lmm_print(lmm_system_t sys)
{
- void *_cnst, *_elem, *_var;
+ void* _cnst;
+ void* _elem;
+ void* _var;
lmm_constraint_t cnst = nullptr;
- lmm_element_t elem = nullptr;
- lmm_variable_t var = nullptr;
- xbt_swag_t cnst_list = nullptr;
- xbt_swag_t var_list = nullptr;
- xbt_swag_t elem_list = nullptr;
- xbt_strbuff_t buf = xbt_strbuff_new();
- double sum = 0.0;
+ lmm_element_t elem = nullptr;
+ lmm_variable_t var = nullptr;
+ xbt_swag_t cnst_list = nullptr;
+ xbt_swag_t var_list = nullptr;
+ xbt_swag_t elem_list = nullptr;
+ std::string buf = std::string("MAX-MIN ( ");
/* Printing Objective */
var_list = &(sys->variable_set);
- xbt_strbuff_append(buf, "MAX-MIN ( ");
xbt_swag_foreach(_var, var_list) {
var = (lmm_variable_t)_var;
- xbt_strbuff_printf(buf, "'%d'(%f) ", var->id_int, var->weight);
+ buf = buf + "'" + std::to_string(var->id_int) + "'(" + std::to_string(var->weight) + ") ";
}
- xbt_strbuff_append(buf, ")");
- XBT_DEBUG("%20s", buf->data);
- xbt_strbuff_clear(buf);
+ buf += ")";
+ XBT_DEBUG("%20s", buf.c_str());
+ buf.clear();
XBT_DEBUG("Constraints");
/* Printing Constraints */
cnst_list = &(sys->active_constraint_set);
xbt_swag_foreach(_cnst, cnst_list) {
- cnst = (lmm_constraint_t)_cnst;
- sum = 0.0;
+ cnst = (lmm_constraint_t)_cnst;
+ double sum = 0.0;
//Show the enabled variables
elem_list = &(cnst->enabled_element_set);
- xbt_strbuff_append(buf, "\t");
- xbt_strbuff_printf(buf, "%s(", (cnst->sharing_policy)?"":"max");
+ buf += "\t";
+ buf += ((cnst->sharing_policy) ? "(" : "max(");
xbt_swag_foreach(_elem, elem_list) {
elem = (lmm_element_t)_elem;
- xbt_strbuff_printf(buf, "%f.'%d'(%f) %s ", elem->value,
- elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":",");
+ buf = buf + std::to_string(elem->value) + ".'" + std::to_string(elem->variable->id_int) + "'(" +
+ std::to_string(elem->variable->value) + ")" + ((cnst->sharing_policy) ? " + " : " , ");
if(cnst->sharing_policy)
sum += elem->value * elem->variable->value;
- else
+ else
sum = MAX(sum,elem->value * elem->variable->value);
}
//TODO: Adding disabled elements only for test compatibility, but do we really want them to be printed?
elem_list = &(cnst->disabled_element_set);
xbt_swag_foreach(_elem, elem_list) {
elem = (lmm_element_t)_elem;
- xbt_strbuff_printf(buf, "%f.'%d'(%f) %s ", elem->value,
- elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":",");
+ buf = buf + std::to_string(elem->value) + ".'" + std::to_string(elem->variable->id_int) + "'(" +
+ std::to_string(elem->variable->value) + ")" + ((cnst->sharing_policy) ? " + " : " , ");
if(cnst->sharing_policy)
sum += elem->value * elem->variable->value;
- else
+ else
sum = MAX(sum,elem->value * elem->variable->value);
}
- xbt_strbuff_printf(buf, "0) <= %f ('%d')", cnst->bound, cnst->id_int);
+ buf = buf + "0) <= " + std::to_string(cnst->bound) + " ('" + std::to_string(cnst->id_int) + "')";
- if (!cnst->sharing_policy) {
- xbt_strbuff_printf(buf, " [MAX-Constraint]");
+ if (not cnst->sharing_policy) {
+ buf += " [MAX-Constraint]";
}
- XBT_DEBUG("%s", buf->data);
- xbt_strbuff_clear(buf);
- xbt_assert(!double_positive(sum - cnst->bound, cnst->bound*sg_maxmin_precision),
- "Incorrect value (%f is not smaller than %f): %g", sum, cnst->bound, sum - cnst->bound);
- //if(double_positive(sum - cnst->bound, cnst->bound*sg_maxmin_precision))
- //XBT_ERROR("Incorrect value (%f is not smaller than %f): %g",sum, cnst->bound, sum - cnst->bound);
+ XBT_DEBUG("%s", buf.c_str());
+ buf.clear();
+ xbt_assert(not double_positive(sum - cnst->bound, cnst->bound * sg_maxmin_precision),
+ "Incorrect value (%f is not smaller than %f): %g", sum, cnst->bound, sum - cnst->bound);
+ // if(double_positive(sum - cnst->bound, cnst->bound*sg_maxmin_precision))
+ // XBT_ERROR("Incorrect value (%f is not smaller than %f): %g",sum, cnst->bound, sum - cnst->bound);
}
XBT_DEBUG("Variables");
var = (lmm_variable_t)_var;
if (var->bound > 0) {
XBT_DEBUG("'%d'(%f) : %f (<=%f)", var->id_int, var->weight, var->value, var->bound);
- xbt_assert(!double_positive(var->value - var->bound, var->bound*sg_maxmin_precision),
- "Incorrect value (%f is not smaller than %f", var->value, var->bound);
+ xbt_assert(not double_positive(var->value - var->bound, var->bound * sg_maxmin_precision),
+ "Incorrect value (%f is not smaller than %f", var->value, var->bound);
} else {
XBT_DEBUG("'%d'(%f) : %f", var->id_int, var->weight, var->value);
}
}
-
- xbt_strbuff_free(buf);
}
void lmm_solve(lmm_system_t sys)
double min_usage = -1;
double min_bound = -1;
- if (!(sys->modified))
+ if (not sys->modified)
return;
XBT_IN("(sys=%p)", sys);
/* 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 (!double_positive(cnst->remaining, cnst->bound*sg_maxmin_precision))
+ if (not double_positive(cnst->remaining, cnst->bound * sg_maxmin_precision))
continue;
cnst->usage = 0;
elem_list = &(cnst->enabled_element_set);
make_elem_active(elem);
simgrid::surf::Action *action = static_cast<simgrid::surf::Action*>(elem->variable->id);
- if (sys->keep_track && !action->is_linked())
+ if (sys->keep_track && not action->is_linked())
sys->keep_track->push_back(*action);
}
}
double_update(&(cnst->remaining), elem->value * var->value, cnst->bound*sg_maxmin_precision);
double_update(&(cnst->usage), elem->value / var->weight, sg_maxmin_precision);
//If the constraint is saturated, remove it from the set of active constraints (light_tab)
- if(!double_positive(cnst->usage,sg_maxmin_precision) ||
- !double_positive(cnst->remaining,cnst->bound*sg_maxmin_precision)) {
+ 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 ",
cnst->usage = MAX(cnst->usage, elem->value / elem->variable->weight);
}
//If the constraint is saturated, remove it from the set of active constraints (light_tab)
- if(!double_positive(cnst->usage,sg_maxmin_precision) ||
- !double_positive(cnst->remaining,cnst->bound*sg_maxmin_precision)) {
+ 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 || \t cnst: %p \t cnst->cnst_light: %p "
}
/** \brief Attribute the value bound to var->bound.
- *
+ *
* \param sys the lmm_system_t
* \param var the lmm_variable_t
* \param bound the new bound to associate with var
- *
+ *
* 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.
*/
if(cnstr->concurrency_limit<0)
return 666;
- return cnstr->concurrency_limit - cnstr->concurrency_current;
+ return cnstr->concurrency_limit - cnstr->concurrency_current;
}
/** \brief Measure the minimum concurrency slack across all constraints where the given var is involved */
int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var){
- int i;
- //FIXME MARTIN: Replace by infinite value std::numeric_limits<int>::(max)(), or something better within Simgrid?
- int slack,minslack=666;
- for (i = 0; i < var->cnsts_number; i++) {
- slack=lmm_concurrency_slack(var->cnsts[i].constraint);
+ int minslack = std::numeric_limits<int>::max();
+ for (int i = 0; i < var->cnsts_number; i++) {
+ int slack = lmm_concurrency_slack(var->cnsts[i].constraint);
//This is only an optimization, to avoid looking at more constraints when slack is already zero
//Disable it when debugging to let lmm_concurrency_slack catch nasty things
- if(!slack && !XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug))
+ if (not slack && not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug))
return 0;
if(minslack>slack)
/* /Check if a variable can be enabled
*
- * Make sure to set staged_weight before, if your intent is only to check concurrency
+ * Make sure to set staged_weight before, if your intent is only to check concurrency
*/
int lmm_can_enable_var(lmm_variable_t var){
return var->staged_weight>0 && lmm_cnstrs_min_concurrency_slack(var)>=var->concurrency_share;
//When used within lmm_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 lmm_check_concurrency() in the end.
// lmm_check_concurrency(sys);
}
int i;
lmm_element_t elem;
- xbt_assert(!var->staged_weight,"Staged weight should have been cleared");
+ xbt_assert(not var->staged_weight, "Staged weight should have been cleared");
//Disabling the variable, move to var to list tail. Subtility is: here, we need to call lmm_update_modified_set BEFORE
//moving the last element of var.
xbt_swag_remove(var, &(sys->variable_set));
var->value = 0.0;
lmm_check_concurrency(sys);
}
-
+
/* /brief Find variables that can be enabled and enable them.
- *
+ *
* Assuming that the variable has already been removed from non-zero weights
* Can we find a staged variable to add?
* 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){
- lmm_element_t elem;
- lmm_element_t nextelem;
- int numelem;
if(cnstr->concurrency_limit<0)
return;
- numelem=xbt_swag_size(&(cnstr->disabled_element_set));
- if(!numelem)
+ int numelem = xbt_swag_size(&(cnstr->disabled_element_set));
+ if (not numelem)
return;
- elem= (lmm_element_t) xbt_swag_getFirst(&(cnstr->disabled_element_set));
+ 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
- while(numelem-- && elem ){
+ while (numelem-- && elem) {
- nextelem = (lmm_element_t) xbt_swag_getNext(elem, cnstr->disabled_element_set.offset);
+ lmm_element_t nextelem = (lmm_element_t)xbt_swag_getNext(elem, cnstr->disabled_element_set.offset);
if (elem->variable->staged_weight>0 ){
//Found a staged variable
//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 lmm_check_concurrency() in the end.
// lmm_check_concurrency(sys);
}
*/
void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double weight)
{
- int minslack;
xbt_assert(weight>=0,"Variable weight should not be negative!");
//Are we enabling this variable?
if (enabling_var){
var->staged_weight = weight;
- minslack=lmm_cnstrs_min_concurrency_slack(var);
- if(minslack<var->concurrency_share){
+ int minslack = lmm_cnstrs_min_concurrency_slack(var);
+ 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);
return;
lmm_check_concurrency(sys);
XBT_OUT();
- return;
}
double lmm_get_variable_weight(lmm_variable_t var)
s_lmm_element_t *cnsts = var->cnsts;
int i;
for (i = 0; var->visited != sys->visited_counter && i < var->cnsts_number ; i++) {
- if (cnsts[i].constraint != cnst && !xbt_swag_belongs(cnsts[i].constraint, &sys->modified_constraint_set)) {
+ if (cnsts[i].constraint != cnst && not xbt_swag_belongs(cnsts[i].constraint, &sys->modified_constraint_set)) {
xbt_swag_insert(cnsts[i].constraint, &sys->modified_constraint_set);
lmm_update_modified_set_rec(sys, cnsts[i].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 = sys->visited_counter;
}
}
static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst)
{
/* nothing to do if selective update isn't active */
- if (sys->selective_update_active && !xbt_swag_belongs(cnst, &sys->modified_constraint_set)) {
+ 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);
}
void *_var;
xbt_swag_foreach(_var, &sys->variable_set)
((lmm_variable_t)_var)->visited = 0;
- }
+ }
xbt_swag_reset(&sys->modified_constraint_set);
}
if (cnst->sharing_policy)
usage += elem->value * elem->variable->value;
else if (usage < elem->value * elem->variable->value)
- usage = max(usage, elem->value * elem->variable->value);
+ usage = std::max(usage, elem->value * elem->variable->value);
}
}
return usage;
}
+int lmm_constraint_get_variable_amount(lmm_constraint_t cnst) {
+ int usage = 0;
+ xbt_swag_t elem_list = &(cnst->enabled_element_set);
+ void *_elem;
-void lmm_check_concurrency(lmm_system_t sys){
- void* _cnst;
- void* _elem;
- void* _var;
- lmm_element_t elem;
- lmm_constraint_t cnst;
- lmm_variable_t var;
- int concurrency;
- int i,belong_to_enabled,belong_to_disabled,belong_to_active;
+ xbt_swag_foreach(_elem, elem_list) {
+ lmm_element_t elem = (lmm_element_t)_elem;
+ if (elem->value > 0)
+ usage++;
+ }
+ return usage;
+}
+void lmm_check_concurrency(lmm_system_t sys){
//These checks are very expensive, so do them only if we want to debug SURF LMM
if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
- xbt_swag_foreach(_cnst, &(sys->constraint_set)) {
- cnst = (lmm_constraint_t) _cnst;
- concurrency=0;
- xbt_swag_foreach(_elem, &(cnst->enabled_element_set)) {
- elem = (lmm_element_t)_elem;
+ void* cnstIt;
+ xbt_swag_foreach(cnstIt, &(sys->constraint_set))
+ {
+ lmm_constraint_t cnst = (lmm_constraint_t)cnstIt;
+ int concurrency = 0;
+ void* elemIt;
+ xbt_swag_foreach(elemIt, &(cnst->enabled_element_set))
+ {
+ lmm_element_t elem = (lmm_element_t)elemIt;
xbt_assert(elem->variable->weight > 0);
concurrency+=lmm_element_concurrency(elem);
}
- xbt_swag_foreach(_elem, &(cnst->disabled_element_set)) {
- elem = (lmm_element_t)_elem;
+ xbt_swag_foreach(elemIt, &(cnst->disabled_element_set))
+ {
+ lmm_element_t elem = (lmm_element_t)elemIt;
//We should have staged variables only if concurrency is reached in some constraint
xbt_assert(cnst->concurrency_limit<0 || elem->variable->staged_weight==0 ||
lmm_cnstrs_min_concurrency_slack(elem->variable) < elem->variable->concurrency_share,
}
//Check that for each variable, all corresponding elements are in the same state (i.e. same element sets)
- xbt_swag_foreach(_var, &(sys->variable_set)) {
- var= (lmm_variable_t) _var;
+ void* varIt;
+ xbt_swag_foreach(varIt, &(sys->variable_set))
+ {
+ lmm_variable_t var = (lmm_variable_t)varIt;
- if(!var->cnsts_number)
+ if (not var->cnsts_number)
continue;
- elem = &var->cnsts[0];
- belong_to_enabled=xbt_swag_belongs(elem,&(elem->constraint->enabled_element_set));
- belong_to_disabled=xbt_swag_belongs(elem,&(elem->constraint->disabled_element_set));
- belong_to_active=xbt_swag_belongs(elem,&(elem->constraint->active_element_set));
+ lmm_element_t elem = &var->cnsts[0];
+ int belong_to_enabled = xbt_swag_belongs(elem, &(elem->constraint->enabled_element_set));
+ int belong_to_disabled = xbt_swag_belongs(elem, &(elem->constraint->disabled_element_set));
+ int belong_to_active = xbt_swag_belongs(elem, &(elem->constraint->active_element_set));
- for (i = 1; i < var->cnsts_number; i++) {
+ for (int i = 1; i < var->cnsts_number; i++) {
elem = &var->cnsts[i];
xbt_assert(belong_to_enabled==xbt_swag_belongs(elem,&(elem->constraint->enabled_element_set)),
"Variable inconsistency (1): enabled_element_set");