Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplifications in MSG task execution
[simgrid.git] / src / msg / msg_task.cpp
index ff50989..49a1b17 100644 (file)
@@ -67,17 +67,22 @@ msg_error_t Task::execute()
   xbt_assert(std::isfinite(flops_amount), "flops_amount is not finite!");
 
   msg_error_t status = MSG_OK;
   xbt_assert(std::isfinite(flops_amount), "flops_amount is not finite!");
 
   msg_error_t status = MSG_OK;
+  if (flops_amount <= 0.0)
+    return MSG_OK;
 
 
-  set_used();
   try {
   try {
-    s4u::ExecPtr e = s4u::this_actor::exec_init(flops_amount)
-                         ->set_priority(1 / priority_)
-                         ->set_bound(bound_)
-                         ->set_tracing_category(tracing_category_)
-                         ->start();
-    compute = boost::static_pointer_cast<kernel::activity::ExecImpl>(e->get_impl());
-
-    e->wait();
+    set_used();
+    if (parallel_)
+      compute = s4u::this_actor::exec_init(hosts_, flops_parallel_amount, bytes_parallel_amount);
+    else
+      compute = s4u::this_actor::exec_init(flops_amount);
+
+    compute->set_name(name_)
+        ->set_tracing_category(tracing_category_)
+        ->set_timeout(timeout_)
+        ->set_priority(1 / priority_)
+        ->set_bound(bound_)
+        ->wait();
 
     set_not_used();
     XBT_DEBUG("Execution task '%s' finished", get_cname());
 
     set_not_used();
     XBT_DEBUG("Execution task '%s' finished", get_cname());
@@ -97,9 +102,13 @@ msg_error_t Task::execute()
   return status;
 }
 
   return status;
 }
 
-Comm* Task::send_async(std::string alias, void_f_pvoid_t cleanup, bool detached)
+s4u::CommPtr Task::send_async(std::string alias, void_f_pvoid_t cleanup, bool detached)
 {
 {
-  TRACE_msg_task_put_start(this);
+  if (TRACE_actor_is_enabled()) {
+    container_t process_container = simgrid::instr::Container::by_name(instr_pid(MSG_process_self()));
+    std::string key               = std::string("p") + std::to_string(get_id());
+    simgrid::instr::Container::get_root()->get_link("ACTOR_TASK_LINK")->start_event(process_container, "SR", key);
+  }
 
   /* Prepare the task to send */
   set_used();
 
   /* Prepare the task to send */
   set_used();
@@ -117,10 +126,7 @@ Comm* Task::send_async(std::string alias, void_f_pvoid_t cleanup, bool detached)
   if (TRACE_is_enabled() && has_tracing_category())
     simgrid::simix::simcall([comm, this] { comm->get_impl()->set_category(std::move(tracing_category_)); });
 
   if (TRACE_is_enabled() && has_tracing_category())
     simgrid::simix::simcall([comm, this] { comm->get_impl()->set_category(std::move(tracing_category_)); });
 
-  if (not detached)
-    return new Comm(this, nullptr, comm);
-  else
-    return nullptr;
+  return comm;
 }
 
 void Task::cancel()
 }
 
 void Task::cancel()
@@ -279,6 +285,25 @@ msg_error_t MSG_task_execute(msg_task_t task)
 {
   return task->execute();
 }
 {
   return task->execute();
 }
+
+/**
+ * @brief Executes a parallel task and waits for its termination.
+ *
+ * @param task a #msg_task_t to execute on the location on which the process is running.
+ *
+ * @return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED or #MSG_HOST_FAILURE otherwise
+ */
+msg_error_t MSG_parallel_task_execute(msg_task_t task)
+{
+  return task->execute();
+}
+
+msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeout)
+{
+  task->set_timeout(timeout);
+  return task->execute();
+}
+
 /**
  * @brief Sends a task on a mailbox.
  *
 /**
  * @brief Sends a task on a mailbox.
  *
@@ -290,7 +315,7 @@ msg_error_t MSG_task_execute(msg_task_t task)
  */
 msg_comm_t MSG_task_isend(msg_task_t task, const char* alias)
 {
  */
 msg_comm_t MSG_task_isend(msg_task_t task, const char* alias)
 {
-  return task->send_async(alias, nullptr, false);
+  return new simgrid::msg::Comm(task, nullptr, task->send_async(alias, nullptr, false));
 }
 
 /**
 }
 
 /**
@@ -307,7 +332,7 @@ msg_comm_t MSG_task_isend(msg_task_t task, const char* alias)
 msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char* alias, double maxrate)
 {
   task->set_rate(maxrate);
 msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char* alias, double maxrate)
 {
   task->set_rate(maxrate);
-  return task->send_async(alias, nullptr, false);
+  return new simgrid::msg::Comm(task, nullptr, task->send_async(alias, nullptr, false));
 }
 
 /**
 }
 
 /**
@@ -327,8 +352,7 @@ msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char* alias, double max
  */
 void MSG_task_dsend(msg_task_t task, const char* alias, void_f_pvoid_t cleanup)
 {
  */
 void MSG_task_dsend(msg_task_t task, const char* alias, void_f_pvoid_t cleanup)
 {
-  msg_comm_t XBT_ATTRIB_UNUSED comm = task->send_async(alias, cleanup, true);
-  xbt_assert(comm == nullptr);
+  task->send_async(alias, cleanup, true);
 }
 
 /**
 }
 
 /**
@@ -354,7 +378,7 @@ void MSG_task_dsend(msg_task_t task, const char* alias, void_f_pvoid_t cleanup)
 void MSG_task_dsend_bounded(msg_task_t task, const char* alias, void_f_pvoid_t cleanup, double maxrate)
 {
   task->set_rate(maxrate);
 void MSG_task_dsend_bounded(msg_task_t task, const char* alias, void_f_pvoid_t cleanup, double maxrate)
 {
   task->set_rate(maxrate);
-  MSG_task_dsend(task, alias, cleanup);
+  task->send_async(alias, cleanup, true);
 }
 
 /** @brief Destroys the given task.
 }
 
 /** @brief Destroys the given task.