From c6e38be67a91e39324842cbf3988edd6133b8e73 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 9 Aug 2016 09:46:48 +0200 Subject: [PATCH 1/1] uniformization of the conversion of task state to string --- include/simgrid/simdag.h | 16 ++++++++-------- src/simdag/sd_global.cpp | 16 +++++++++++----- src/simdag/sd_task.cpp | 16 ++++++---------- src/simdag/simdag_private.h | 3 ++- teshsuite/simdag/incomplete/incomplete.tesh | 6 +++--- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/include/simgrid/simdag.h b/include/simgrid/simdag.h index d74286a6c8..cdebdc678f 100644 --- a/include/simgrid/simdag.h +++ b/include/simgrid/simdag.h @@ -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 * diff --git a/src/simdag/sd_global.cpp b/src/simdag/sd_global.cpp index 8aeb02a1af..01ce55778d 100644 --- a/src/simdag/sd_global.cpp +++ b/src/simdag/sd_global.cpp @@ -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_global->runnable_tasks = new std::set(); sd_global->completed_tasks = new std::set(); @@ -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; diff --git a/src/simdag/sd_task.cpp b/src/simdag/sd_task.cpp index 332b4dcf94..e1fcd2934b 100644 --- a/src/simdag/sd_task.cpp +++ b/src/simdag/sd_task.cpp @@ -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) { diff --git a/src/simdag/simdag_private.h b/src/simdag/simdag_private.h index 3cc57b70ca..380ca67d9b 100644 --- a/src/simdag/simdag_private.h +++ b/src/simdag/simdag_private.h @@ -7,6 +7,7 @@ #ifndef SIMDAG_PRIVATE_H #define SIMDAG_PRIVATE_H #include +#include #include #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 *initial_tasks; std::set *runnable_tasks; std::set *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 diff --git a/teshsuite/simdag/incomplete/incomplete.tesh b/teshsuite/simdag/incomplete/incomplete.tesh index 933bdb4af2..a5a7b8b843 100644 --- a/teshsuite/simdag/incomplete/incomplete.tesh +++ b/teshsuite/simdag/incomplete/incomplete.tesh @@ -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 -- 2.20.1