From 684313ff27ab7b9a3205b2c0af38916e44ead89e Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 26 Dec 2017 21:59:37 +0100 Subject: [PATCH] Return 1.0 if the task has not started. --- ChangeLog | 4 ++++ src/msg/msg_task.cpp | 9 +++++---- teshsuite/msg/task_progress/task_progress.cpp | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17d53f5c28..479c24b486 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ SimGrid (3.19) NOT RELEASED YET (target: March 20 2018, 16:15:27 UTC) + MSG + - Fix MSG_task_get_remaining_work_ratio() to return 1.0 for tasks that have + not started. + S4U - Execution->setHost() can be called after start() to migrate it. - Comm::test_any() is now implemented. diff --git a/src/msg/msg_task.cpp b/src/msg/msg_task.cpp index ae1f59c4e0..3e1d68be7a 100644 --- a/src/msg/msg_task.cpp +++ b/src/msg/msg_task.cpp @@ -86,7 +86,9 @@ msg_task_t MSG_task_create(const char *name, double flop_amount, double message_ msg_task_t MSG_parallel_task_create(const char *name, int host_nb, const msg_host_t * host_list, double *flops_amount, double *bytes_amount, void *data) { - msg_task_t task = MSG_task_create(name, 0, 0, data); + // Task's flops amount is set to an arbitrary value > 0.0 to be able to distinguish, in + // MSG_task_get_remaining_work_ratio(), a finished task and a task that has not started yet. + msg_task_t task = MSG_task_create(name, 1.0, 0, data); simdata_task_t simdata = task->simdata; /* Simulator Data specific to parallel tasks */ @@ -231,7 +233,6 @@ msg_error_t MSG_task_cancel(msg_task_t task) * to do: starts at 1 and goes to 0. Returns 0 if not started or finished. * * It works for either parallel or sequential tasks. - * TODO: Improve this function by returning 1 if the task has not started */ double MSG_task_get_remaining_work_ratio(msg_task_t task) { @@ -240,8 +241,8 @@ double MSG_task_get_remaining_work_ratio(msg_task_t task) { // Task in progress return task->simdata->compute->remainingRatio(); } else { - // Task not started or finished - return 0; + // Task not started (flops_amount is > 0.0) or finished (flops_amount is set to 0.0) + return task->simdata->flops_amount > 0.0 ? 1.0 : 0.0; } } diff --git a/teshsuite/msg/task_progress/task_progress.cpp b/teshsuite/msg/task_progress/task_progress.cpp index d128dceb44..adf5200278 100644 --- a/teshsuite/msg/task_progress/task_progress.cpp +++ b/teshsuite/msg/task_progress/task_progress.cpp @@ -22,7 +22,7 @@ static int seq_task(int /*argc*/, char* /*argv*/ []) XBT_INFO("get the progress of %s before the task starts", task->name); progress = MSG_task_get_remaining_work_ratio(task); - xbt_assert(progress == 0, "Progress should be 0 not %f", progress); + xbt_assert(progress == 1.0, "Progress should be 1.0 not %f", progress); XBT_INFO("Executing task: \"%s\"", task->name); MSG_task_execute(task); @@ -51,7 +51,7 @@ static int par_task(int /*argc*/, char* /*argv*/ []) XBT_INFO("get the progress of %s before the task starts", task->name); progress = MSG_task_get_remaining_work_ratio(task); - xbt_assert(progress == 0, "Progress should be 0 not %f", progress); + xbt_assert(progress == 1.0, "Progress should be 1.0 not %f", progress); XBT_INFO("Executing task: \"%s\"", task->name); MSG_parallel_task_execute(task); -- 2.20.1