-/* $Id$ */
-
-/* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
+/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. 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. */
static void *lmm_variable_mallocator_new_f(void);
static void lmm_variable_mallocator_free_f(void *var);
static void lmm_variable_mallocator_reset_f(void *var);
-static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst);
+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);
-int sg_maxmin_selective_update = 0;
+int sg_maxmin_selective_update = 1;
static int Global_debug_id = 1;
static int Global_const_debug_id = 1;
lmm_system_t lmm_system_new(void)
lmm_variable_t var = NULL;
lmm_constraint_t cnst = NULL;
- while ((var = extract_variable(sys)))
+ while ((var = extract_variable(sys))) {
+ WARN2
+ ("Variable %p (%d) still in LMM system when freing it: this may be a bug",
+ var, var->id_int);
lmm_var_free(sys, var);
+ }
while ((cnst = extract_constraint(sys)))
lmm_cnst_free(sys, cnst);
free(sys);
}
-void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var)
+XBT_INLINE void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var)
{
int i;
lmm_element_t elem = NULL;
xbt_mallocator_release(sys->variable_mallocator, var);
}
-static void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst)
+static XBT_INLINE void lmm_cnst_free(lmm_system_t sys,
+ lmm_constraint_t cnst)
{
/* xbt_assert0(xbt_swag_size(&(cnst->element_set)), */
/* "This list should be empty!"); */
return cnst;
}
-void lmm_constraint_shared(lmm_constraint_t cnst)
+XBT_INLINE void lmm_constraint_shared(lmm_constraint_t cnst)
{
cnst->shared = 0;
}
-int lmm_constraint_is_shared(lmm_constraint_t cnst)
+XBT_INLINE int lmm_constraint_is_shared(lmm_constraint_t cnst)
{
return (cnst->shared);
}
-void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst)
+XBT_INLINE void lmm_constraint_free(lmm_system_t sys,
+ lmm_constraint_t cnst)
{
remove_constraint(sys, cnst);
lmm_cnst_free(sys, cnst);
lmm_var_free(sys, var);
}
-double lmm_variable_getvalue(lmm_variable_t var)
+XBT_INLINE double lmm_variable_getvalue(lmm_variable_t var)
{
return (var->value);
}
-double lmm_variable_getbound(lmm_variable_t var)
+XBT_INLINE double lmm_variable_getbound(lmm_variable_t var)
{
return (var->bound);
}
DIE_IMPOSSIBLE;
}
-lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
- lmm_variable_t var, int num)
+XBT_INLINE lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
+ lmm_variable_t var,
+ int num)
{
if (num < var->cnsts_number)
return (var->cnsts[num].constraint);
return NULL;
}
-int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var)
+XBT_INLINE int lmm_get_number_of_cnst_from_var(lmm_system_t sys,
+ lmm_variable_t var)
{
return (var->cnsts_number);
}
return NULL;
}
-void *lmm_constraint_id(lmm_constraint_t cnst)
+XBT_INLINE void *lmm_constraint_id(lmm_constraint_t cnst)
{
return cnst->id;
}
-void *lmm_variable_id(lmm_variable_t var)
+XBT_INLINE void *lmm_variable_id(lmm_variable_t var)
{
return var->id;
}
-static void saturated_constraint_set_update(lmm_system_t sys,
- lmm_constraint_t cnst,
- double *min_usage)
+static XBT_INLINE void saturated_constraint_set_update(lmm_system_t sys,
+ lmm_constraint_t
+ cnst,
+ double *min_usage)
{
lmm_constraint_t useless_cnst = NULL;
XBT_OUT;
}
-static void saturated_variable_set_update(lmm_system_t sys)
+static XBT_INLINE void saturated_variable_set_update(lmm_system_t sys)
{
lmm_constraint_t cnst = NULL;
xbt_swag_t cnst_list = NULL;
var_list = &(sys->variable_set);
sprintf(print_buf, "MAX-MIN ( ");
trace_buf =
- xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
+ xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
strcat(trace_buf, print_buf);
xbt_swag_foreach(var, var_list) {
sprintf(print_buf, "'%d'(%f) ", var->id_int, var->weight);
trace_buf =
- xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
+ xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
strcat(trace_buf, print_buf);
}
sprintf(print_buf, ")");
trace_buf =
- xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
+ xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
strcat(trace_buf, print_buf);
fprintf(stderr, "%s", trace_buf);
//DEBUG1("%20s", trace_buf); FIXME
elem_list = &(cnst->element_set);
sprintf(print_buf, "\t");
trace_buf =
- xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
+ xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
strcat(trace_buf, print_buf);
+ sprintf(print_buf, "%s(",(cnst->shared)?"":"max");
+ trace_buf =
+ xbt_realloc(trace_buf,
+ strlen(trace_buf) + strlen(print_buf) + 1);
+ strcat(trace_buf, print_buf);
xbt_swag_foreach(elem, elem_list) {
- sprintf(print_buf, "%f.'%d'(%f) + ", elem->value,
- elem->variable->id_int, elem->variable->value);
+ sprintf(print_buf, "%f.'%d'(%f) %s ", elem->value,
+ elem->variable->id_int, elem->variable->value,(cnst->shared)?"+":",");
trace_buf =
- xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
+ xbt_realloc(trace_buf,
+ strlen(trace_buf) + strlen(print_buf) + 1);
strcat(trace_buf, print_buf);
- sum += elem->value * elem->variable->value;
+ if(cnst->shared)
+ sum += elem->value * elem->variable->value;
+ else
+ sum = MAX(sum,elem->value * elem->variable->value);
}
- sprintf(print_buf, "0 <= %f ('%d')", cnst->bound, cnst->id_int);
+ sprintf(print_buf, "0) <= %f ('%d')", cnst->bound, cnst->id_int);
trace_buf =
- xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
+ xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
strcat(trace_buf, print_buf);
if (!cnst->shared) {
sprintf(print_buf, " [MAX-Constraint]");
trace_buf =
- xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
+ xbt_realloc(trace_buf,
+ strlen(trace_buf) + strlen(print_buf) + 1);
strcat(trace_buf, print_buf);
}
// DEBUG1("%s", trace_buf);
- fprintf(stderr, "%s", trace_buf);
+ fprintf(stderr, "%s\n", trace_buf);
trace_buf[0] = '\000';
xbt_assert3(!double_positive(sum - cnst->bound),
"Incorrect value (%f is not smaller than %f): %g",
if (!(sys->modified))
return;
+ XBT_IN1("(sys=%p)", sys);
+
/*
* Compute Usage and store the variables that reach the maximum.
*/
- cnst_list = sys->selective_update_active ? &(sys->modified_constraint_set) :
- &(sys->active_constraint_set);
+ cnst_list =
+ sys->
+ selective_update_active ? &(sys->modified_constraint_set) :
+ &(sys->active_constraint_set);
DEBUG1("Active constraints : %d", xbt_swag_size(cnst_list));
/* Init: Only modified code portions */
}
}
- /* Init: special case where all constraints are 0 */
- var_list = &(sys->variable_set);
- DEBUG1("Variable set : %d", xbt_swag_size(var_list));
- xbt_swag_foreach(var, var_list) {
- int nb = 0;
- int i;
- if (var->weight <= 0.0)
- break;
- for (i = 0; i < var->cnsts_number; i++) {
- if (var->cnsts[i].value == 0.0)
- nb++;
- }
- if ((nb == var->cnsts_number) && (var->weight > 0.0))
- var->value = 1.0;
- }
-
- DEBUG1("Active constraints : %d", xbt_swag_size(cnst_list));
xbt_swag_foreach(cnst, cnst_list) {
/* INIT */
cnst->remaining = cnst->bound;
+ if (cnst->remaining == 0)
+ continue;
cnst->usage = 0;
elem_list = &(cnst->element_set);
- cnst->usage = 0.0;
xbt_swag_foreach(elem, elem_list) {
/* 0-weighted elements (ie, sleep actions) are at the end of the swag and we don't want to consider them */
if (elem->variable->weight <= 0)
make_elem_active(elem);
}
}
- DEBUG2("Constraint Usage %d : %f", cnst->id_int, cnst->usage);
+ DEBUG2("Constraint Usage '%d' : %f", cnst->id_int, cnst->usage);
/* Saturated constraints update */
saturated_constraint_set_update(sys, cnst, &min_usage);
}
/* First check if some of these variables have reach their upper
bound and update min_usage accordingly. */
DEBUG5
- ("var=%d, var->bound=%f, var->weight=%f, min_usage=%f, var->bound*var->weight=%f",
- var->id_int, var->bound, var->weight, min_usage,
- var->bound * var->weight);
+ ("var=%d, var->bound=%f, var->weight=%f, min_usage=%f, var->bound*var->weight=%f",
+ var->id_int, var->bound, var->weight, min_usage,
+ var->bound * var->weight);
if ((var->bound > 0) && (var->bound * var->weight < min_usage)) {
if (min_bound < 0)
min_bound = var->bound;
} else { /* FIXME one day: We recompute usage.... :( */
cnst->usage = 0.0;
make_elem_inactive(elem);
+ elem_list = &(cnst->element_set);
xbt_swag_foreach(elem, elem_list) {
if (elem->variable->weight <= 0)
break;
if (elem->variable->value > 0)
break;
if ((elem->value > 0)) {
- if (cnst->usage < elem->value / elem->variable->weight)
- cnst->usage = elem->value / elem->variable->weight;
- DEBUG2("Constraint Usage %d : %f", cnst->id_int, cnst->usage);
+ cnst->usage =
+ MAX(cnst->usage, elem->value / elem->variable->weight);
+ DEBUG2("Constraint Usage %d : %f", cnst->id_int,
+ cnst->usage);
make_elem_active(elem);
}
}
/* Find out which variables reach the maximum */
cnst_list =
- sys->selective_update_active ? &(sys->modified_constraint_set) :
- &(sys->active_constraint_set);
+ sys->selective_update_active ? &(sys->modified_constraint_set) :
+ &(sys->active_constraint_set);
min_usage = -1;
min_bound = -1;
xbt_swag_foreach(cnst, cnst_list) {
if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
lmm_print(sys);
}
+ XBT_OUT;
}
/* Not a O(1) function */
XBT_OUT;
}
-double lmm_get_variable_weight(lmm_variable_t var)
+XBT_INLINE double lmm_get_variable_weight(lmm_variable_t var)
{
return var->weight;
}
-void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst,
- double bound)
+XBT_INLINE void lmm_update_constraint_bound(lmm_system_t sys,
+ lmm_constraint_t cnst,
+ double bound)
{
sys->modified = 1;
lmm_update_modified_set(sys, cnst);
cnst->bound = bound;
}
-int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst)
+XBT_INLINE int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst)
{
return xbt_swag_belongs(cnst, &(sys->active_constraint_set));
}
-lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys)
+XBT_INLINE lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t
+ sys)
{
return xbt_swag_getFirst(&(sys->active_constraint_set));
}
-lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys,
- lmm_constraint_t cnst)
+XBT_INLINE lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t
+ sys,
+ lmm_constraint_t
+ cnst)
{
return xbt_swag_getNext(cnst, (sys->active_constraint_set).offset);
}
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+XBT_INLINE int lmm_is_variable_limited_by_latency(lmm_variable_t var)
+{
+ return (double_equals(var->bound, var->value));
+}
+#endif
+
+
/** \brief Update the constraint set propagating recursively to
* other constraints so the system should not be entirely computed.
*
* constraints that have changed. Each constraint change is propagated
* to the list of constraints for each variable.
*/
-static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst)
+static void lmm_update_modified_set(lmm_system_t sys,
+ lmm_constraint_t cnst)
{
lmm_element_t elem = NULL;
lmm_variable_t var = NULL;