Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use doxygen's section instead of my poor approximation; link to the list of all exist...
[simgrid.git] / src / surf / workstation_KCCFLN05.c
index e3c3d91..6f816dd 100644 (file)
@@ -362,7 +362,8 @@ static void action_network_KCCFLN05_free(surf_action_t action)
   workstation_KCCFLN05_t dst = ((surf_action_network_KCCFLN05_t) action)->dst;
 
   xbt_swag_remove(action, action->state_set);
-  lmm_variable_free(maxmin_system_network_KCCFLN05, 
+  if(((surf_action_network_KCCFLN05_t)action)->variable)
+    lmm_variable_free(maxmin_system_network_KCCFLN05, 
                    ((surf_action_network_KCCFLN05_t) action)->variable);
 
   xbt_dynar_foreach (src->outgoing_communications,cpt,act) {
@@ -394,6 +395,31 @@ static double share_network_KCCFLN05_resources(double now)
 static void action_network_KCCFLN05_change_state(surf_action_t action,
                                                 e_surf_action_state_t state)
 {
+  int cpt;
+  surf_action_t act = NULL;
+  workstation_KCCFLN05_t src = ((surf_action_network_KCCFLN05_t) action)->src;
+  workstation_KCCFLN05_t dst = ((surf_action_network_KCCFLN05_t) action)->dst;
+
+  if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED))
+    if(((surf_action_network_KCCFLN05_t)action)->variable) {
+      lmm_variable_disable(maxmin_system_network_KCCFLN05, 
+                          ((surf_action_network_KCCFLN05_t)action)->variable);
+      ((surf_action_network_KCCFLN05_t)action)->variable = NULL;
+    }
+
+  xbt_dynar_foreach (src->outgoing_communications,cpt,act) {
+    if(act==action) {
+      xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
+      break;
+    }
+  }
+
+  xbt_dynar_foreach (dst->incomming_communications,cpt,act) {
+    if(act==action) {
+      xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
+      break;
+    }
+  }
   surf_action_change_state(action, state);
   return;
 }
@@ -425,10 +451,6 @@ static void update_actions_network_KCCFLN05_state(double now, double delta)
     }
   }
 
-  xbt_swag_foreach_safe(action, next_action, failed_actions) {
-    lmm_variable_disable(maxmin_system_network_KCCFLN05, action->variable);
-  }
-
   return;
 }
 
@@ -501,10 +523,25 @@ static int network_KCCFLN05_action_is_suspended(surf_action_t action)
 static void action_cpu_KCCFLN05_free(surf_action_t action)
 {
   xbt_swag_remove(action, action->state_set);
-  lmm_variable_free(maxmin_system_cpu_KCCFLN05, ((surf_action_cpu_KCCFLN05_t)action)->variable);
+  if(((surf_action_cpu_KCCFLN05_t)action)->variable)
+    lmm_variable_free(maxmin_system_cpu_KCCFLN05, ((surf_action_cpu_KCCFLN05_t)action)->variable);
   xbt_free(action);
 }
 
+static void action_cpu_KCCFLN05_change_state(surf_action_t action,
+                               e_surf_action_state_t state)
+{
+  if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED))
+    if(((surf_action_cpu_KCCFLN05_t)action)->variable) {
+      lmm_variable_disable(maxmin_system_cpu_KCCFLN05, 
+                          ((surf_action_cpu_KCCFLN05_t)action)->variable);
+      ((surf_action_cpu_KCCFLN05_t)action)->variable = NULL;
+    }
+
+  surf_action_change_state(action, state);
+  return;
+}
+
 /* #define WARNING(format, ...) (fprintf(stderr, "[%s , %s : %d] ", __FILE__, __FUNCTION__, __LINE__),\ */
 /*                               fprintf(stderr, format, ## __VA_ARGS__), \ */
 /*                               fprintf(stderr, "\n")) */
@@ -522,6 +559,11 @@ static double share_cpu_KCCFLN05_resources(double now)
   int cpt;
   surf_action_network_KCCFLN05_t action;
 
+  if(surf_get_clock()>=475.895) 
+    {
+      W=0.0;
+    }
+
   for(cnst = lmm_get_first_active_constraint(maxmin_system_cpu_KCCFLN05);
       cnst;
       cnst= lmm_get_next_active_constraint(maxmin_system_cpu_KCCFLN05, cnst))
@@ -594,11 +636,11 @@ static void update_actions_cpu_KCCFLN05_state(double now, double delta)
     if ((action->generic_action.remains <= 0) && 
        (lmm_get_variable_weight(action->variable)>0)) {
       action->generic_action.finish = surf_get_clock();
-      surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
+      action_cpu_KCCFLN05_change_state((surf_action_t) action, SURF_ACTION_DONE);
     } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
               (action->generic_action.max_duration <= 0)) {
       action->generic_action.finish = surf_get_clock();
-      surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
+      action_cpu_KCCFLN05_change_state((surf_action_t) action, SURF_ACTION_DONE);
     } else {                   /* Need to check that none of the resource has failed */
       lmm_constraint_t cnst = NULL;
       int i = 0;
@@ -610,17 +652,13 @@ static void update_actions_cpu_KCCFLN05_state(double now, double delta)
        cpu = lmm_constraint_id(cnst);
        if (cpu->state_current == SURF_CPU_OFF) {
          action->generic_action.finish = surf_get_clock();
-         surf_action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
+         action_cpu_KCCFLN05_change_state((surf_action_t) action, SURF_ACTION_FAILED);
          break;
        }
       }
     }
   }
 
-  xbt_swag_foreach_safe(action, next_action, failed_actions) {
-    lmm_variable_disable(maxmin_system_cpu_KCCFLN05, action->variable);
-  }
-
   return;
 }
 
@@ -675,14 +713,21 @@ static int cpu_KCCFLN05_action_is_suspended(surf_action_t action)
 static void action_change_state(surf_action_t action,
                                e_surf_action_state_t state)
 {
-  xbt_assert0(0, "Workstation is a virtual resource. I should not be there!");
-  surf_action_change_state(action, state);
+  if(action->resource_type==(surf_resource_t)surf_network_resource) 
+    surf_network_resource->common_public->action_change_state(action,state);
+  else if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
+    surf_cpu_resource->common_public->action_change_state(action,state);
+  else DIE_IMPOSSIBLE;
   return;
 }
 
 static void action_free(surf_action_t action)
 {
-  xbt_assert0(0, "Workstation is a virtual resource. I should not be there!");
+  if(action->resource_type==(surf_resource_t)surf_network_resource) 
+    surf_network_resource->common_public->action_free(action);
+  else if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
+    surf_cpu_resource->common_public->action_free(action);
+  else DIE_IMPOSSIBLE;
   return;
 }
 
@@ -792,7 +837,7 @@ static void cpu_KCCFLN05_resource_init_internal(void)
   surf_cpu_resource->common_public->action_free = action_cpu_KCCFLN05_free;
   surf_cpu_resource->common_public->action_cancel = NULL;
   surf_cpu_resource->common_public->action_recycle = NULL;
-  surf_cpu_resource->common_public->action_change_state = surf_action_change_state;
+  surf_cpu_resource->common_public->action_change_state = action_cpu_KCCFLN05_change_state;
   surf_cpu_resource->common_public->action_set_data = surf_action_set_data;
   surf_cpu_resource->common_public->name = "CPU KCCFLN05";