Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Handle failed tasks in update_resource_state function instead of the update_action_st...
[simgrid.git] / src / surf / network.c
index f8e841b..c2ed3ea 100644 (file)
@@ -6,8 +6,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "network_private.h"
-#include "cpu_private.h"
 #include "xbt/log.h"
+#include "xbt/str.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
                                "Logging specific to the SURF network module");
@@ -427,8 +427,6 @@ static void update_actions_state(double now, double delta)
     if (action->generic_action.max_duration != NO_MAX_DURATION)
       double_update(&(action->generic_action.max_duration), delta);
 
-    /*   if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
-
     if ((action->generic_action.remains <= 0) &&
        (lmm_get_variable_weight(action->variable) > 0)) {
       action->generic_action.finish = surf_get_clock();
@@ -437,21 +435,6 @@ static void update_actions_state(double now, double delta)
               (action->generic_action.max_duration <= 0)) {
       action->generic_action.finish = surf_get_clock();
       action_change_state((surf_action_t) action, SURF_ACTION_DONE);
-    } else {                   /* Need to check that none of the model has failed */
-      lmm_constraint_t cnst = NULL;
-      int i = 0;
-      link_CM02_t nw_link = NULL;
-
-      while ((cnst =
-             lmm_get_cnst_from_var(network_maxmin_system,
-                                   action->variable, i++))) {
-       nw_link = lmm_constraint_id(cnst);
-       if (nw_link->state_current == SURF_LINK_OFF) {
-         action->generic_action.finish = surf_get_clock();
-         action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
-         break;
-       }
-      }
     }
   }
 
@@ -460,7 +443,7 @@ static void update_actions_state(double now, double delta)
 
 static void update_resource_state(void *id,
                                  tmgr_trace_event_t event_type,
-                                 double value)
+                                 double value, double date)
 {
   link_CM02_t nw_link = id;
   /*   printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
@@ -474,11 +457,12 @@ static void update_resource_state(void *id,
   } else if (event_type == nw_link->lat_event) {
     double delta = value - nw_link->lat_current;
     lmm_variable_t var = NULL;
+    lmm_element_t elem = NULL;
     surf_action_network_CM02_t action = NULL;
 
     nw_link->lat_current = value;
-    while (lmm_get_var_from_cnst
-          (network_maxmin_system, nw_link->constraint, &var)) {
+    while ((var= lmm_get_var_from_cnst
+          (network_maxmin_system, nw_link->constraint, &elem))) {
       action = lmm_variable_id(var);
       action->lat_current += delta;
       if (action->rate < 0)
@@ -501,8 +485,23 @@ static void update_resource_state(void *id,
   } else if (event_type == nw_link->state_event) {
     if (value > 0)
       nw_link->state_current = SURF_LINK_ON;
-    else
+    else {
+      lmm_constraint_t cnst = nw_link->constraint;
+      lmm_variable_t var = NULL;
+      lmm_element_t elem = NULL;
+
       nw_link->state_current = SURF_LINK_OFF;
+      while ((var= lmm_get_var_from_cnst
+             (network_maxmin_system, cnst, &elem))) {
+       surf_action_t action = lmm_variable_id(var) ;
+
+       if(surf_action_get_state(action)==SURF_ACTION_RUNNING ||
+          surf_action_get_state(action)==SURF_ACTION_READY) {
+         action->finish = date;
+         action_change_state( action, SURF_ACTION_FAILED);
+       }
+      }
+    }
   } else {
     CRITICAL0("Unknown event ! \n");
     xbt_abort();
@@ -547,7 +546,13 @@ static surf_action_t communicate(void *src, void *dst, double size,
                                   calloc but it seems to help valgrind... */
   action->generic_action.state_set =
       surf_network_model->common_public->states.running_action_set;
-
+  for (i = 0; i < route_size; i++) 
+    if(route[i]->state_current == SURF_LINK_OFF) {
+      action->generic_action.state_set =
+       surf_network_model->common_public->states.failed_action_set;
+      break;
+    }
+  
   xbt_swag_insert(action, action->generic_action.state_set);
   action->rate = rate;