Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
uniformization of the conversion of task state to string
[simgrid.git] / src / simdag / sd_global.cpp
index 66f3c61..01ce557 100644 (file)
@@ -4,22 +4,27 @@
 /* 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. */
 
-#include "instr/instr_interface.h"
 #include "simgrid/sg_config.h"
 #include "simgrid/host.h"
 #include "src/simdag/simdag_private.h"
 #include "src/surf/surf_interface.hpp"
 #include "simgrid/s4u/engine.hpp"
 
-#if HAVE_JEDULE
-#include "simgrid/jedule/jedule_sd_binding.h"
-#endif
-
 XBT_LOG_NEW_CATEGORY(sd, "Logging specific to SimDag");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_kernel, sd, "Logging specific to SimDag (kernel)");
 
 SD_global_t sd_global = nullptr;
 
+/**
+ * \brief helper for pretty printing of task state
+ * \param state the state of a task
+ * \return the equivalent as a readable string
+ */
+const char *__get_state_name(e_SD_task_state_t state){
+  std::string state_names[7] = { "not scheduled", "schedulable", "scheduled", "runnable","running", "done", "failed" };
+  return state_names[(int)log2(state)].data();
+}
+
 /**
  * \brief Initializes SD internal data
  *
@@ -35,9 +40,6 @@ void SD_init(int *argc, char **argv)
 
   sd_global = xbt_new(s_SD_global_t, 1);
   sd_global->watch_point_reached = false;
-
-  sd_global->task_mallocator=xbt_mallocator_new(65536, SD_task_new_f, SD_task_free_f, SD_task_recycle_f);
-
   sd_global->initial_tasks = new std::set<SD_task_t>();
   sd_global->runnable_tasks = new std::set<SD_task_t>();
   sd_global->completed_tasks = new std::set<SD_task_t>();
@@ -139,8 +141,8 @@ xbt_dynar_t SD_simulate(double how_long) {
     /* let's see which tasks are done */
     unsigned int iter;
     xbt_dynar_foreach(all_existing_models, iter, model) {
-      surf_action_t action;
-      while ((action = surf_model_extract_done_action_set(model))) {
+      surf_action_t action = surf_model_extract_done_action_set(model);
+      while (action != nullptr) {
         SD_task_t task = static_cast<SD_task_t>(action->getData());
         XBT_VERB("Task '%s' done", SD_task_get_name(task));
         SD_task_set_state(task, SD_DONE);
@@ -185,24 +187,25 @@ xbt_dynar_t SD_simulate(double how_long) {
             SD_task_run(output);
         }
         task->outputs->clear();
+        action = surf_model_extract_done_action_set(model);
       }
 
       /* let's see which tasks have just failed */
-      while ((action = surf_model_extract_failed_action_set(model))) {
+      action = surf_model_extract_failed_action_set(model);
+      while (action != nullptr) {
         SD_task_t task = static_cast<SD_task_t>(action->getData());
         XBT_VERB("Task '%s' failed", SD_task_get_name(task));
         SD_task_set_state(task, SD_FAILED);
         xbt_dynar_push(sd_global->return_set, &task);
+        action = surf_model_extract_failed_action_set(model);
       }
     }
   }
 
   if (!sd_global->watch_point_reached && how_long < 0 && !sd_global->initial_tasks->empty()) {
     XBT_WARN("Simulation is finished but %zu tasks are still not done", sd_global->initial_tasks->size());
-    static const char* state_names[] =
-      { "SD_NOT_SCHEDULED", "SD_SCHEDULABLE", "SD_SCHEDULED", "SD_RUNNABLE", "SD_RUNNING", "SD_DONE","SD_FAILED" };
     for (auto t : *sd_global->initial_tasks)
-      XBT_WARN("%s is in %s state", SD_task_get_name(t), state_names[SD_task_get_state(t)]);
+      XBT_WARN("%s is in %s state", SD_task_get_name(t), __get_state_name(SD_task_get_state(t)));
   }
 
   XBT_DEBUG("elapsed_time = %f, total_time = %f, watch_point_reached = %d",
@@ -224,14 +227,10 @@ double SD_get_clock() {
  */
 void SD_exit()
 {
-  TRACE_surf_resource_utilization_release();
-
 #if HAVE_JEDULE
   jedule_sd_cleanup();
   jedule_sd_exit();
 #endif
-
-  xbt_mallocator_free(sd_global->task_mallocator);
   delete sd_global->initial_tasks;
   delete sd_global->runnable_tasks;
   delete sd_global->completed_tasks;