Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
isolating latency bounded functions with ifdef's
[simgrid.git] / src / surf / maxmin.c
index b8e210d..accceb5 100644 (file)
@@ -1,6 +1,5 @@
-/*     $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. */
@@ -21,7 +20,7 @@ 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_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)
@@ -66,8 +65,11 @@ void lmm_system_free(lmm_system_t sys)
   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);
@@ -76,7 +78,7 @@ void lmm_system_free(lmm_system_t sys)
   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;
@@ -105,7 +107,7 @@ static void lmm_var_free(lmm_system_t sys, lmm_variable_t var)
   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!"); */
@@ -135,17 +137,17 @@ lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id,
   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);
@@ -218,12 +220,12 @@ void lmm_variable_free(lmm_system_t sys, lmm_variable_t var)
   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);
 }
@@ -289,7 +291,7 @@ void lmm_elem_set_value(lmm_system_t sys, lmm_constraint_t cnst,
     DIE_IMPOSSIBLE;
 }
 
-lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
+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)
@@ -298,7 +300,7 @@ lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
     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);
 }
@@ -317,17 +319,17 @@ lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys,
     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,
+static XBT_INLINE void saturated_constraint_set_update(lmm_system_t sys,
                                             lmm_constraint_t cnst,
                                             double *min_usage)
 {
@@ -358,7 +360,7 @@ static void saturated_constraint_set_update(lmm_system_t sys,
   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;
@@ -501,9 +503,10 @@ void lmm_solve(lmm_system_t sys)
   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)
@@ -577,14 +580,14 @@ void lmm_solve(lmm_system_t sys)
         } 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;
+              cnst->usage=MAX(cnst->usage,elem->value / elem->variable->weight);
               DEBUG2("Constraint Usage %d : %f", cnst->id_int, cnst->usage);
               make_elem_active(elem);
             }
@@ -691,12 +694,12 @@ void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var,
   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,
+XBT_INLINE void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst,
                                  double bound)
 {
   sys->modified = 1;
@@ -704,22 +707,30 @@ void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t 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,
+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.
  *