Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
uniformization of the conversion of task state to string
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 9 Aug 2016 07:46:48 +0000 (09:46 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 9 Aug 2016 07:46:48 +0000 (09:46 +0200)
include/simgrid/simdag.h
src/simdag/sd_global.cpp
src/simdag/sd_task.cpp
src/simdag/simdag_private.h
teshsuite/simdag/incomplete/incomplete.tesh

index d74286a..cdebdc6 100644 (file)
@@ -14,7 +14,6 @@
 #include "xbt/log.h"
 #include "simgrid/link.h"
 #include "simgrid/host.h"
-
 SG_BEGIN_DECL()
 
 /** @brief Link opaque datatype
@@ -38,14 +37,14 @@ typedef struct SD_task *SD_task_t;
 /** @brief Task states
     @ingroup SD_task_api */
 typedef enum {
-  SD_NOT_SCHEDULED = 0,      /**< @brief Initial state (not valid for SD_watch and SD_unwatch). */
-  SD_SCHEDULABLE = 0x0001,   /**< @brief A task becomes SD_SCHEDULABLE as soon as its dependencies are satisfied */
-  SD_SCHEDULED = 0x0002,     /**< @brief A task becomes SD_SCHEDULED when you call function
+  SD_NOT_SCHEDULED = 0x0001,      /**< @brief Initial state (not valid for SD_watch and SD_unwatch). */
+  SD_SCHEDULABLE = 0x0002,   /**< @brief A task becomes SD_SCHEDULABLE as soon as its dependencies are satisfied */
+  SD_SCHEDULED = 0x0004,     /**< @brief A task becomes SD_SCHEDULED when you call function
                                   SD_task_schedule. SD_simulate will execute it when it becomes SD_RUNNABLE. */
-  SD_RUNNABLE = 0x0004,      /**< @brief A scheduled task becomes runnable is SD_simulate as soon as its dependencies are satisfied. */
-  SD_RUNNING = 0x0008,       /**< @brief An SD_RUNNABLE task becomes SD_RUNNING when it is launched. */
-  SD_DONE = 0x0010,          /**< @brief The task is successfully finished. */
-  SD_FAILED = 0x0020         /**< @brief A problem occurred during the execution of the task. */
+  SD_RUNNABLE = 0x0008,      /**< @brief A scheduled task becomes runnable is SD_simulate as soon as its dependencies are satisfied. */
+  SD_RUNNING = 0x0010,       /**< @brief An SD_RUNNABLE task becomes SD_RUNNING when it is launched. */
+  SD_DONE = 0x0020,          /**< @brief The task is successfully finished. */
+  SD_FAILED = 0x0040         /**< @brief A problem occurred during the execution of the task. */
 } e_SD_task_state_t;
 
 /** @brief Task kinds
@@ -58,6 +57,7 @@ typedef enum {
   SD_TASK_COMM_PAR_MXN_1D_BLOCK = 4 /**< @brief MxN data redistribution (1D Block distribution) */
 } e_SD_task_kind_t;
 
+
 /************************** Workstation handling ****************************/
 /** @addtogroup SD_host_api
  *
index 8aeb02a..01ce557 100644 (file)
@@ -15,6 +15,16 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_kernel, sd, "Logging specific to SimDag (kern
 
 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
  *
@@ -30,7 +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->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>();
@@ -195,10 +204,8 @@ xbt_dynar_t SD_simulate(double how_long) {
 
   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,7 +231,6 @@ void SD_exit()
   jedule_sd_cleanup();
   jedule_sd_exit();
 #endif
-
   delete sd_global->initial_tasks;
   delete sd_global->runnable_tasks;
   delete sd_global->completed_tasks;
index 332b4dc..e1fcd29 100644 (file)
@@ -448,16 +448,12 @@ e_SD_task_kind_t SD_task_get_kind(SD_task_t task)
 void SD_task_dump(SD_task_t task)
 {
   XBT_INFO("Displaying task %s", SD_task_get_name(task));
-  char *statename = bprintf("%s%s%s%s%s%s%s",
-                      (task->state == SD_NOT_SCHEDULED ? " not scheduled" : ""),
-                      (task->state == SD_SCHEDULABLE ? " schedulable" : ""),
-                      (task->state == SD_SCHEDULED ? " scheduled" : ""),
-                      (task->state == SD_RUNNABLE ? " runnable" : " not runnable"),
-                      (task->state == SD_RUNNING ? " running" : ""),
-                      (task->state == SD_DONE ? " done" : ""),
-                      (task->state == SD_FAILED ? " failed" : ""));
-  XBT_INFO("  - state:%s", statename);
-  free(statename);
+  if (task->state == SD_RUNNABLE)
+    XBT_INFO("  - state: runnable");
+  else if (task->state < SD_RUNNABLE)
+    XBT_INFO("  - state: %s not runnable", __get_state_name(task->state));
+  else
+    XBT_INFO("  - state: not runnable %s", __get_state_name(task->state));
 
   if (task->kind != 0) {
     switch (task->kind) {
index 3cc57b7..380ca67 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef SIMDAG_PRIVATE_H
 #define SIMDAG_PRIVATE_H
 #include <set>
+#include <string>
 #include <vector>
 #include "xbt/dynar.h"
 #include "simgrid/simdag.h"
@@ -22,7 +23,6 @@ SG_BEGIN_DECL()
 
 typedef struct SD_global {
   bool watch_point_reached;      /* has a task just reached a watch point? */
-
   std::set<SD_task_t> *initial_tasks;
   std::set<SD_task_t> *runnable_tasks;
   std::set<SD_task_t> *completed_tasks;
@@ -66,6 +66,7 @@ XBT_PRIVATE void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
 XBT_PRIVATE void SD_task_run(SD_task_t task);
 XBT_PRIVATE bool acyclic_graph_detail(xbt_dynar_t dag);
 XBT_PRIVATE void uniq_transfer_task_name(SD_task_t task);
+XBT_PRIVATE const char *__get_state_name(e_SD_task_state_t state);
 
 SG_END_DECL()
 #endif
index 933bdb4..a5a7b8b 100644 (file)
@@ -2,7 +2,7 @@
 $ ${bindir:=.}/incomplete ../../../examples/platforms/two_hosts_platform_shared.xml "--log=root.fmt:[%10.6r]%e%m%n"
 > [  0.000000] Switching to the L07 model to handle parallel tasks.
 > [  8.000100] Simulation is finished but 3 tasks are still not done
-> [  8.000100] Task D is in SD_SCHEDULED state
-> [  8.000100] Task C is in SD_NOT_SCHEDULED state
-> [  8.000100] Task B is in SD_SCHEDULABLE state
+> [  8.000100] Task D is in scheduled state
+> [  8.000100] Task C is in not scheduled state
+> [  8.000100] Task B is in schedulable state
 > [  8.000100] Simulation time: 8.000100