-/**
- * @brief Executes a task and waits for its termination.
- *
- * This function is used for describing the behavior of a process. It takes only one parameter.
- * @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_task_execute(msg_task_t task)
-{
- return MSG_parallel_task_execute(task);
-}
-
-/**
- * @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)
-{
- simdata_task_t simdata = task->simdata;
- e_smx_state_t comp_state;
- msg_error_t status = MSG_OK;
-
-
- xbt_assert((not simdata->compute) && not task->simdata->isused,
- "This task is executed somewhere else. Go fix your code!");
-
- XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
-
- if (simdata->flops_amount <= 0.0 && not simdata->host_nb) {
- 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 {
- simdata->setUsed();
-
- if (simdata->host_nb > 0) {
- simdata->compute =
- boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(simcall_execution_parallel_start(
- task->name ?: "", simdata->host_nb, simdata->host_list, simdata->flops_parallel_amount,
- simdata->bytes_parallel_amount, -1.0, timeout));
- XBT_DEBUG("Parallel execution action created: %p", simdata->compute.get());
- if (task->category != nullptr)
- simgrid::simix::simcall([task] { task->simdata->compute->set_category(task->category); });
- } else {
- sg_host_t host = MSG_process_get_host(MSG_process_self());
- simdata->compute = simgrid::simix::simcall([task, host] {
- return simgrid::kernel::activity::ExecImplPtr(
- new simgrid::kernel::activity::ExecImpl(task->name ?: "", task->category ?: "",
- /*timeout_detector*/ nullptr, host));
- });
- /* checking for infinite values */
- xbt_assert(std::isfinite(simdata->flops_amount), "flops_amount is not finite!");
- xbt_assert(std::isfinite(simdata->priority), "priority is not finite!");
-
- simdata->compute->start(simdata->flops_amount, simdata->priority, simdata->bound);
- }
-
- comp_state = simcall_execution_wait(simdata->compute);
-
- simdata->setNotUsed();
-
- XBT_DEBUG("Execution task '%s' finished in state %d", task->name, (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 */
- simdata->flops_amount = 0.0;
- simdata->comm = nullptr;
- simdata->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;
-}
-