Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Return 1.0 if the task has not started.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 26 Dec 2017 20:59:37 +0000 (21:59 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 27 Dec 2017 17:08:38 +0000 (18:08 +0100)
ChangeLog
src/msg/msg_task.cpp
teshsuite/msg/task_progress/task_progress.cpp

index 17d53f5..479c24b 100644 (file)
--- 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.
index ae1f59c..3e1d68b 100644 (file)
@@ -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;
   }
 }
 
index d128dce..adf5200 100644 (file)
@@ -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);