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), flops_amount(flops_amount), bytes_amount(bytes_amount)
24 static std::atomic_ullong counter{0};
28 MC_ignore_heap(&(id_), sizeof(id_));
31 Task::Task(const std::string& name, std::vector<s4u::Host*>&& hosts, std::vector<double>&& flops_amount,
32 std::vector<double>&& bytes_amount, void* data)
33 : Task(name, 1.0, 0, data)
36 hosts_ = std::move(hosts);
37 flops_parallel_amount = std::move(flops_amount);
38 bytes_parallel_amount = std::move(bytes_amount);
41 Task* Task::create(const std::string& name, double flops_amount, double bytes_amount, void* data)
43 return new Task(name, flops_amount, bytes_amount, data);
46 Task* Task::create_parallel(const std::string& name, int host_nb, const msg_host_t* host_list, double* flops_amount,
47 double* bytes_amount, void* data)
49 std::vector<s4u::Host*> hosts(host_list, host_list + host_nb);
50 std::vector<double> flops;
51 std::vector<double> bytes;
52 if (flops_amount != nullptr)
53 flops = std::vector<double>(flops_amount, flops_amount + host_nb);
54 if (bytes_amount != nullptr)
55 bytes = std::vector<double>(bytes_amount, bytes_amount + host_nb * host_nb);
57 return new Task(name, std::move(hosts), std::move(flops), std::move(bytes), data);
60 msg_error_t Task::execute()
62 /* checking for infinite values */
63 xbt_assert(std::isfinite(flops_amount), "flops_amount is not finite!");
65 msg_error_t status = MSG_OK;
66 if (flops_amount <= 0.0)
72 compute = s4u::this_actor::exec_init(hosts_, flops_parallel_amount, bytes_parallel_amount);
74 compute = s4u::this_actor::exec_init(flops_amount);
76 compute->set_name(name_)
77 ->set_tracing_category(tracing_category_)
78 ->set_timeout(timeout_)
79 ->set_priority(1 / priority_)
84 XBT_DEBUG("Execution task '%s' finished", get_cname());
85 } catch (const HostFailureException&) {
86 status = MSG_HOST_FAILURE;
87 } catch (const TimeoutException&) {
89 } catch (const CancelException&) {
90 status = MSG_TASK_CANCELED;
93 /* action ended, set comm and compute = nullptr, the actions is already destroyed in the main function */
101 s4u::CommPtr Task::send_async(const std::string& alias, void_f_pvoid_t cleanup, bool detached)
103 if (TRACE_actor_is_enabled()) {
104 container_t process_container = instr::Container::by_name(instr_pid(*MSG_process_self()));
105 std::string key = std::string("p") + std::to_string(get_id());
106 instr::Container::get_root()->get_link("ACTOR_TASK_LINK")->start_event(process_container, "SR", key);
109 /* Prepare the task to send */
111 this->comm = nullptr;
112 msg_global->sent_msg++;
114 s4u::CommPtr s4u_comm = s4u::Mailbox::by_name(alias)->put_init(this, bytes_amount)->set_rate(get_rate());
115 if (TRACE_is_enabled() && has_tracing_category())
116 s4u_comm->set_tracing_category(tracing_category_);
121 comm->detach(cleanup);
128 msg_error_t Task::send(const std::string& alias, double timeout)
130 msg_error_t ret = MSG_OK;
133 comm = nullptr; // needed, otherwise MC gets confused.
134 s4u::CommPtr s4u_comm = send_async(alias, nullptr, false);
136 comm->wait_for(timeout);
137 } catch (const TimeoutException&) {
139 } catch (const CancelException&) {
140 ret = MSG_HOST_FAILURE;
141 } catch (const NetworkFailureException&) {
142 ret = MSG_TRANSFER_FAILURE;
143 /* If the send failed, it is not used anymore */
159 void Task::set_priority(double priority)
161 xbt_assert(std::isfinite(1.0 / priority), "priority is not finite!");
162 priority_ = 1.0 / priority;
165 s4u::Actor* Task::get_sender()
167 return comm ? comm->get_sender() : nullptr;
170 s4u::Host* Task::get_source()
172 return comm ? comm->get_sender()->get_host() : nullptr;
175 void Task::set_used()
178 report_multiple_use();
182 void Task::report_multiple_use() const
184 if (MSG_Global_t::debug_multiple_use) {
185 XBT_ERROR("This task is already used in there:");
187 XBT_ERROR("<missing backtrace>");
188 XBT_ERROR("And you try to reuse it from here:");
189 xbt_backtrace_display_current();
191 xbt_die("This task is still being used somewhere else. You cannot send it now. Go fix your code!"
192 "(use --cfg=msg/debug-multiple-use:on to get the backtrace of the other process)");
196 } // namespace simgrid
198 /********************************* Task **************************************/
199 /** @brief Creates a new task
201 * A constructor for msg_task_t taking four arguments.
203 * @param name a name for the object. It is for user-level information and can be nullptr.
204 * @param flop_amount a value of the processing amount (in flop) needed to process this new task.
205 * If 0, then it cannot be executed with MSG_task_execute(). This value has to be >=0.
206 * @param message_size a value of the amount of data (in bytes) needed to transfer this new task. If 0, then it cannot
207 * be transferred with MSG_task_send() and MSG_task_recv(). This value has to be >=0.
208 * @param data a pointer to any data may want to attach to the new object. It is for user-level information and can
209 * be nullptr. It can be retrieved with the function @ref MSG_task_get_data.
210 * @return The new corresponding object.
212 msg_task_t MSG_task_create(const char *name, double flop_amount, double message_size, void *data)
214 return simgrid::msg::Task::create(name ? std::string(name) : "", flop_amount, message_size, data);
217 /** @brief Creates a new parallel task
219 * A constructor for #msg_task_t taking six arguments.
222 * See :cpp:func:`void simgrid::s4u::this_actor::parallel_execute(int, s4u::Host**, double*, double*)` for
223 * the exact semantic of the parameters.
226 * @param name a name for the object. It is for user-level information and can be nullptr.
227 * @param host_nb the number of hosts implied in the parallel task.
228 * @param host_list an array of @p host_nb msg_host_t.
229 * @param flops_amount an array of @p host_nb doubles.
230 * flops_amount[i] is the total number of operations that have to be performed on host_list[i].
231 * @param bytes_amount an array of @p host_nb* @p host_nb doubles.
232 * @param data a pointer to any data may want to attach to the new object.
233 * It is for user-level information and can be nullptr.
234 * It can be retrieved with the function @ref MSG_task_get_data().
236 msg_task_t MSG_parallel_task_create(const char *name, int host_nb, const msg_host_t * host_list,
237 double *flops_amount, double *bytes_amount, void *data)
239 // Task's flops amount is set to an arbitrary value > 0.0 to be able to distinguish, in
240 // MSG_task_get_remaining_work_ratio(), a finished task and a task that has not started yet.
241 return simgrid::msg::Task::create_parallel(name ? name : "", host_nb, host_list, flops_amount, bytes_amount, data);
244 /** @brief Return the user data of the given task */
245 void* MSG_task_get_data(msg_task_t task)
247 return task->get_data();
250 /** @brief Sets the user data of a given task */
251 void MSG_task_set_data(msg_task_t task, void *data)
253 task->set_data(data);
256 /** @brief Returns the sender of the given task */
257 msg_process_t MSG_task_get_sender(msg_task_t task)
259 return task->get_sender();
262 /** @brief Returns the source (the sender's host) of the given task */
263 msg_host_t MSG_task_get_source(msg_task_t task)
265 return task->get_source();
268 /** @brief Returns the name of the given task. */
269 const char *MSG_task_get_name(msg_task_t task)
271 return task->get_cname();
274 /** @brief Sets the name of the given task. */
275 void MSG_task_set_name(msg_task_t task, const char *name)
277 task->set_name(name);
281 * @brief Executes a task and waits for its termination.
283 * This function is used for describing the behavior of a process. It takes only one parameter.
284 * @param task a #msg_task_t to execute on the location on which the process is running.
285 * @return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED or #MSG_HOST_FAILURE otherwise
287 msg_error_t MSG_task_execute(msg_task_t task)
289 return task->execute();
293 * @brief Executes a parallel task and waits for its termination.
295 * @param task a #msg_task_t to execute on the location on which the process is running.
297 * @return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED or #MSG_HOST_FAILURE otherwise
299 msg_error_t MSG_parallel_task_execute(msg_task_t task)
301 return task->execute();
304 msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeout)
306 task->set_timeout(timeout);
307 return task->execute();
311 * @brief Sends a task on a mailbox.
313 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
315 * @param task a #msg_task_t to send on another location.
316 * @param alias name of the mailbox to sent the task to
317 * @return the msg_comm_t communication created
319 msg_comm_t MSG_task_isend(msg_task_t task, const char* alias)
321 return new simgrid::msg::Comm(task, nullptr, task->send_async(alias, nullptr, false));
325 * @brief Sends a task on a mailbox with a maximum rate
327 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication. The maxrate
328 * parameter allows the application to limit the bandwidth utilization of network links when sending the task.
330 * @param task a #msg_task_t to send on another location.
331 * @param alias name of the mailbox to sent the task to
332 * @param maxrate the maximum communication rate for sending this task (byte/sec).
333 * @return the msg_comm_t communication created
335 msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char* alias, double maxrate)
337 task->set_rate(maxrate);
338 return new simgrid::msg::Comm(task, nullptr, task->send_async(alias, nullptr, false));
342 * @brief Sends a task on a mailbox.
344 * This is a non blocking detached send function.
345 * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
346 * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
347 * usual. More details on this can be obtained on
348 * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
349 * in the SimGrid-user mailing list archive.
351 * @param task a #msg_task_t to send on another location.
352 * @param alias name of the mailbox to sent the task to
353 * @param cleanup a function to destroy the task if the communication fails, e.g. MSG_task_destroy
354 * (if nullptr, no function will be called)
356 void MSG_task_dsend(msg_task_t task, const char* alias, void_f_pvoid_t cleanup)
358 task->send_async(alias, cleanup, true);
362 * @brief Sends a task on a mailbox with a maximal rate.
364 * This is a non blocking detached send function.
365 * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
366 * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
367 * usual. More details on this can be obtained on
368 * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
369 * in the SimGrid-user mailing list archive.
371 * The rate parameter can be used to send a task with a limited bandwidth (smaller than the physical available value).
372 * Use MSG_task_dsend() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
374 * @param task a #msg_task_t to send on another location.
375 * @param alias name of the mailbox to sent the task to
376 * @param cleanup a function to destroy the task if the communication fails, e.g. MSG_task_destroy (if nullptr, no
377 * function will be called)
378 * @param maxrate the maximum communication rate for sending this task (byte/sec)
381 void MSG_task_dsend_bounded(msg_task_t task, const char* alias, void_f_pvoid_t cleanup, double maxrate)
383 task->set_rate(maxrate);
384 task->send_async(alias, cleanup, true);
387 * @brief Sends a task to a mailbox
389 * This is a blocking function, the execution flow will be blocked until the task is sent (and received on the other
390 * side if #MSG_task_receive is used).
391 * See #MSG_task_isend for sending tasks asynchronously.
393 * @param task the task to be sent
394 * @param alias the mailbox name to where the task is sent
396 * @return Returns #MSG_OK if the task was successfully sent,
397 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
399 msg_error_t MSG_task_send(msg_task_t task, const char* alias)
401 XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
402 return task->send(alias, -1);
406 * @brief Sends a task to a mailbox with a maximum rate
408 * This is a blocking function, the execution flow will be blocked until the task is sent. The maxrate parameter allows
409 * the application to limit the bandwidth utilization of network links when sending the task.
411 * The maxrate parameter can be used to send a task with a limited bandwidth (smaller than the physical available
412 * value). Use MSG_task_send() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
414 * @param task the task to be sent
415 * @param alias the mailbox name to where the task is sent
416 * @param maxrate the maximum communication rate for sending this task (byte/sec)
418 * @return Returns #MSG_OK if the task was successfully sent,
419 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
421 msg_error_t MSG_task_send_bounded(msg_task_t task, const char* alias, double maxrate)
423 task->set_rate(maxrate);
424 return task->send(alias, -1);
428 * @brief Sends a task to a mailbox with a timeout
430 * This is a blocking function, the execution flow will be blocked until the task is sent or the timeout is achieved.
432 * @param task the task to be sent
433 * @param alias the mailbox name to where the task is sent
434 * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
436 * @return Returns #MSG_OK if the task was successfully sent,
437 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
439 msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char* alias, double timeout)
441 return task->send(alias, timeout);
445 * @brief Sends a task to a mailbox with a timeout and with a maximum rate
447 * This is a blocking function, the execution flow will be blocked until the task is sent or the timeout is achieved.
449 * The maxrate parameter can be used to send a task with a limited bandwidth (smaller than the physical available
450 * value). Use MSG_task_send_with_timeout() if you don't limit the rate (or pass -1 as a rate value do disable this
453 * @param task the task to be sent
454 * @param alias the mailbox name to where the task is sent
455 * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
456 * @param maxrate the maximum communication rate for sending this task (byte/sec)
458 * @return Returns #MSG_OK if the task was successfully sent,
459 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
461 msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char* alias, double timeout, double maxrate)
463 task->set_rate(maxrate);
464 return task->send(alias, timeout);
468 * @brief Receives a task from a mailbox.
470 * This is a blocking function, the execution flow will be blocked until the task is received. See #MSG_task_irecv
471 * for receiving tasks asynchronously.
473 * @param task a memory location for storing a #msg_task_t.
474 * @param alias name of the mailbox to receive the task from
477 * #MSG_OK if the task was successfully received,
478 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
480 msg_error_t MSG_task_receive(msg_task_t * task, const char *alias)
482 return MSG_task_receive_with_timeout(task, alias, -1);
486 * @brief Receives a task from a mailbox at a given rate.
488 * @param task a memory location for storing a #msg_task_t.
489 * @param alias name of the mailbox to receive the task from
490 * @param rate limit the reception to rate bandwidth (byte/sec)
492 * The rate parameter can be used to receive a task with a limited bandwidth (smaller than the physical available
493 * value). Use MSG_task_receive() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
496 * #MSG_OK if the task was successfully received,
497 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
499 msg_error_t MSG_task_receive_bounded(msg_task_t* task, const char* alias, double rate)
501 return MSG_task_receive_with_timeout_bounded(task, alias, -1, rate);
505 * @brief Receives a task from a mailbox with a given timeout.
507 * This is a blocking function with a timeout, the execution flow will be blocked until the task is received or the
508 * timeout is achieved. See #MSG_task_irecv for receiving tasks asynchronously. You can provide a -1 timeout
509 * to obtain an infinite timeout.
511 * @param task a memory location for storing a #msg_task_t.
512 * @param alias name of the mailbox to receive the task from
513 * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
516 * #MSG_OK if the task was successfully received,
517 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
519 msg_error_t MSG_task_receive_with_timeout(msg_task_t* task, const char* alias, double timeout)
521 return MSG_task_receive_with_timeout_bounded(task, alias, timeout, -1);
525 * @brief Receives a task from a mailbox with a given timeout and at a given rate.
527 * @param task a memory location for storing a #msg_task_t.
528 * @param alias name of the mailbox to receive the task from
529 * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
530 * @param rate limit the reception to rate bandwidth (byte/sec)
532 * The rate parameter can be used to send a task with a limited
533 * bandwidth (smaller than the physical available value). Use
534 * MSG_task_receive() if you don't limit the rate (or pass -1 as a
535 * rate value do disable this feature).
538 * #MSG_OK if the task was successfully received,
539 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
541 msg_error_t MSG_task_receive_with_timeout_bounded(msg_task_t* task, const char* alias, double timeout, double rate)
543 XBT_DEBUG("MSG_task_receive_with_timeout_bounded: Trying to receive a message on mailbox '%s'", alias);
544 msg_error_t ret = MSG_OK;
547 xbt_assert(task, "Null pointer for the task storage");
550 XBT_WARN("Asked to write the received task in a non empty struct -- proceeding.");
552 /* Try to receive it by calling SIMIX network layer */
555 simgrid::s4u::Mailbox::by_name(alias)
557 ->set_dst_data(&payload, sizeof(msg_task_t*))
560 *task = static_cast<msg_task_t>(payload);
561 XBT_DEBUG("Got task %s from %s", (*task)->get_cname(), alias);
562 (*task)->set_not_used();
563 } catch (const simgrid::HostFailureException&) {
564 ret = MSG_HOST_FAILURE;
565 } catch (const simgrid::TimeoutException&) {
567 } catch (const simgrid::CancelException&) {
568 ret = MSG_TASK_CANCELED;
569 } catch (const simgrid::NetworkFailureException&) {
570 ret = MSG_TRANSFER_FAILURE;
573 if (TRACE_actor_is_enabled() && ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) {
574 container_t process_container = simgrid::instr::Container::by_name(instr_pid(*MSG_process_self()));
576 std::string key = std::string("p") + std::to_string((*task)->get_id());
577 simgrid::instr::Container::get_root()->get_link("ACTOR_TASK_LINK")->end_event(process_container, "SR", key);
583 * @brief Starts listening for receiving a task from an asynchronous communication.
585 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
587 * @param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
588 * @param name of the mailbox to receive the task on
589 * @return the msg_comm_t communication created
591 msg_comm_t MSG_task_irecv(msg_task_t* task, const char* name)
593 return MSG_task_irecv_bounded(task, name, -1.0);
597 * @brief Starts listening for receiving a task from an asynchronous communication at a given rate.
599 * The rate parameter can be used to receive a task with a limited
600 * bandwidth (smaller than the physical available value). Use
601 * MSG_task_irecv() if you don't limit the rate (or pass -1 as a rate
602 * value do disable this feature).
604 * @param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
605 * @param name of the mailbox to receive the task on
606 * @param rate limit the bandwidth to the given rate (byte/sec)
607 * @return the msg_comm_t communication created
609 msg_comm_t MSG_task_irecv_bounded(msg_task_t* task, const char* name, double rate)
611 /* FIXME: these functions are not traceable */
613 xbt_assert(task, "Null pointer for the task storage");
616 XBT_CRITICAL("MSG_task_irecv() was asked to write in a non empty task struct.");
618 /* Try to receive it by calling SIMIX network layer */
619 simgrid::s4u::CommPtr comm = simgrid::s4u::Mailbox::by_name(name)
621 ->set_dst_data((void**)task, sizeof(msg_task_t*))
625 return new simgrid::msg::Comm(nullptr, task, comm);
629 * @brief Look if there is a communication on a mailbox and return the PID of the sender process.
631 * @param alias the name of the mailbox to be considered
633 * @return Returns the PID of sender process (or -1 if there is no communication in the mailbox)
636 int MSG_task_listen_from(const char* alias)
638 /* looks inside the rdv directly. Not clean. */
639 simgrid::kernel::activity::CommImplPtr comm = simgrid::s4u::Mailbox::by_name(alias)->front();
641 if (comm && comm->src_actor_)
642 return comm->src_actor_->get_pid();
647 /** @brief Destroys the given task.
649 * You should free user data, if any, @b before calling this destructor.
651 * Only the process that owns the task can destroy it.
652 * The owner changes after a successful send.
653 * If a task is successfully sent, the receiver becomes the owner and is supposed to destroy it. The sender should not
655 * If the task failed to be sent, the sender remains the owner of the task.
657 msg_error_t MSG_task_destroy(msg_task_t task)
659 if (task->is_used()) {
660 /* the task is being sent or executed: cancel it first */
664 /* free main structures */
670 /** @brief Cancel the given task
672 * If it was currently executed or transferred, the working process is stopped.
674 msg_error_t MSG_task_cancel(msg_task_t task)
676 xbt_assert((task != nullptr), "Cannot cancel a nullptr task");
681 /** @brief Returns a value in ]0,1[ that represent the task remaining work
682 * to do: starts at 1 and goes to 0. Returns 0 if not started or finished.
684 * It works for either parallel or sequential tasks.
686 double MSG_task_get_remaining_work_ratio(msg_task_t task) {
688 xbt_assert((task != nullptr), "Cannot get information from a nullptr task");
691 return task->compute->get_remaining_ratio();
693 // Task not started (flops_amount is > 0.0) or finished (flops_amount is set to 0.0)
694 return task->flops_amount > 0.0 ? 1.0 : 0.0;
698 /** @brief Returns the amount of flops that remain to be computed
700 * The returned value is initially the cost that you defined for the task, then it decreases until it reaches 0
702 * It works for sequential tasks, but the remaining amount of work is not a scalar value for parallel tasks.
703 * So you will get an exception if you call this function on parallel tasks. Just don't do it.
705 double MSG_task_get_flops_amount(msg_task_t task) {
706 if (task->compute != nullptr) {
707 return task->compute->get_remaining();
709 // Not started or already done.
710 // - Before starting, flops_amount is initially the task cost
711 // - After execution, flops_amount is set to 0 (until someone uses MSG_task_set_flops_amount, if any)
712 return task->flops_amount;
716 /** @brief set the computation amount needed to process the given task.
718 * @warning If the computation is ongoing (already started and not finished),
719 * it is not modified by this call. Moreover, after its completion, the ongoing execution with set the flops_amount to
720 * zero, overriding any value set during the execution.
722 void MSG_task_set_flops_amount(msg_task_t task, double flops_amount)
724 task->flops_amount = flops_amount;
727 /** @brief set the amount data attached with the given task.
729 * @warning If the transfer is ongoing (already started and not finished), it is not modified by this call.
731 void MSG_task_set_bytes_amount(msg_task_t task, double data_size)
733 task->bytes_amount = data_size;
736 /** @brief Returns the total amount received by the given task
738 * If the communication does not exist it will return 0.
739 * So, if the communication has FINISHED or FAILED it returns zero.
741 double MSG_task_get_remaining_communication(msg_task_t task)
743 XBT_DEBUG("calling simcall_communication_get_remains(%p)", task->comm.get());
744 return task->comm->get_remaining();
747 /** @brief Returns the size of the data attached to the given task. */
748 double MSG_task_get_bytes_amount(msg_task_t task)
750 xbt_assert(task != nullptr, "Invalid parameter");
751 return task->bytes_amount;
754 /** @brief Changes the priority of a computation task.
756 * This priority doesn't affect the transfer rate. A priority of 2
757 * will make a task receive two times more cpu power than regular tasks.
759 void MSG_task_set_priority(msg_task_t task, double priority)
761 task->set_priority(priority);
764 /** @brief Changes the maximum CPU utilization of a computation task (in flops/s).
766 * For VMs, there is a pitfall. Please see MSG_vm_set_bound().
768 void MSG_task_set_bound(msg_task_t task, double bound)
770 if (bound < 1e-12) /* close enough to 0 without any floating precision surprise */
771 XBT_INFO("bound == 0 means no capping (i.e., unlimited).");
772 task->set_bound(bound);
776 * @brief Sets the tracing category of a task.
778 * This function should be called after the creation of a MSG task, to define the category of that task. The
779 * first parameter task must contain a task that was =created with the function #MSG_task_create. The second
780 * parameter category must contain a category that was previously declared with the function #TRACE_category
781 * (or with #TRACE_category_with_color).
783 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
785 * @param task the task that is going to be categorized
786 * @param category the name of the category to be associated to the task
788 * @see MSG_task_get_category, TRACE_category, TRACE_category_with_color
790 void MSG_task_set_category(msg_task_t task, const char* category)
792 xbt_assert(not task->has_tracing_category(), "Task %p(%s) already has a category (%s).", task, task->get_cname(),
793 task->get_tracing_category().c_str());
795 // if user provides a nullptr category, task is no longer traced
796 if (category == nullptr) {
797 task->set_tracing_category("");
798 XBT_DEBUG("MSG task %p(%s), category removed", task, task->get_cname());
801 task->set_tracing_category(category);
802 XBT_DEBUG("MSG task %p(%s), category %s", task, task->get_cname(), task->get_tracing_category().c_str());
807 * @brief Gets the current tracing category of a task. (@see MSG_task_set_category)
808 * @param task the task to be considered
809 * @return Returns the name of the tracing category of the given task, "" otherwise
811 const char* MSG_task_get_category(msg_task_t task)
813 return task->get_tracing_category().c_str();