Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[MSG] add MSG_task_get_remaining_work_ratio + test
authorMERCIER Michael <michael.mercier@inria.fr>
Thu, 9 Nov 2017 15:26:41 +0000 (16:26 +0100)
committerMERCIER Michael <michael.mercier@inria.fr>
Thu, 9 Nov 2017 15:48:51 +0000 (16:48 +0100)
Make MSG_task_get_flops_amount returning anly the actual flops amount

Create an other function tu return the remaining amount of work.
F
or more details:
https://github.com/simgrid/simgrid/issues/223

examples/msg/cloud-capping/cloud-capping.c
examples/msg/cloud-two-tasks/cloud-two-tasks.c
include/simgrid/msg.h
src/msg/msg_task.cpp
teshsuite/msg/CMakeLists.txt
teshsuite/msg/task_progress/task_progress.cpp [new file with mode: 0644]
teshsuite/msg/task_progress/task_progress.tesh [new file with mode: 0644]

index 73b3eda..e84ac2c 100644 (file)
@@ -76,8 +76,8 @@ static void test_dynamic_change(void)
   MSG_process_create("worker0", worker_busy_loop_main, &task0, (msg_host_t)vm0);
   MSG_process_create("worker1", worker_busy_loop_main, &task1, (msg_host_t)vm1);
 
   MSG_process_create("worker0", worker_busy_loop_main, &task0, (msg_host_t)vm0);
   MSG_process_create("worker1", worker_busy_loop_main, &task1, (msg_host_t)vm1);
 
-  double task0_remain_prev = MSG_task_get_flops_amount(task0);
-  double task1_remain_prev = MSG_task_get_flops_amount(task1);
+  double task0_remain_prev = MSG_task_get_remaining_work_ratio(task0);
+  double task1_remain_prev = MSG_task_get_remaining_work_ratio(task1);
 
   const double cpu_speed = MSG_host_get_speed(pm0);
   for (int i = 0; i < 10; i++) {
 
   const double cpu_speed = MSG_host_get_speed(pm0);
   for (int i = 0; i < 10; i++) {
@@ -86,8 +86,8 @@ static void test_dynamic_change(void)
     MSG_vm_set_bound(vm1, new_bound);
     MSG_process_sleep(100);
 
     MSG_vm_set_bound(vm1, new_bound);
     MSG_process_sleep(100);
 
-    double task0_remain_now = MSG_task_get_flops_amount(task0);
-    double task1_remain_now = MSG_task_get_flops_amount(task1);
+    double task0_remain_now = MSG_task_get_remaining_work_ratio(task0);
+    double task1_remain_now = MSG_task_get_remaining_work_ratio(task1);
 
     double task0_flops_per_sec = task0_remain_prev - task0_remain_now;
     double task1_flops_per_sec = task1_remain_prev - task1_remain_now;
 
     double task0_flops_per_sec = task0_remain_prev - task0_remain_now;
     double task1_flops_per_sec = task1_remain_prev - task1_remain_now;
index e8b2d0b..1b0f499 100644 (file)
@@ -63,7 +63,7 @@ static int master_main(int argc, char *argv[])
 
   while(MSG_get_clock()<100) {
     if (atask != NULL)
 
   while(MSG_get_clock()<100) {
     if (atask != NULL)
-      XBT_INFO("aTask remaining duration: %g", MSG_task_get_flops_amount(atask));
+      XBT_INFO("aTask remaining duration: %g", MSG_task_get_remaining_work_ratio(atask));
     MSG_process_sleep(1);
   }
 
     MSG_process_sleep(1);
   }
 
index 7aaf109..ce49c90 100644 (file)
@@ -380,8 +380,10 @@ XBT_PUBLIC(msg_error_t) MSG_process_sleep(double nb_sec);
 
 XBT_PUBLIC(void) MSG_task_set_flops_amount(msg_task_t task, double flops_amount);
 XBT_PUBLIC(double) MSG_task_get_flops_amount(msg_task_t task);
 
 XBT_PUBLIC(void) MSG_task_set_flops_amount(msg_task_t task, double flops_amount);
 XBT_PUBLIC(double) MSG_task_get_flops_amount(msg_task_t task);
+XBT_PUBLIC(double) MSG_task_get_remaining_work_ratio(msg_task_t task);
 XBT_PUBLIC(void) MSG_task_set_bytes_amount(msg_task_t task, double bytes_amount);
 
 XBT_PUBLIC(void) MSG_task_set_bytes_amount(msg_task_t task, double bytes_amount);
 
+
 XBT_PUBLIC(double) MSG_task_get_remaining_communication(msg_task_t task);
 XBT_PUBLIC(int) MSG_task_is_latency_bounded(msg_task_t task);
 XBT_PUBLIC(double) MSG_task_get_bytes_amount(msg_task_t task);
 XBT_PUBLIC(double) MSG_task_get_remaining_communication(msg_task_t task);
 XBT_PUBLIC(int) MSG_task_is_latency_bounded(msg_task_t task);
 XBT_PUBLIC(double) MSG_task_get_bytes_amount(msg_task_t task);
index 0ad5499..e5f3641 100644 (file)
@@ -228,19 +228,39 @@ msg_error_t MSG_task_cancel(msg_task_t task)
 }
 
 /** \ingroup m_task_management
 }
 
 /** \ingroup m_task_management
- * \brief Returns the remaining amount of flops needed to execute a task #msg_task_t.
+ * \brief Returns a value in ]0,1[ that represent the task remaining work
+ *    to do: starts at 1 and goes to 0. Returns 0 if not started or finished.
  *
  *
- * Once a task has been processed, this amount is set to 0. If you want, you can reset this value with
- * #MSG_task_set_flops_amount before restarting the task.
+ * 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_flops_amount(msg_task_t task) {
+double MSG_task_get_remaining_work_ratio(msg_task_t task) {
+
+  xbt_assert((task != nullptr), "Cannot get information from a nullptr task");
   if (task->simdata->compute) {
   if (task->simdata->compute) {
+    // Task in progress
     return task->simdata->compute->remains();
     return task->simdata->compute->remains();
+
+  //} else if ((MSG_task_get_flops_amount(task) == 0 and task->simdata->flops_parallel_amount == nullptr) //this is a sequential task
+  //    or (task->simdata->flops_parallel_amount != nullptr and task->simdata->flops_parallel_amount == 0)) {
+  //  // Task finished
+  //  return 1;
   } else {
   } else {
-    return task->simdata->flops_amount;
+    // Task not started or finished
+    return 0;
   }
 }
 
   }
 }
 
+/** \ingroup m_task_management
+ * \brief Returns the initial amount of flops needed to execute a task #msg_task_t.
+ *
+ * Once a task has been processed, this amount is set to 0. If you want, you can reset this value with
+ * #MSG_task_set_flops_amount before restarting the task.
+ */
+double MSG_task_get_flops_amount(msg_task_t task) {
+  return task->simdata->flops_amount;
+}
+
 /** \ingroup m_task_management
  * \brief set the computation amount needed to process a task #msg_task_t.
  *
 /** \ingroup m_task_management
  * \brief set the computation amount needed to process a task #msg_task_t.
  *
index 39b4e94..0556ec3 100644 (file)
@@ -10,7 +10,7 @@ foreach(x actions-comm actions-storage cloud-sharing get_sender host_on_off host
 endforeach()
 
 # CPP examples
 endforeach()
 
 # CPP examples
-foreach(x task_destroy_cancel task_listen_from)
+foreach(x task_destroy_cancel task_listen_from task_progress)
   add_executable       (${x}  ${x}/${x}.cpp)
   target_link_libraries(${x}  simgrid)
   set_target_properties(${x}  PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x})
   add_executable       (${x}  ${x}/${x}.cpp)
   target_link_libraries(${x}  simgrid)
   set_target_properties(${x}  PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x})
@@ -51,7 +51,8 @@ set(xml_files     ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/acti
                                    ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp1-c1s1-c3s2.xml
                                    ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp2.5-hbp1.5.xml    PARENT_SCOPE)
 
                                    ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp1-c1s1-c3s2.xml
                                    ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp2.5-hbp1.5.xml    PARENT_SCOPE)
 
-foreach(x get_sender host_on_off host_on_off_processes host_on_off_recv task_destroy_cancel task_listen_from trace_integration)
+foreach(x get_sender host_on_off host_on_off_processes host_on_off_recv
+    task_destroy_cancel task_listen_from task_progress trace_integration)
   ADD_TESH_FACTORIES(tesh-msg-${x} "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh)
 endforeach()
 
   ADD_TESH_FACTORIES(tesh-msg-${x} "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh)
 endforeach()
 
diff --git a/teshsuite/msg/task_progress/task_progress.cpp b/teshsuite/msg/task_progress/task_progress.cpp
new file mode 100644 (file)
index 0000000..feefbfc
--- /dev/null
@@ -0,0 +1,108 @@
+/* Copyright (c) 2010-2017. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* 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 <xbt/ex.hpp>
+#include "simgrid/msg.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
+
+static std::vector<msg_task_t> tasks = std::vector<msg_task_t>();
+
+static int seq_task(int /*argc*/, char* /*argv*/ [])
+{
+  double task_comp_size = 5E7;
+  double task_comm_size = 1E6;
+  double progress = 0;
+
+  msg_task_t task = MSG_task_create("simple", task_comp_size, task_comm_size, NULL);
+  tasks.push_back(task);
+
+  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_INFO("Executing task: \"%s\"", task->name);
+  MSG_task_execute(task);
+
+  XBT_INFO("get the progress of %s after the task finishes", task->name);
+  progress = MSG_task_get_remaining_work_ratio(task);
+  xbt_assert(progress == 0, "Progress should be equal to 1 not %f", progress);
+
+  XBT_INFO("Goodbye now!");
+  return 0;
+}
+
+static int par_task(int /*argc*/, char* /*argv*/ [])
+{
+  int nb_res = 2;
+  //double * computation_amount = xbt_new(double, nb_res);
+  double * computation_amount = new double[2] {10E7, 10E7};
+  //double * communication_amount = xbt_new(double, nb_res);
+  double * communication_amount = new double[4] {1E6, 1E6, 1E6, 1E6};
+  double progress = 0;
+
+  std::vector<msg_host_t> hosts_to_use = std::vector<msg_host_t>();
+  hosts_to_use.push_back(MSG_get_host_by_name("Tremblay"));
+  hosts_to_use.push_back(MSG_get_host_by_name("Jupiter"));
+
+  msg_task_t task = MSG_parallel_task_create("ptask", 2, hosts_to_use.data(), computation_amount, communication_amount, NULL);
+  tasks.push_back(task);
+
+  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_INFO("Executing task: \"%s\"", task->name);
+  MSG_parallel_task_execute(task);
+
+  XBT_INFO("get the progress of %s after the task finishes", task->name);
+  progress = MSG_task_get_remaining_work_ratio(task);
+  xbt_assert(progress == 0, "Progress should be equal to 1 not %f", progress);
+
+  XBT_INFO("Goodbye now!");
+  return 0;
+}
+
+static int get_progress(int /*argc*/, char* /*argv*/ [])
+{
+  while (tasks.empty()) {
+    MSG_process_sleep(0.5);
+  }
+  for(auto const& task: tasks) {
+    double progress;
+    double progress_prev = 1;
+    for (int i = 0; i < 3; i++) {
+      MSG_process_sleep(0.2);
+      progress = MSG_task_get_remaining_work_ratio(task);
+      xbt_assert(progress >= 0 and progress < 1, "Progress should be in [0, 1[, and not %f", progress);
+      xbt_assert(progress < progress_prev, "Progress should decrease, not increase");
+      XBT_INFO("Progress of \"%s\": %f", task->name, progress);
+      progress_prev = progress;
+    }
+  }
+}
+
+int main(int argc, char *argv[])
+{
+  MSG_init(&argc, argv);
+  MSG_config("host/model", "ptask_L07");
+  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../examples/platforms/two_hosts.xml\n", argv[0], argv[0]);
+
+  MSG_create_environment(argv[1]);
+
+  MSG_process_create("sequential", seq_task, NULL, MSG_get_host_by_name("Tremblay"));
+
+  MSG_process_create("parallel", par_task, NULL, MSG_get_host_by_name("Tremblay"));
+
+  // Create a process to test in progress task
+  MSG_process_create("get_progress", get_progress, NULL, MSG_get_host_by_name("Tremblay"));
+
+  msg_error_t res = MSG_main();
+
+  XBT_INFO("Simulation time %g", MSG_get_clock());
+
+  return res != MSG_OK;
+}
diff --git a/teshsuite/msg/task_progress/task_progress.tesh b/teshsuite/msg/task_progress/task_progress.tesh
new file mode 100644 (file)
index 0000000..679e181
--- /dev/null
@@ -0,0 +1,18 @@
+$ ./task_progress ${srcdir:=.}/../../../examples/platforms/small_platform.xml
+> [0.000000] [xbt_cfg/INFO] Switching to the L07 model to handle parallel tasks.
+> [Tremblay:sequential:(1) 0.000000] [msg_test/INFO] get the progress of simple before the task starts
+> [Tremblay:sequential:(1) 0.000000] [msg_test/INFO] Executing task: "simple"
+> [Tremblay:parallel:(2) 0.000000] [msg_test/INFO] get the progress of ptask before the task starts
+> [Tremblay:parallel:(2) 0.000000] [msg_test/INFO] Executing task: "ptask"
+> [Tremblay:get_progress:(3) 0.200000] [msg_test/INFO] Progress of "simple": 0.802376
+> [Tremblay:get_progress:(3) 0.400000] [msg_test/INFO] Progress of "simple": 0.606186
+> [Tremblay:get_progress:(3) 0.600000] [msg_test/INFO] Progress of "simple": 0.409996
+> [Tremblay:get_progress:(3) 0.800000] [msg_test/INFO] Progress of "ptask": 0.608337
+> [Tremblay:get_progress:(3) 1.000000] [msg_test/INFO] Progress of "ptask": 0.510242
+> [Tremblay:sequential:(1) 1.017958] [msg_test/INFO] get the progress of simple after the task finishes
+> [Tremblay:sequential:(1) 1.017958] [msg_test/INFO] Goodbye now!
+> [Tremblay:get_progress:(3) 1.200000] [msg_test/INFO] Progress of "ptask": 0.362543
+> [Tremblay:parallel:(2) 1.675180] [msg_test/INFO] get the progress of ptask after the task finishes
+> [Tremblay:parallel:(2) 1.675180] [msg_test/INFO] Goodbye now!
+> [1.675180] [msg_test/INFO] Simulation time 1.67518
+