-/** \ingroup msg_task_usage
- * \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);
-}
-
-/** \ingroup msg_task_usage
- * \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;
-
- TRACE_msg_task_execute_start(task);
-
- 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) {
- TRACE_msg_task_execute_end(task);
- return MSG_OK;
- }
-
- 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());
- } else {
- simdata->compute = boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(
- simcall_execution_start(task->name, simdata->flops_amount, simdata->priority, simdata->bound,
- MSG_process_get_host(MSG_process_self())));
- }
- simcall_set_category(simdata->compute, task->category);
- comp_state = simcall_execution_wait(simdata->compute);
-
- simdata->setNotUsed();
-
- XBT_DEBUG("Execution task '%s' finished in state %d", task->name, (int)comp_state);
- }
- catch (xbt_ex& e) {
- switch (e.category) {
- case cancel_error:
- status = MSG_TASK_CANCELED;
- break;
- case host_error:
- status = MSG_HOST_FAILURE;
- break;
- case timeout_error:
- status = MSG_TIMEOUT;
- break;
- default:
- throw;
- }
- }
-
- /* 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;
- TRACE_msg_task_execute_end(task);
-
- return status;
-}
-
-/** \ingroup msg_task_usage
- * \brief Sleep for the specified number of seconds
- *
- * Makes the current process sleep until \a time seconds have elapsed.
- *
- * \param nb_sec a number of second
- */
-msg_error_t MSG_process_sleep(double nb_sec)
-{
- msg_error_t status = MSG_OK;
-
- if (TRACE_actor_is_enabled())
- simgrid::instr::Container::byName(instr_pid(MSG_process_self()))->getState("ACTOR_STATE")->pushEvent("sleep");
-
- try {
- simcall_process_sleep(nb_sec);
- }
- catch(xbt_ex& e) {
- if (e.category == cancel_error) {
- XBT_DEBUG("According to the JAVA API, a sleep call should only deal with HostFailureException, I'm lost.");
- // adsein: MSG_TASK_CANCELED is assigned when someone kills the process that made the sleep, this is not
- // correct. For instance, when the node is turned off, the error should be MSG_HOST_FAILURE, which is by the way
- // and according to the JAVA document, the only exception that can be triggered by MSG_Process_sleep call.
- // To avoid possible impacts in the code, I just raised a host_failure exception for the moment in the JAVA code
- // and did not change anythings at the C level.
- // See comment in the jmsg_process.c file, function JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cls, jlong jmillis, jint jnanos)
- status = MSG_TASK_CANCELED;
- } else
- throw;
- }
-
- if (TRACE_actor_is_enabled())
- simgrid::instr::Container::byName(instr_pid(MSG_process_self()))->getState("ACTOR_STATE")->popEvent();
-
- return status;
-}
-
-/** \ingroup msg_task_usage
- * \brief Receives a task from a mailbox.