Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
803c9db1534b01f7eb459cbeacdfc9830a8d46cf
[simgrid.git] / src / msg / msg_task.cpp
1 /* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
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>
12
13 #include <algorithm>
14 #include <vector>
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_task, msg, "Logging specific to MSG (task)");
17
18 namespace simgrid {
19 namespace msg {
20
21 Task::Task(std::string name, double flops_amount, double bytes_amount, void* data)
22     : name_(std::move(name)), userdata_(data), flops_amount(flops_amount), bytes_amount(bytes_amount)
23 {
24   static std::atomic_ullong counter{0};
25   id_ = counter++;
26   if (MC_is_active())
27     MC_ignore_heap(&(id_), sizeof(id_));
28 }
29
30 Task::Task(std::string name, std::vector<s4u::Host*> hosts, std::vector<double> flops_amount,
31            std::vector<double> bytes_amount, void* data)
32     : Task(std::move(name), 1.0, 0, data)
33 {
34   parallel_             = true;
35   hosts_                = std::move(hosts);
36   flops_parallel_amount = std::move(flops_amount);
37   bytes_parallel_amount = std::move(bytes_amount);
38 }
39
40 Task* Task::create(std::string name, double flops_amount, double bytes_amount, void* data)
41 {
42   return new Task(std::move(name), flops_amount, bytes_amount, data);
43 }
44
45 Task* Task::create_parallel(std::string name, int host_nb, const msg_host_t* host_list, double* flops_amount,
46                             double* bytes_amount, void* data)
47 {
48   std::vector<s4u::Host*> hosts;
49   std::vector<double> flops;
50   std::vector<double> bytes;
51
52   for (int i = 0; i < host_nb; i++) {
53     hosts.push_back(host_list[i]);
54     if (flops_amount != nullptr)
55       flops.push_back(flops_amount[i]);
56     if (bytes_amount != nullptr) {
57       for (int j = 0; j < host_nb; j++)
58         bytes.push_back(bytes_amount[host_nb * i + j]);
59     }
60   }
61   return new Task(std::move(name), std::move(hosts), std::move(flops), std::move(bytes), data);
62 }
63
64 msg_error_t Task::execute()
65 {
66   /* checking for infinite values */
67   xbt_assert(std::isfinite(flops_amount), "flops_amount is not finite!");
68
69   msg_error_t status = MSG_OK;
70   if (flops_amount <= 0.0)
71     return MSG_OK;
72
73   try {
74     set_used();
75     if (parallel_)
76       compute = s4u::this_actor::exec_init(hosts_, flops_parallel_amount, bytes_parallel_amount);
77     else
78       compute = s4u::this_actor::exec_init(flops_amount);
79
80     compute->set_name(name_)
81         ->set_tracing_category(tracing_category_)
82         ->set_timeout(timeout_)
83         ->set_priority(1 / priority_)
84         ->set_bound(bound_)
85         ->wait();
86
87     set_not_used();
88     XBT_DEBUG("Execution task '%s' finished", get_cname());
89   } catch (HostFailureException& e) {
90     status = MSG_HOST_FAILURE;
91   } catch (TimeoutError& e) {
92     status = MSG_TIMEOUT;
93   } catch (CancelException& e) {
94     status = MSG_TASK_CANCELED;
95   }
96
97   /* action ended, set comm and compute = nullptr, the actions is already destroyed in the main function */
98   flops_amount = 0.0;
99   comm         = nullptr;
100   compute      = nullptr;
101
102   return status;
103 }
104
105 s4u::CommPtr Task::send_async(std::string alias, void_f_pvoid_t cleanup, bool detached)
106 {
107   if (TRACE_actor_is_enabled()) {
108     container_t process_container = simgrid::instr::Container::by_name(instr_pid(MSG_process_self()));
109     std::string key               = std::string("p") + std::to_string(get_id());
110     simgrid::instr::Container::get_root()->get_link("ACTOR_TASK_LINK")->start_event(process_container, "SR", key);
111   }
112
113   /* Prepare the task to send */
114   set_used();
115   this->comm = nullptr;
116   msg_global->sent_msg++;
117
118   s4u::CommPtr comm = s4u::Mailbox::by_name(alias)->put_init(this, bytes_amount)->set_rate(get_rate());
119   this->comm        = comm;
120
121   if (detached)
122     comm->detach(cleanup);
123   else
124     comm->start();
125
126   if (TRACE_is_enabled() && has_tracing_category())
127     simgrid::simix::simcall([comm, this] { comm->get_impl()->set_category(std::move(tracing_category_)); });
128
129   return comm;
130 }
131
132 msg_error_t Task::send(std::string alias, double timeout)
133 {
134   msg_error_t ret = MSG_OK;
135   /* Try to send it */
136   try {
137     s4u::CommPtr s4u_comm = send_async(alias, nullptr, false);
138     comm                  = s4u_comm;
139     comm->wait_for(timeout);
140   } catch (simgrid::TimeoutError& e) {
141     ret = MSG_TIMEOUT;
142   } catch (simgrid::CancelException& e) {
143     ret = MSG_HOST_FAILURE;
144   } catch (xbt_ex& e) {
145     if (e.category == network_error)
146       ret = MSG_TRANSFER_FAILURE;
147     else
148       throw;
149
150     /* If the send failed, it is not used anymore */
151     set_not_used();
152   }
153
154   return ret;
155 }
156 void Task::cancel()
157 {
158   if (compute) {
159     compute->cancel();
160   } else if (comm) {
161     comm->cancel();
162   }
163   set_not_used();
164 }
165
166 void Task::set_priority(double priority)
167 {
168   xbt_assert(std::isfinite(1.0 / priority), "priority is not finite!");
169   priority_ = 1.0 / priority;
170 }
171
172 s4u::Actor* Task::get_sender()
173 {
174   return comm ? comm->get_sender().get() : nullptr;
175 }
176
177 s4u::Host* Task::get_source()
178 {
179   return comm ? comm->get_sender()->get_host() : nullptr;
180 }
181
182 void Task::set_used()
183 {
184   if (is_used_)
185     report_multiple_use();
186   is_used_ = true;
187 }
188
189 void Task::report_multiple_use() const
190 {
191   if (msg_global->debug_multiple_use){
192     XBT_ERROR("This task is already used in there:");
193     // TODO, backtrace
194     XBT_ERROR("<missing backtrace>");
195     XBT_ERROR("And you try to reuse it from here:");
196     xbt_backtrace_display_current();
197   } else {
198     xbt_die("This task is still being used somewhere else. You cannot send it now. Go fix your code!"
199              "(use --cfg=msg/debug-multiple-use:on to get the backtrace of the other process)");
200   }
201 }
202 } // namespace msg
203 } // namespace simgrid
204
205 /********************************* Task **************************************/
206 /** @brief Creates a new task
207  *
208  * A constructor for msg_task_t taking four arguments.
209  *
210  * @param name a name for the object. It is for user-level information and can be nullptr.
211  * @param flop_amount a value of the processing amount (in flop) needed to process this new task.
212  * If 0, then it cannot be executed with MSG_task_execute(). This value has to be >=0.
213  * @param message_size a value of the amount of data (in bytes) needed to transfer this new task. If 0, then it cannot
214  * be transfered with MSG_task_send() and MSG_task_recv(). This value has to be >=0.
215  * @param data a pointer to any data may want to attach to the new object.  It is for user-level information and can
216  * be nullptr. It can be retrieved with the function @ref MSG_task_get_data.
217  * @return The new corresponding object.
218  */
219 msg_task_t MSG_task_create(const char *name, double flop_amount, double message_size, void *data)
220 {
221   return simgrid::msg::Task::create(name ? std::string(name) : "", flop_amount, message_size, data);
222 }
223
224 /** @brief Creates a new parallel task
225  *
226  * A constructor for #msg_task_t taking six arguments.
227  *
228  * \rst
229  * See :cpp:func:`void simgrid::s4u::this_actor::parallel_execute(int, s4u::Host**, double*, double*)` for
230  * the exact semantic of the parameters.
231  * \endrst
232  *
233  * @param name a name for the object. It is for user-level information and can be nullptr.
234  * @param host_nb the number of hosts implied in the parallel task.
235  * @param host_list an array of @p host_nb msg_host_t.
236  * @param flops_amount an array of @p host_nb doubles.
237  *        flops_amount[i] is the total number of operations that have to be performed on host_list[i].
238  * @param bytes_amount an array of @p host_nb* @p host_nb doubles.
239  * @param data a pointer to any data may want to attach to the new object.
240  *             It is for user-level information and can be nullptr.
241  *             It can be retrieved with the function @ref MSG_task_get_data().
242  */
243 msg_task_t MSG_parallel_task_create(const char *name, int host_nb, const msg_host_t * host_list,
244                                     double *flops_amount, double *bytes_amount, void *data)
245 {
246   // Task's flops amount is set to an arbitrary value > 0.0 to be able to distinguish, in
247   // MSG_task_get_remaining_work_ratio(), a finished task and a task that has not started yet.
248   return simgrid::msg::Task::create_parallel(name ? name : "", host_nb, host_list, flops_amount, bytes_amount, data);
249 }
250
251 /** @brief Return the user data of the given task */
252 void* MSG_task_get_data(msg_task_t task)
253 {
254   return task->get_user_data();
255 }
256
257 /** @brief Sets the user data of a given task */
258 void MSG_task_set_data(msg_task_t task, void *data)
259 {
260   task->set_user_data(data);
261 }
262
263 /** @brief Sets a function to be called when a task has just been copied.
264  * @param callback a callback function
265  */
266 void MSG_task_set_copy_callback(void (*callback) (msg_task_t task, msg_process_t sender, msg_process_t receiver)) {
267
268   msg_global->task_copy_callback = callback;
269
270   if (callback) {
271     SIMIX_comm_set_copy_data_callback(MSG_comm_copy_data_from_SIMIX);
272   } else {
273     SIMIX_comm_set_copy_data_callback(SIMIX_comm_copy_pointer_callback);
274   }
275 }
276
277 /** @brief Returns the sender of the given task */
278 msg_process_t MSG_task_get_sender(msg_task_t task)
279 {
280   return task->get_sender();
281 }
282
283 /** @brief Returns the source (the sender's host) of the given task */
284 msg_host_t MSG_task_get_source(msg_task_t task)
285 {
286   return task->get_source();
287 }
288
289 /** @brief Returns the name of the given task. */
290 const char *MSG_task_get_name(msg_task_t task)
291 {
292   return task->get_cname();
293 }
294
295 /** @brief Sets the name of the given task. */
296 void MSG_task_set_name(msg_task_t task, const char *name)
297 {
298   task->set_name(name);
299 }
300
301 /**
302  * @brief Executes a task and waits for its termination.
303  *
304  * This function is used for describing the behavior of a process. It takes only one parameter.
305  * @param task a #msg_task_t to execute on the location on which the process is running.
306  * @return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED or #MSG_HOST_FAILURE otherwise
307  */
308 msg_error_t MSG_task_execute(msg_task_t task)
309 {
310   return task->execute();
311 }
312
313 /**
314  * @brief Executes a parallel task and waits for its termination.
315  *
316  * @param task a #msg_task_t to execute on the location on which the process is running.
317  *
318  * @return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED or #MSG_HOST_FAILURE otherwise
319  */
320 msg_error_t MSG_parallel_task_execute(msg_task_t task)
321 {
322   return task->execute();
323 }
324
325 msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeout)
326 {
327   task->set_timeout(timeout);
328   return task->execute();
329 }
330
331 /**
332  * @brief Sends a task on a mailbox.
333  *
334  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
335  *
336  * @param task a #msg_task_t to send on another location.
337  * @param alias name of the mailbox to sent the task to
338  * @return the msg_comm_t communication created
339  */
340 msg_comm_t MSG_task_isend(msg_task_t task, const char* alias)
341 {
342   return new simgrid::msg::Comm(task, nullptr, task->send_async(alias, nullptr, false));
343 }
344
345 /**
346  * @brief Sends a task on a mailbox with a maximum rate
347  *
348  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication. The maxrate
349  * parameter allows the application to limit the bandwidth utilization of network links when sending the task.
350  *
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 maxrate the maximum communication rate for sending this task (byte/sec).
354  * @return the msg_comm_t communication created
355  */
356 msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char* alias, double maxrate)
357 {
358   task->set_rate(maxrate);
359   return new simgrid::msg::Comm(task, nullptr, task->send_async(alias, nullptr, false));
360 }
361
362 /**
363  * @brief Sends a task on a mailbox.
364  *
365  * This is a non blocking detached send function.
366  * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
367  * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
368  * usual. More details on this can be obtained on
369  * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
370  * in the SimGrid-user mailing list archive.
371  *
372  * @param task a #msg_task_t to send on another location.
373  * @param alias name of the mailbox to sent the task to
374  * @param cleanup a function to destroy the task if the communication fails, e.g. MSG_task_destroy
375  * (if nullptr, no function will be called)
376  */
377 void MSG_task_dsend(msg_task_t task, const char* alias, void_f_pvoid_t cleanup)
378 {
379   task->send_async(alias, cleanup, true);
380 }
381
382 /**
383  * @brief Sends a task on a mailbox with a maximal rate.
384  *
385  * This is a non blocking detached send function.
386  * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
387  * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
388  * usual. More details on this can be obtained on
389  * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
390  * in the SimGrid-user mailing list archive.
391  *
392  * The rate parameter can be used to send a task with a limited bandwidth (smaller than the physical available value).
393  * Use MSG_task_dsend() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
394  *
395  * @param task a #msg_task_t to send on another location.
396  * @param alias name of the mailbox to sent the task to
397  * @param cleanup a function to destroy the task if the communication fails, e.g. MSG_task_destroy (if nullptr, no
398  *        function will be called)
399  * @param maxrate the maximum communication rate for sending this task (byte/sec)
400  *
401  */
402 void MSG_task_dsend_bounded(msg_task_t task, const char* alias, void_f_pvoid_t cleanup, double maxrate)
403 {
404   task->set_rate(maxrate);
405   task->send_async(alias, cleanup, true);
406 }
407 /**
408  * @brief Sends a task to a mailbox
409  *
410  * This is a blocking function, the execution flow will be blocked until the task is sent (and received on the other
411  * side if #MSG_task_receive is used).
412  * See #MSG_task_isend for sending tasks asynchronously.
413  *
414  * @param task the task to be sent
415  * @param alias the mailbox name to where the task is sent
416  *
417  * @return Returns #MSG_OK if the task was successfully sent,
418  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
419  */
420 msg_error_t MSG_task_send(msg_task_t task, const char* alias)
421 {
422   XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
423   return task->send(alias, -1);
424 }
425
426 /**
427  * @brief Sends a task to a mailbox with a maximum rate
428  *
429  * This is a blocking function, the execution flow will be blocked until the task is sent. The maxrate parameter allows
430  * the application to limit the bandwidth utilization of network links when sending the task.
431  *
432  * The maxrate parameter can be used to send a task with a limited bandwidth (smaller than the physical available
433  * value). Use MSG_task_send() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
434  *
435  * @param task the task to be sent
436  * @param alias the mailbox name to where the task is sent
437  * @param maxrate the maximum communication rate for sending this task (byte/sec)
438  *
439  * @return Returns #MSG_OK if the task was successfully sent,
440  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
441  */
442 msg_error_t MSG_task_send_bounded(msg_task_t task, const char* alias, double maxrate)
443 {
444   task->set_rate(maxrate);
445   return task->send(alias, -1);
446 }
447
448 /**
449  * @brief Sends a task to a mailbox with a timeout
450  *
451  * This is a blocking function, the execution flow will be blocked until the task is sent or the timeout is achieved.
452  *
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  *
457  * @return Returns #MSG_OK if the task was successfully sent,
458  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
459  */
460 msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char* alias, double timeout)
461 {
462   return task->send(alias, timeout);
463 }
464
465 /**
466  * @brief Sends a task to a mailbox with a timeout and with a maximum rate
467  *
468  * This is a blocking function, the execution flow will be blocked until the task is sent or the timeout is achieved.
469  *
470  * The maxrate parameter can be used to send a task with a limited bandwidth (smaller than the physical available
471  * value). Use MSG_task_send_with_timeout() if you don't limit the rate (or pass -1 as a rate value do disable this
472  * feature).
473  *
474  * @param task the task to be sent
475  * @param alias the mailbox name to where the task is sent
476  * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
477  * @param maxrate the maximum communication rate for sending this task (byte/sec)
478  *
479  * @return Returns #MSG_OK if the task was successfully sent,
480  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
481  */
482 msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char* alias, double timeout, double maxrate)
483 {
484   task->set_rate(maxrate);
485   return task->send(alias, timeout);
486 }
487
488 /** @brief Destroys the given task.
489  *
490  * You should free user data, if any, @b before calling this destructor.
491  *
492  * Only the process that owns the task can destroy it.
493  * The owner changes after a successful send.
494  * If a task is successfully sent, the receiver becomes the owner and is supposed to destroy it. The sender should not
495  * use it anymore.
496  * If the task failed to be sent, the sender remains the owner of the task.
497  */
498 msg_error_t MSG_task_destroy(msg_task_t task)
499 {
500   if (task->is_used()) {
501     /* the task is being sent or executed: cancel it first */
502     task->cancel();
503   }
504
505   /* free main structures */
506   delete task;
507
508   return MSG_OK;
509 }
510
511 /** @brief Cancel the given task
512  *
513  * If it was currently executed or transfered, the working process is stopped.
514  */
515 msg_error_t MSG_task_cancel(msg_task_t task)
516 {
517   xbt_assert((task != nullptr), "Cannot cancel a nullptr task");
518   task->cancel();
519   return MSG_OK;
520 }
521
522 /** @brief Returns a value in ]0,1[ that represent the task remaining work
523  *    to do: starts at 1 and goes to 0. Returns 0 if not started or finished.
524  *
525  * It works for either parallel or sequential tasks.
526  */
527 double MSG_task_get_remaining_work_ratio(msg_task_t task) {
528
529   xbt_assert((task != nullptr), "Cannot get information from a nullptr task");
530   if (task->compute) {
531     // Task in progress
532     return task->compute->get_remaining_ratio();
533   } else {
534     // Task not started (flops_amount is > 0.0) or finished (flops_amount is set to 0.0)
535     return task->flops_amount > 0.0 ? 1.0 : 0.0;
536   }
537 }
538
539 /** @brief Returns the amount of flops that remain to be computed
540  *
541  * The returned value is initially the cost that you defined for the task, then it decreases until it reaches 0
542  *
543  * It works for sequential tasks, but the remaining amount of work is not a scalar value for parallel tasks.
544  * So you will get an exception if you call this function on parallel tasks. Just don't do it.
545  */
546 double MSG_task_get_flops_amount(msg_task_t task) {
547   if (task->compute != nullptr) {
548     return task->compute->get_remaining();
549   } else {
550     // Not started or already done.
551     // - Before starting, flops_amount is initially the task cost
552     // - After execution, flops_amount is set to 0 (until someone uses MSG_task_set_flops_amount, if any)
553     return task->flops_amount;
554   }
555 }
556
557 /** @brief set the computation amount needed to process the given task.
558  *
559  * @warning If the computation is ongoing (already started and not finished),
560  * it is not modified by this call. Moreover, after its completion, the ongoing execution with set the flops_amount to
561  * zero, overriding any value set during the execution.
562  */
563 void MSG_task_set_flops_amount(msg_task_t task, double flops_amount)
564 {
565   task->flops_amount = flops_amount;
566 }
567
568 /** @brief set the amount data attached with the given task.
569  *
570  * @warning If the transfer is ongoing (already started and not finished), it is not modified by this call.
571  */
572 void MSG_task_set_bytes_amount(msg_task_t task, double data_size)
573 {
574   task->bytes_amount = data_size;
575 }
576
577 /** @brief Returns the total amount received by the given task
578  *
579  *  If the communication does not exist it will return 0.
580  *  So, if the communication has FINISHED or FAILED it returns zero.
581  */
582 double MSG_task_get_remaining_communication(msg_task_t task)
583 {
584   XBT_DEBUG("calling simcall_communication_get_remains(%p)", task->comm.get());
585   return task->comm->get_remaining();
586 }
587
588 /** @brief Returns the size of the data attached to the given task. */
589 double MSG_task_get_bytes_amount(msg_task_t task)
590 {
591   xbt_assert(task != nullptr, "Invalid parameter");
592   return task->bytes_amount;
593 }
594
595 /** @brief Changes the priority of a computation task.
596  *
597  * This priority doesn't affect the transfer rate. A priority of 2
598  * will make a task receive two times more cpu power than regular tasks.
599  */
600 void MSG_task_set_priority(msg_task_t task, double priority)
601 {
602   task->set_priority(priority);
603 }
604
605 /** @brief Changes the maximum CPU utilization of a computation task (in flops/s).
606  *
607  * For VMs, there is a pitfall. Please see MSG_vm_set_bound().
608  */
609 void MSG_task_set_bound(msg_task_t task, double bound)
610 {
611   if (bound < 1e-12) /* close enough to 0 without any floating precision surprise */
612     XBT_INFO("bound == 0 means no capping (i.e., unlimited).");
613   task->set_bound(bound);
614 }
615
616 /**
617  * @brief Sets the tracing category of a task.
618  *
619  * This function should be called after the creation of a MSG task, to define the category of that task. The
620  * first parameter task must contain a task that was  =created with the function #MSG_task_create. The second
621  * parameter category must contain a category that was previously declared with the function #TRACE_category
622  * (or with #TRACE_category_with_color).
623  *
624  * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
625  *
626  * @param task the task that is going to be categorized
627  * @param category the name of the category to be associated to the task
628  *
629  * @see MSG_task_get_category, TRACE_category, TRACE_category_with_color
630  */
631 void MSG_task_set_category(msg_task_t task, const char* category)
632 {
633   xbt_assert(not task->has_tracing_category(), "Task %p(%s) already has a category (%s).", task, task->get_cname(),
634              task->get_tracing_category().c_str());
635
636   // if user provides a nullptr category, task is no longer traced
637   if (category == nullptr) {
638     task->set_tracing_category("");
639     XBT_DEBUG("MSG task %p(%s), category removed", task, task->get_cname());
640   } else {
641     // set task category
642     task->set_tracing_category(category);
643     XBT_DEBUG("MSG task %p(%s), category %s", task, task->get_cname(), task->get_tracing_category().c_str());
644   }
645 }
646
647 /**
648  * @brief Gets the current tracing category of a task. (@see MSG_task_set_category)
649  * @param task the task to be considered
650  * @return Returns the name of the tracing category of the given task, "" otherwise
651  */
652 const char* MSG_task_get_category(msg_task_t task)
653 {
654   return task->get_tracing_category().c_str();
655 }