-/**
- * @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 MSG_parallel_task_execute_with_timeout(task, -1);
-}
-
-msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeout)
-{
- e_smx_state_t comp_state;
- msg_error_t status = MSG_OK;
-
- xbt_assert((not task->compute) && not task->is_used(), "This task is executed somewhere else. Go fix your code!");
-
- XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
-
- if (task->flops_amount <= 0.0 && not task->hosts_.empty()) {
- return MSG_OK;
- }
-
- if (TRACE_actor_is_enabled())
- simgrid::instr::Container::by_name(instr_pid(MSG_process_self()))->get_state("ACTOR_STATE")->push_event("execute");
-
- try {
- task->set_used();
-
- task->compute = boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(simcall_execution_parallel_start(
- std::move(task->get_name()), task->hosts_.size(), task->hosts_.data(),
- (task->flops_parallel_amount.empty() ? nullptr : task->flops_parallel_amount.data()),
- (task->bytes_parallel_amount.empty() ? nullptr : task->bytes_parallel_amount.data()), -1.0, timeout));
- XBT_DEBUG("Parallel execution action created: %p", task->compute.get());
- if (task->has_tracing_category())
- simgrid::simix::simcall([task] { task->compute->set_category(std::move(task->get_tracing_category())); });
-
- comp_state = simcall_execution_wait(task->compute);
-
- task->set_not_used();
-
- XBT_DEBUG("Execution task '%s' finished in state %d", task->get_cname(), (int)comp_state);
- } catch (simgrid::HostFailureException& e) {
- status = MSG_HOST_FAILURE;
- } catch (simgrid::TimeoutError& e) {
- status = MSG_TIMEOUT;
- } catch (simgrid::CancelException& e) {
- status = MSG_TASK_CANCELED;
- }
-
- /* action ended, set comm and compute = nullptr, the actions is already destroyed in the main function */
- task->flops_amount = 0.0;
- task->comm = nullptr;
- task->compute = nullptr;
-
- if (TRACE_actor_is_enabled())
- simgrid::instr::Container::by_name(instr_pid(MSG_process_self()))->get_state("ACTOR_STATE")->pop_event();
-
- return status;
-}
-