1 /* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "msg_private.hpp"
7 #include "src/instr/instr_private.hpp"
8 #include <simgrid/s4u/Comm.hpp>
9 #include <simgrid/s4u/Exec.hpp>
10 #include <simgrid/s4u/Host.hpp>
11 #include <simgrid/s4u/Mailbox.hpp>
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_task, msg, "Logging specific to MSG (task)");
21 Task::Task(const std::string& name, double flops_amount, double bytes_amount, void* data)
22 : name_(name), userdata_(data), flops_amount(flops_amount), bytes_amount(bytes_amount)
24 static std::atomic_ullong counter{0};
27 MC_ignore_heap(&(id_), sizeof(id_));
30 Task::Task(const std::string& name, std::vector<s4u::Host*>&& hosts, std::vector<double>&& flops_amount,
31 std::vector<double>&& bytes_amount, void* data)
32 : Task(name, 1.0, 0, data)
35 hosts_ = std::move(hosts);
36 flops_parallel_amount = std::move(flops_amount);
37 bytes_parallel_amount = std::move(bytes_amount);
40 Task* Task::create(const std::string& name, double flops_amount, double bytes_amount, void* data)
42 return new Task(name, flops_amount, bytes_amount, data);
45 Task* Task::create_parallel(const std::string& name, int host_nb, const msg_host_t* host_list, double* flops_amount,
46 double* bytes_amount, void* data)
48 std::vector<s4u::Host*> hosts(host_list, host_list + host_nb);
49 std::vector<double> flops;
50 std::vector<double> bytes;
51 if (flops_amount != nullptr)
52 flops = std::vector<double>(flops_amount, flops_amount + host_nb);
53 if (bytes_amount != nullptr)
54 bytes = std::vector<double>(bytes_amount, bytes_amount + host_nb * host_nb);
56 return new Task(name, std::move(hosts), std::move(flops), std::move(bytes), data);
59 msg_error_t Task::execute()
61 /* checking for infinite values */
62 xbt_assert(std::isfinite(flops_amount), "flops_amount is not finite!");
64 msg_error_t status = MSG_OK;
65 if (flops_amount <= 0.0)
71 compute = s4u::this_actor::exec_init(hosts_, flops_parallel_amount, bytes_parallel_amount);
73 compute = s4u::this_actor::exec_init(flops_amount);
75 compute->set_name(name_)
76 ->set_tracing_category(tracing_category_)
77 ->set_timeout(timeout_)
78 ->set_priority(1 / priority_)
83 XBT_DEBUG("Execution task '%s' finished", get_cname());
84 } catch (const HostFailureException&) {
85 status = MSG_HOST_FAILURE;
86 } catch (const TimeoutException&) {
88 } catch (const CancelException&) {
89 status = MSG_TASK_CANCELED;
92 /* action ended, set comm and compute = nullptr, the actions is already destroyed in the main function */
100 s4u::CommPtr Task::send_async(const std::string& alias, void_f_pvoid_t cleanup, bool detached)
102 if (TRACE_actor_is_enabled()) {
103 container_t process_container = instr::Container::by_name(instr_pid(*MSG_process_self()));
104 std::string key = std::string("p") + std::to_string(get_id());
105 instr::Container::get_root()->get_link("ACTOR_TASK_LINK")->start_event(process_container, "SR", key);
108 /* Prepare the task to send */
110 this->comm = nullptr;
111 msg_global->sent_msg++;
113 s4u::CommPtr s4u_comm = s4u::Mailbox::by_name(alias)->put_init(this, bytes_amount)->set_rate(get_rate());
114 if (TRACE_is_enabled() && has_tracing_category())
115 s4u_comm->set_tracing_category(tracing_category_);
120 comm->detach(cleanup);
127 msg_error_t Task::send(const std::string& alias, double timeout)
129 msg_error_t ret = MSG_OK;
132 comm = nullptr; // needed, otherwise MC gets confused.
133 s4u::CommPtr s4u_comm = send_async(alias, nullptr, false);
135 comm->wait_for(timeout);
136 } catch (const TimeoutException&) {
138 } catch (const CancelException&) {
139 ret = MSG_HOST_FAILURE;
140 } catch (const NetworkFailureException&) {
141 ret = MSG_TRANSFER_FAILURE;
142 /* If the send failed, it is not used anymore */
158 void Task::set_priority(double priority)
160 xbt_assert(std::isfinite(1.0 / priority), "priority is not finite!");
161 priority_ = 1.0 / priority;
164 s4u::Actor* Task::get_sender()
166 return comm ? comm->get_sender() : nullptr;
169 s4u::Host* Task::get_source()
171 return comm ? comm->get_sender()->get_host() : nullptr;
174 void Task::set_used()
177 report_multiple_use();
181 void Task::report_multiple_use() const
183 if (MSG_Global_t::debug_multiple_use) {
184 XBT_ERROR("This task is already used in there:");
186 XBT_ERROR("<missing backtrace>");
187 XBT_ERROR("And you try to reuse it from here:");
188 xbt_backtrace_display_current();
190 xbt_die("This task is still being used somewhere else. You cannot send it now. Go fix your code!"
191 "(use --cfg=msg/debug-multiple-use:on to get the backtrace of the other process)");
195 } // namespace simgrid
197 /********************************* Task **************************************/
198 /** @brief Creates a new task
200 * A constructor for msg_task_t taking four arguments.
202 * @param name a name for the object. It is for user-level information and can be nullptr.
203 * @param flop_amount a value of the processing amount (in flop) needed to process this new task.
204 * If 0, then it cannot be executed with MSG_task_execute(). This value has to be >=0.
205 * @param message_size a value of the amount of data (in bytes) needed to transfer this new task. If 0, then it cannot
206 * be transferred with MSG_task_send() and MSG_task_recv(). This value has to be >=0.
207 * @param data a pointer to any data may want to attach to the new object. It is for user-level information and can
208 * be nullptr. It can be retrieved with the function @ref MSG_task_get_data.
209 * @return The new corresponding object.
211 msg_task_t MSG_task_create(const char *name, double flop_amount, double message_size, void *data)
213 return simgrid::msg::Task::create(name ? std::string(name) : "", flop_amount, message_size, data);
216 /** @brief Creates a new parallel task
218 * A constructor for #msg_task_t taking six arguments.
221 * See :cpp:func:`void simgrid::s4u::this_actor::parallel_execute(int, s4u::Host**, double*, double*)` for
222 * the exact semantic of the parameters.
225 * @param name a name for the object. It is for user-level information and can be nullptr.
226 * @param host_nb the number of hosts implied in the parallel task.
227 * @param host_list an array of @p host_nb msg_host_t.
228 * @param flops_amount an array of @p host_nb doubles.
229 * flops_amount[i] is the total number of operations that have to be performed on host_list[i].
230 * @param bytes_amount an array of @p host_nb* @p host_nb doubles.
231 * @param data a pointer to any data may want to attach to the new object.
232 * It is for user-level information and can be nullptr.
233 * It can be retrieved with the function @ref MSG_task_get_data().
235 msg_task_t MSG_parallel_task_create(const char *name, int host_nb, const msg_host_t * host_list,
236 double *flops_amount, double *bytes_amount, void *data)
238 // Task's flops amount is set to an arbitrary value > 0.0 to be able to distinguish, in
239 // MSG_task_get_remaining_work_ratio(), a finished task and a task that has not started yet.
240 return simgrid::msg::Task::create_parallel(name ? name : "", host_nb, host_list, flops_amount, bytes_amount, data);
243 /** @brief Return the user data of the given task */
244 void* MSG_task_get_data(msg_task_t task)
246 return task->get_user_data();
249 /** @brief Sets the user data of a given task */
250 void MSG_task_set_data(msg_task_t task, void *data)
252 task->set_user_data(data);
255 /** @brief Returns the sender of the given task */
256 msg_process_t MSG_task_get_sender(msg_task_t task)
258 return task->get_sender();
261 /** @brief Returns the source (the sender's host) of the given task */
262 msg_host_t MSG_task_get_source(msg_task_t task)
264 return task->get_source();
267 /** @brief Returns the name of the given task. */
268 const char *MSG_task_get_name(msg_task_t task)
270 return task->get_cname();
273 /** @brief Sets the name of the given task. */
274 void MSG_task_set_name(msg_task_t task, const char *name)
276 task->set_name(name);
280 * @brief Executes a task and waits for its termination.
282 * This function is used for describing the behavior of a process. It takes only one parameter.
283 * @param task a #msg_task_t to execute on the location on which the process is running.
284 * @return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED or #MSG_HOST_FAILURE otherwise
286 msg_error_t MSG_task_execute(msg_task_t task)
288 return task->execute();
292 * @brief Executes a parallel task and waits for its termination.
294 * @param task a #msg_task_t to execute on the location on which the process is running.
296 * @return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED or #MSG_HOST_FAILURE otherwise
298 msg_error_t MSG_parallel_task_execute(msg_task_t task)
300 return task->execute();
303 msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeout)
305 task->set_timeout(timeout);
306 return task->execute();
310 * @brief Sends a task on a mailbox.
312 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
314 * @param task a #msg_task_t to send on another location.
315 * @param alias name of the mailbox to sent the task to
316 * @return the msg_comm_t communication created
318 msg_comm_t MSG_task_isend(msg_task_t task, const char* alias)
320 return new simgrid::msg::Comm(task, nullptr, task->send_async(alias, nullptr, false));
324 * @brief Sends a task on a mailbox with a maximum rate
326 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication. The maxrate
327 * parameter allows the application to limit the bandwidth utilization of network links when sending the task.
329 * @param task a #msg_task_t to send on another location.
330 * @param alias name of the mailbox to sent the task to
331 * @param maxrate the maximum communication rate for sending this task (byte/sec).
332 * @return the msg_comm_t communication created
334 msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char* alias, double maxrate)
336 task->set_rate(maxrate);
337 return new simgrid::msg::Comm(task, nullptr, task->send_async(alias, nullptr, false));
341 * @brief Sends a task on a mailbox.
343 * This is a non blocking detached send function.
344 * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
345 * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
346 * usual. More details on this can be obtained on
347 * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
348 * in the SimGrid-user mailing list archive.
350 * @param task a #msg_task_t to send on another location.
351 * @param alias name of the mailbox to sent the task to
352 * @param cleanup a function to destroy the task if the communication fails, e.g. MSG_task_destroy
353 * (if nullptr, no function will be called)
355 void MSG_task_dsend(msg_task_t task, const char* alias, void_f_pvoid_t cleanup)
357 task->send_async(alias, cleanup, true);
361 * @brief Sends a task on a mailbox with a maximal rate.
363 * This is a non blocking detached send function.
364 * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
365 * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
366 * usual. More details on this can be obtained on
367 * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
368 * in the SimGrid-user mailing list archive.
370 * The rate parameter can be used to send a task with a limited bandwidth (smaller than the physical available value).
371 * Use MSG_task_dsend() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
373 * @param task a #msg_task_t to send on another location.
374 * @param alias name of the mailbox to sent the task to
375 * @param cleanup a function to destroy the task if the communication fails, e.g. MSG_task_destroy (if nullptr, no
376 * function will be called)
377 * @param maxrate the maximum communication rate for sending this task (byte/sec)
380 void MSG_task_dsend_bounded(msg_task_t task, const char* alias, void_f_pvoid_t cleanup, double maxrate)
382 task->set_rate(maxrate);
383 task->send_async(alias, cleanup, true);
386 * @brief Sends a task to a mailbox
388 * This is a blocking function, the execution flow will be blocked until the task is sent (and received on the other
389 * side if #MSG_task_receive is used).
390 * See #MSG_task_isend for sending tasks asynchronously.
392 * @param task the task to be sent
393 * @param alias the mailbox name to where the task is sent
395 * @return Returns #MSG_OK if the task was successfully sent,
396 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
398 msg_error_t MSG_task_send(msg_task_t task, const char* alias)
400 XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
401 return task->send(alias, -1);
405 * @brief Sends a task to a mailbox with a maximum rate
407 * This is a blocking function, the execution flow will be blocked until the task is sent. The maxrate parameter allows
408 * the application to limit the bandwidth utilization of network links when sending the task.
410 * The maxrate parameter can be used to send a task with a limited bandwidth (smaller than the physical available
411 * value). Use MSG_task_send() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
413 * @param task the task to be sent
414 * @param alias the mailbox name to where the task is sent
415 * @param maxrate the maximum communication rate for sending this task (byte/sec)
417 * @return Returns #MSG_OK if the task was successfully sent,
418 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
420 msg_error_t MSG_task_send_bounded(msg_task_t task, const char* alias, double maxrate)
422 task->set_rate(maxrate);
423 return task->send(alias, -1);
427 * @brief Sends a task to a mailbox with a timeout
429 * This is a blocking function, the execution flow will be blocked until the task is sent or the timeout is achieved.
431 * @param task the task to be sent
432 * @param alias the mailbox name to where the task is sent
433 * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
435 * @return Returns #MSG_OK if the task was successfully sent,
436 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
438 msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char* alias, double timeout)
440 return task->send(alias, timeout);
444 * @brief Sends a task to a mailbox with a timeout and with a maximum rate
446 * This is a blocking function, the execution flow will be blocked until the task is sent or the timeout is achieved.
448 * The maxrate parameter can be used to send a task with a limited bandwidth (smaller than the physical available
449 * value). Use MSG_task_send_with_timeout() if you don't limit the rate (or pass -1 as a rate value do disable this
452 * @param task the task to be sent
453 * @param alias the mailbox name to where the task is sent
454 * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
455 * @param maxrate the maximum communication rate for sending this task (byte/sec)
457 * @return Returns #MSG_OK if the task was successfully sent,
458 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
460 msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char* alias, double timeout, double maxrate)
462 task->set_rate(maxrate);
463 return task->send(alias, timeout);
467 * @brief Receives a task from a mailbox.
469 * This is a blocking function, the execution flow will be blocked until the task is received. See #MSG_task_irecv
470 * for receiving tasks asynchronously.
472 * @param task a memory location for storing a #msg_task_t.
473 * @param alias name of the mailbox to receive the task from
476 * #MSG_OK if the task was successfully received,
477 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
479 msg_error_t MSG_task_receive(msg_task_t * task, const char *alias)
481 return MSG_task_receive_with_timeout(task, alias, -1);
485 * @brief Receives a task from a mailbox at a given rate.
487 * @param task a memory location for storing a #msg_task_t.
488 * @param alias name of the mailbox to receive the task from
489 * @param rate limit the reception to rate bandwidth (byte/sec)
491 * The rate parameter can be used to receive a task with a limited bandwidth (smaller than the physical available
492 * value). Use MSG_task_receive() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
495 * #MSG_OK if the task was successfully received,
496 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
498 msg_error_t MSG_task_receive_bounded(msg_task_t* task, const char* alias, double rate)
500 return MSG_task_receive_with_timeout_bounded(task, alias, -1, rate);
504 * @brief Receives a task from a mailbox with a given timeout.
506 * This is a blocking function with a timeout, the execution flow will be blocked until the task is received or the
507 * timeout is achieved. See #MSG_task_irecv for receiving tasks asynchronously. You can provide a -1 timeout
508 * to obtain an infinite timeout.
510 * @param task a memory location for storing a #msg_task_t.
511 * @param alias name of the mailbox to receive the task from
512 * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
515 * #MSG_OK if the task was successfully received,
516 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
518 msg_error_t MSG_task_receive_with_timeout(msg_task_t* task, const char* alias, double timeout)
520 return MSG_task_receive_with_timeout_bounded(task, alias, timeout, -1);
524 * @brief Receives a task from a mailbox with a given timeout and at a given rate.
526 * @param task a memory location for storing a #msg_task_t.
527 * @param alias name of the mailbox to receive the task from
528 * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
529 * @param rate limit the reception to rate bandwidth (byte/sec)
531 * The rate parameter can be used to send a task with a limited
532 * bandwidth (smaller than the physical available value). Use
533 * MSG_task_receive() if you don't limit the rate (or pass -1 as a
534 * rate value do disable this feature).
537 * #MSG_OK if the task was successfully received,
538 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
540 msg_error_t MSG_task_receive_with_timeout_bounded(msg_task_t* task, const char* alias, double timeout, double rate)
542 XBT_DEBUG("MSG_task_receive_with_timeout_bounded: Trying to receive a message on mailbox '%s'", alias);
543 msg_error_t ret = MSG_OK;
546 xbt_assert(task, "Null pointer for the task storage");
549 XBT_WARN("Asked to write the received task in a non empty struct -- proceeding.");
551 /* Try to receive it by calling SIMIX network layer */
554 simgrid::s4u::Mailbox::by_name(alias)
556 ->set_dst_data(&payload, sizeof(msg_task_t*))
559 *task = static_cast<msg_task_t>(payload);
560 XBT_DEBUG("Got task %s from %s", (*task)->get_cname(), alias);
561 (*task)->set_not_used();
562 } catch (const simgrid::HostFailureException&) {
563 ret = MSG_HOST_FAILURE;
564 } catch (const simgrid::TimeoutException&) {
566 } catch (const simgrid::CancelException&) {
567 ret = MSG_TASK_CANCELED;
568 } catch (const simgrid::NetworkFailureException&) {
569 ret = MSG_TRANSFER_FAILURE;
572 if (TRACE_actor_is_enabled() && ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) {
573 container_t process_container = simgrid::instr::Container::by_name(instr_pid(*MSG_process_self()));
575 std::string key = std::string("p") + std::to_string((*task)->get_id());
576 simgrid::instr::Container::get_root()->get_link("ACTOR_TASK_LINK")->end_event(process_container, "SR", key);
582 * @brief Starts listening for receiving a task from an asynchronous communication.
584 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
586 * @param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
587 * @param name of the mailbox to receive the task on
588 * @return the msg_comm_t communication created
590 msg_comm_t MSG_task_irecv(msg_task_t* task, const char* name)
592 return MSG_task_irecv_bounded(task, name, -1.0);
596 * @brief Starts listening for receiving a task from an asynchronous communication at a given rate.
598 * The rate parameter can be used to receive a task with a limited
599 * bandwidth (smaller than the physical available value). Use
600 * MSG_task_irecv() if you don't limit the rate (or pass -1 as a rate
601 * value do disable this feature).
603 * @param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
604 * @param name of the mailbox to receive the task on
605 * @param rate limit the bandwidth to the given rate (byte/sec)
606 * @return the msg_comm_t communication created
608 msg_comm_t MSG_task_irecv_bounded(msg_task_t* task, const char* name, double rate)
610 /* FIXME: these functions are not traceable */
612 xbt_assert(task, "Null pointer for the task storage");
615 XBT_CRITICAL("MSG_task_irecv() was asked to write in a non empty task struct.");
617 /* Try to receive it by calling SIMIX network layer */
618 simgrid::s4u::CommPtr comm = simgrid::s4u::Mailbox::by_name(name)
620 ->set_dst_data((void**)task, sizeof(msg_task_t*))
624 return new simgrid::msg::Comm(nullptr, task, comm);
628 * @brief Look if there is a communication on a mailbox and return the PID of the sender process.
630 * @param alias the name of the mailbox to be considered
632 * @return Returns the PID of sender process (or -1 if there is no communication in the mailbox)
635 int MSG_task_listen_from(const char* alias)
637 /* looks inside the rdv directly. Not clean. */
638 simgrid::kernel::activity::CommImplPtr comm = simgrid::s4u::Mailbox::by_name(alias)->front();
640 if (comm && comm->src_actor_)
641 return comm->src_actor_->get_pid();
646 /** @brief Destroys the given task.
648 * You should free user data, if any, @b before calling this destructor.
650 * Only the process that owns the task can destroy it.
651 * The owner changes after a successful send.
652 * If a task is successfully sent, the receiver becomes the owner and is supposed to destroy it. The sender should not
654 * If the task failed to be sent, the sender remains the owner of the task.
656 msg_error_t MSG_task_destroy(msg_task_t task)
658 if (task->is_used()) {
659 /* the task is being sent or executed: cancel it first */
663 /* free main structures */
669 /** @brief Cancel the given task
671 * If it was currently executed or transferred, the working process is stopped.
673 msg_error_t MSG_task_cancel(msg_task_t task)
675 xbt_assert((task != nullptr), "Cannot cancel a nullptr task");
680 /** @brief Returns a value in ]0,1[ that represent the task remaining work
681 * to do: starts at 1 and goes to 0. Returns 0 if not started or finished.
683 * It works for either parallel or sequential tasks.
685 double MSG_task_get_remaining_work_ratio(msg_task_t task) {
687 xbt_assert((task != nullptr), "Cannot get information from a nullptr task");
690 return task->compute->get_remaining_ratio();
692 // Task not started (flops_amount is > 0.0) or finished (flops_amount is set to 0.0)
693 return task->flops_amount > 0.0 ? 1.0 : 0.0;
697 /** @brief Returns the amount of flops that remain to be computed
699 * The returned value is initially the cost that you defined for the task, then it decreases until it reaches 0
701 * It works for sequential tasks, but the remaining amount of work is not a scalar value for parallel tasks.
702 * So you will get an exception if you call this function on parallel tasks. Just don't do it.
704 double MSG_task_get_flops_amount(msg_task_t task) {
705 if (task->compute != nullptr) {
706 return task->compute->get_remaining();
708 // Not started or already done.
709 // - Before starting, flops_amount is initially the task cost
710 // - After execution, flops_amount is set to 0 (until someone uses MSG_task_set_flops_amount, if any)
711 return task->flops_amount;
715 /** @brief set the computation amount needed to process the given task.
717 * @warning If the computation is ongoing (already started and not finished),
718 * it is not modified by this call. Moreover, after its completion, the ongoing execution with set the flops_amount to
719 * zero, overriding any value set during the execution.
721 void MSG_task_set_flops_amount(msg_task_t task, double flops_amount)
723 task->flops_amount = flops_amount;
726 /** @brief set the amount data attached with the given task.
728 * @warning If the transfer is ongoing (already started and not finished), it is not modified by this call.
730 void MSG_task_set_bytes_amount(msg_task_t task, double data_size)
732 task->bytes_amount = data_size;
735 /** @brief Returns the total amount received by the given task
737 * If the communication does not exist it will return 0.
738 * So, if the communication has FINISHED or FAILED it returns zero.
740 double MSG_task_get_remaining_communication(msg_task_t task)
742 XBT_DEBUG("calling simcall_communication_get_remains(%p)", task->comm.get());
743 return task->comm->get_remaining();
746 /** @brief Returns the size of the data attached to the given task. */
747 double MSG_task_get_bytes_amount(msg_task_t task)
749 xbt_assert(task != nullptr, "Invalid parameter");
750 return task->bytes_amount;
753 /** @brief Changes the priority of a computation task.
755 * This priority doesn't affect the transfer rate. A priority of 2
756 * will make a task receive two times more cpu power than regular tasks.
758 void MSG_task_set_priority(msg_task_t task, double priority)
760 task->set_priority(priority);
763 /** @brief Changes the maximum CPU utilization of a computation task (in flops/s).
765 * For VMs, there is a pitfall. Please see MSG_vm_set_bound().
767 void MSG_task_set_bound(msg_task_t task, double bound)
769 if (bound < 1e-12) /* close enough to 0 without any floating precision surprise */
770 XBT_INFO("bound == 0 means no capping (i.e., unlimited).");
771 task->set_bound(bound);
775 * @brief Sets the tracing category of a task.
777 * This function should be called after the creation of a MSG task, to define the category of that task. The
778 * first parameter task must contain a task that was =created with the function #MSG_task_create. The second
779 * parameter category must contain a category that was previously declared with the function #TRACE_category
780 * (or with #TRACE_category_with_color).
782 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
784 * @param task the task that is going to be categorized
785 * @param category the name of the category to be associated to the task
787 * @see MSG_task_get_category, TRACE_category, TRACE_category_with_color
789 void MSG_task_set_category(msg_task_t task, const char* category)
791 xbt_assert(not task->has_tracing_category(), "Task %p(%s) already has a category (%s).", task, task->get_cname(),
792 task->get_tracing_category().c_str());
794 // if user provides a nullptr category, task is no longer traced
795 if (category == nullptr) {
796 task->set_tracing_category("");
797 XBT_DEBUG("MSG task %p(%s), category removed", task, task->get_cname());
800 task->set_tracing_category(category);
801 XBT_DEBUG("MSG task %p(%s), category %s", task, task->get_cname(), task->get_tracing_category().c_str());
806 * @brief Gets the current tracing category of a task. (@see MSG_task_set_category)
807 * @param task the task to be considered
808 * @return Returns the name of the tracing category of the given task, "" otherwise
810 const char* MSG_task_get_category(msg_task_t task)
812 return task->get_tracing_category().c_str();