Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #237 from oar-team/upstream
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 21 Nov 2017 23:46:58 +0000 (00:46 +0100)
committerGitHub <noreply@github.com>
Tue, 21 Nov 2017 23:46:58 +0000 (00:46 +0100)
 [MSG] add MSG_task_get_remaining_work_ratio + test

examples/msg/cloud-capping/cloud-capping.c
examples/msg/cloud-two-tasks/cloud-two-tasks.c
examples/msg/plugin-hostload/plugin-hostload.c
include/simgrid/msg.h
src/msg/msg_task.cpp
src/msg/msg_vm.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);
 
-  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++) {
@@ -86,8 +86,8 @@ static void test_dynamic_change(void)
     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;
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)
-      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);
   }
 
index 717c54b..e458d27 100644 (file)
@@ -27,7 +27,7 @@ static int execute_load_test(int argc, char* argv[])
   // Run a task
   start            = MSG_get_clock();
   msg_task_t task1 = MSG_task_create("t1", 100E6, 0, NULL);
-  XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1));
+  XBT_INFO("Run a task of %.0E flops", MSG_task_get_initial_flops_amount(task1));
   MSG_task_execute(task1);
   MSG_task_destroy(task1);
 
@@ -44,7 +44,7 @@ static int execute_load_test(int argc, char* argv[])
   // Run a second task
   start = MSG_get_clock();
   task1 = MSG_task_create("t2", 100E6, 0, NULL);
-  XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1));
+  XBT_INFO("Run a task of %.0E flops", MSG_task_get_initial_flops_amount(task1));
   MSG_task_execute(task1);
   MSG_task_destroy(task1);
   XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
index 7aaf109..9fd43cb 100644 (file)
@@ -379,9 +379,21 @@ XBT_PUBLIC(msg_error_t) MSG_process_join(msg_process_t process, double timeout);
 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);
+/* Unable to compile that without -Werror=deprecated-declarations
+XBT_ATTRIB_DEPRECATED_v321( "Use MSG_task_get_initial_flops_amount if you want to get initial amounts of flops, or "
+                            "Use MSG_task_get_remaining_work_ratio to get task progress (in order "
+                            "to compute progress in flops)") static inline double MSG_task_get_flops_amount(msg_task_t task)
+{
+  return MSG_task_get_flops_amount(task);
+}
+*/
+
 XBT_PUBLIC(double) MSG_task_get_flops_amount(msg_task_t task);
+XBT_PUBLIC(double) MSG_task_get_initial_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(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..86ece99 100644 (file)
@@ -228,11 +228,29 @@ msg_error_t MSG_task_cancel(msg_task_t task)
 }
 
 /** \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_remaining_work_ratio(msg_task_t task) {
+
+  xbt_assert((task != nullptr), "Cannot get information from a nullptr task");
+  if (task->simdata->compute) {
+    // Task in progress
+    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 {
+    // Task not started or finished
+    return 0;
+  }
+}
+
 double MSG_task_get_flops_amount(msg_task_t task) {
   if (task->simdata->compute) {
     return task->simdata->compute->remains();
@@ -241,6 +259,18 @@ double MSG_task_get_flops_amount(msg_task_t task) {
   }
 }
 
+/** \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.
+ *
+ * Warning: Only work for simple task, not parallel task.
+ */
+double MSG_task_get_initial_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.
  *
index 4938bfc..4e485ba 100644 (file)
@@ -337,7 +337,7 @@ static void start_dirty_page_tracking(msg_vm_t vm)
 
   for (auto const& elm : vm->pimpl_vm_->dp_objs) {
     dirty_page_t dp    = elm.second;
-    double remaining = MSG_task_get_flops_amount(dp->task);
+    double remaining = MSG_task_get_remaining_work_ratio(dp->task);
     dp->prev_clock = MSG_get_clock();
     dp->prev_remaining = remaining;
     XBT_DEBUG("%s@%s remaining %f", elm.first.c_str(), vm->getCname(), remaining);
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
-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})
@@ -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)
 
-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()
 
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..7c3ad78
--- /dev/null
@@ -0,0 +1,106 @@
+/* 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*/ [])
+{
+  double * computation_amount = new double[2] {10E7, 10E7};
+  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);
+  }
+  double progress;
+  for(auto const& task: tasks) {
+    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;
+    }
+  }
+  return 0;
+}
+
+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
+