Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't use %t in log format, but %P; revalidate the output after listener introduction
[simgrid.git] / src / simdag / sd_global.c
index aea07a1..d1a3ae7 100644 (file)
@@ -20,11 +20,12 @@ SD_global_t sd_global = NULL;
  * \see SD_create_environment(), SD_exit()
  */
 void SD_init(int *argc, char **argv) {
-  if (SD_INITIALISED()) {
-    xbt_assert0(0, "SD_init() already called");
-  }
 
-  sd_global = xbt_new0(s_SD_global_t, 1);
+  s_SD_task_t task;
+  
+  xbt_assert0( !SD_INITIALISED() , "SD_init() already called");
+
+  sd_global = xbt_new(s_SD_global_t, 1);
   sd_global->workstations = xbt_dict_new();
   sd_global->workstation_count = 0;
   sd_global->workstation_list = NULL;
@@ -34,7 +35,6 @@ void SD_init(int *argc, char **argv) {
   sd_global->recyclable_route = NULL;
   sd_global->watch_point_reached = 0;
 
-  s_SD_task_t task;
   sd_global->not_scheduled_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
   sd_global->scheduled_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
   sd_global->ready_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
@@ -42,10 +42,54 @@ void SD_init(int *argc, char **argv) {
   sd_global->running_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
   sd_global->done_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
   sd_global->failed_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
+  sd_global->task_number = 0;
 
   surf_init(argc, argv);
 }
 
+/**
+ * \brief Reinits the application part of the simulation (experimental feature)
+ * 
+ * This function allows you to run several simulations on the same platform 
+ * by resetting the part describing the application. 
+ * 
+ * @warning: this function is still experimental and not perfect. For example,
+ * the simulation clock (and traces usage) is not reset. So, do not use it if
+ * you use traces in your simulation, and do not use absolute timing after using it.
+ * That being said, this function is still precious if you want to compare a bunch of
+ * heuristics on the same platforms.
+ */
+void SD_application_reinit(void) {
+   
+  s_SD_task_t task;
+   
+  if (SD_INITIALISED()) {
+    DEBUG0("Recreating the swags...");
+    xbt_swag_free(sd_global->not_scheduled_task_set);
+    xbt_swag_free(sd_global->scheduled_task_set);
+    xbt_swag_free(sd_global->ready_task_set);
+    xbt_swag_free(sd_global->in_fifo_task_set);
+    xbt_swag_free(sd_global->running_task_set);
+    xbt_swag_free(sd_global->done_task_set);
+    xbt_swag_free(sd_global->failed_task_set);
+
+    sd_global->not_scheduled_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
+    sd_global->scheduled_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
+    sd_global->ready_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
+    sd_global->in_fifo_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
+    sd_global->running_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
+    sd_global->done_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
+    sd_global->failed_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
+    sd_global->task_number = 0;
+  } else {
+    WARN0("SD_application_reinit called before initialization of SimDag");
+    /* we cannot use exceptions here because xbt is not running! */
+  }
+
+}
+
+
+
 /**
  * \brief Creates the environment
  *
@@ -89,6 +133,8 @@ void SD_create_environment(const char *platform_file) {
   xbt_dict_foreach(network_link_set, cursor, name, surf_link) {
     __SD_link_create(surf_link, NULL);
   }
+
+  DEBUG2("Workstation number: %d, link number: %d", SD_workstation_get_number(), SD_link_get_number());
 }
 
 /**
@@ -112,7 +158,7 @@ SD_task_t* SD_simulate(double how_long)
   surf_action_t action;
   SD_task_t *changed_tasks = NULL;
   int changed_task_number = 0;
-  int changed_task_capacity = 16; /* will be increased if necessary */
+  int changed_task_capacity = sd_global->task_number + 1;
   int i;
   static int first_time = 1;
 
@@ -121,7 +167,7 @@ SD_task_t* SD_simulate(double how_long)
   INFO0("Starting simulation...");
 
   /* create the array that will be returned */
-  changed_tasks = xbt_new0(SD_task_t, changed_task_capacity);
+  changed_tasks = xbt_new(SD_task_t, changed_task_capacity);
   changed_tasks[0] = NULL;
 
   if (first_time) {
@@ -129,6 +175,10 @@ SD_task_t* SD_simulate(double how_long)
     first_time = 0;
   }
 
+  if(how_long>0) {
+    surf_timer_resource->extension_public->set(surf_get_clock()+how_long,
+                                              NULL,NULL);
+  }
   sd_global->watch_point_reached = 0;
 
   /* explore the ready tasks */
@@ -136,10 +186,12 @@ SD_task_t* SD_simulate(double how_long)
     INFO1("Executing task '%s'", SD_task_get_name(task));
     if ((task->state_changed = __SD_task_try_to_run(task))) {
       changed_tasks[changed_task_number++] = task; /* replace NULL by the task */
+      /*
       if (changed_task_number == changed_task_capacity) {
        changed_task_capacity *= 2;
        changed_tasks = xbt_realloc(changed_tasks, sizeof(SD_task_t) * changed_task_capacity);
       }
+      */
       changed_tasks[changed_task_number] = NULL;
     }
   }
@@ -149,6 +201,10 @@ SD_task_t* SD_simulate(double how_long)
   while (elapsed_time >= 0.0 &&
         (how_long < 0.0 || total_time < how_long) &&
         !sd_global->watch_point_reached) {
+    /* dumb variables */
+    void *fun = NULL;
+    void *arg = NULL;
+
 
     DEBUG1("Total time: %f", total_time);
 
@@ -169,10 +225,12 @@ SD_task_t* SD_simulate(double how_long)
       if (!task->state_changed) {
        task->state_changed = 1;
        changed_tasks[changed_task_number++] = task;
+       /*
        if (changed_task_number == changed_task_capacity) {
          changed_task_capacity *= 2;
          changed_tasks = xbt_realloc(changed_tasks, sizeof(SD_task_t) * changed_task_capacity);
        }
+       */
        changed_tasks[changed_task_number] = NULL;
       }
 
@@ -187,10 +245,12 @@ SD_task_t* SD_simulate(double how_long)
          INFO1("Executing task '%s'", SD_task_get_name(dst));
          if (__SD_task_try_to_run(dst)) {
            changed_tasks[changed_task_number++] = dst;
+           /*
            if (changed_task_number == changed_task_capacity) {
              changed_task_capacity *= 2;
              changed_tasks = xbt_realloc(changed_tasks, sizeof(SD_task_t) * changed_task_capacity);
            }
+           */
            changed_tasks[changed_task_number] = NULL;
          }
        }
@@ -208,13 +268,18 @@ SD_task_t* SD_simulate(double how_long)
       if (!task->state_changed) {
        task->state_changed = 1;
        changed_tasks[changed_task_number++] = task;
+       /*
        if (changed_task_number == changed_task_capacity) {
          changed_task_capacity *= 2;
          changed_tasks = xbt_realloc(changed_tasks, sizeof(SD_task_t) * changed_task_capacity);
        }
+       */
        changed_tasks[changed_task_number] = NULL;
       }
     }
+
+    while (surf_timer_resource->extension_public->get(&fun,(void*)&arg)) {
+    }
   }
 
   /* we must reset every task->state_changed */
@@ -282,7 +347,7 @@ void SD_exit(void) {
     surf_exit();
   }
   else {
-    fprintf(stderr, "Warning: SD_exit() called while SimDag was not running\n");
+    WARN0("SD_exit() called, but SimDag is not running");
     /* we cannot use exceptions here because xbt is not running! */
   }
 }