Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
apply agier fixes for StarPU build
[simgrid.git] / src / msg / msg_gos.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 <cmath>
7
8 #include "simgrid/Exception.hpp"
9 #include "simgrid/s4u/Comm.hpp"
10 #include "simgrid/s4u/Mailbox.hpp"
11 #include "src/instr/instr_private.hpp"
12 #include "src/kernel/activity/ExecImpl.hpp"
13 #include "src/msg/msg_private.hpp"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg, "Logging specific to MSG (gos)");
16
17 /**
18  * @brief Executes a parallel task and waits for its termination.
19  *
20  * @param task a #msg_task_t to execute on the location on which the process is running.
21  *
22  * @return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED or #MSG_HOST_FAILURE otherwise
23  */
24 msg_error_t MSG_parallel_task_execute(msg_task_t task)
25 {
26   return MSG_parallel_task_execute_with_timeout(task, -1);
27 }
28
29 msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeout)
30 {
31   e_smx_state_t comp_state;
32   msg_error_t status = MSG_OK;
33
34   xbt_assert((not task->compute) && not task->is_used(), "This task is executed somewhere else. Go fix your code!");
35
36   XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
37
38   if (TRACE_actor_is_enabled())
39     simgrid::instr::Container::by_name(instr_pid(MSG_process_self()))->get_state("ACTOR_STATE")->push_event("execute");
40
41   try {
42     task->set_used();
43
44     task->compute = boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(simcall_execution_parallel_start(
45         std::move(task->get_name()), task->hosts_.size(), task->hosts_.data(),
46         (task->flops_parallel_amount.empty() ? nullptr : task->flops_parallel_amount.data()),
47         (task->bytes_parallel_amount.empty() ? nullptr : task->bytes_parallel_amount.data()), -1.0, timeout));
48     XBT_DEBUG("Parallel execution action created: %p", task->compute.get());
49     if (task->has_tracing_category())
50       simgrid::simix::simcall([task] { task->compute->set_category(std::move(task->get_tracing_category())); });
51
52     comp_state = simcall_execution_wait(task->compute);
53
54     task->set_not_used();
55
56     XBT_DEBUG("Execution task '%s' finished in state %d", task->get_cname(), (int)comp_state);
57   } catch (simgrid::HostFailureException& e) {
58     status = MSG_HOST_FAILURE;
59   } catch (simgrid::TimeoutError& e) {
60     status = MSG_TIMEOUT;
61   } catch (simgrid::CancelException& e) {
62     status = MSG_TASK_CANCELED;
63   }
64
65   /* action ended, set comm and compute = nullptr, the actions is already destroyed in the main function */
66   task->flops_amount = 0.0;
67   task->comm         = nullptr;
68   task->compute      = nullptr;
69
70   if (TRACE_actor_is_enabled())
71     simgrid::instr::Container::by_name(instr_pid(MSG_process_self()))->get_state("ACTOR_STATE")->pop_event();
72
73   return status;
74 }
75
76 /**
77  * @brief Receives a task from a mailbox.
78  *
79  * This is a blocking function, the execution flow will be blocked until the task is received. See #MSG_task_irecv
80  * for receiving tasks asynchronously.
81  *
82  * @param task a memory location for storing a #msg_task_t.
83  * @param alias name of the mailbox to receive the task from
84  *
85  * @return Returns
86  * #MSG_OK if the task was successfully received,
87  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
88  */
89 msg_error_t MSG_task_receive(msg_task_t * task, const char *alias)
90 {
91   return MSG_task_receive_with_timeout(task, alias, -1);
92 }
93
94 /**
95  * @brief Receives a task from a mailbox at a given rate.
96  *
97  * @param task a memory location for storing a #msg_task_t.
98  * @param alias name of the mailbox to receive the task from
99  * @param rate limit the reception to rate bandwidth (byte/sec)
100  *
101  * The rate parameter can be used to receive a task with a limited bandwidth (smaller than the physical available
102  * value). Use MSG_task_receive() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
103  *
104  * @return Returns
105  * #MSG_OK if the task was successfully received,
106  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
107  */
108 msg_error_t MSG_task_receive_bounded(msg_task_t * task, const char *alias, double rate)
109 {
110   return MSG_task_receive_with_timeout_bounded(task, alias, -1, rate);
111 }
112
113 /**
114  * @brief Receives a task from a mailbox with a given timeout.
115  *
116  * This is a blocking function with a timeout, the execution flow will be blocked until the task is received or the
117  * timeout is achieved. See #MSG_task_irecv for receiving tasks asynchronously.  You can provide a -1 timeout
118  * to obtain an infinite timeout.
119  *
120  * @param task a memory location for storing a #msg_task_t.
121  * @param alias name of the mailbox to receive the task from
122  * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
123  *
124  * @return Returns
125  * #MSG_OK if the task was successfully received,
126  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
127  */
128 msg_error_t MSG_task_receive_with_timeout(msg_task_t * task, const char *alias, double timeout)
129 {
130   return MSG_task_receive_ext(task, alias, timeout, nullptr);
131 }
132
133 /**
134  * @brief Receives a task from a mailbox with a given timeout and at a given rate.
135  *
136  * @param task a memory location for storing a #msg_task_t.
137  * @param alias name of the mailbox to receive the task from
138  * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
139  * @param rate limit the reception to rate bandwidth (byte/sec)
140  *
141  * The rate parameter can be used to send a task with a limited
142  * bandwidth (smaller than the physical available value). Use
143  * MSG_task_receive() if you don't limit the rate (or pass -1 as a
144  * rate value do disable this feature).
145  *
146  * @return Returns
147  * #MSG_OK if the task was successfully received,
148  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
149  */
150 msg_error_t MSG_task_receive_with_timeout_bounded(msg_task_t* task, const char* alias, double timeout, double rate)
151 {
152   return MSG_task_receive_ext_bounded(task, alias, timeout, nullptr, rate);
153 }
154
155 /**
156  * @brief Receives a task from a mailbox from a specific host with a given timeout.
157  *
158  * This is a blocking function with a timeout, the execution flow will be blocked until the task is received or the
159  * timeout is achieved. See #MSG_task_irecv for receiving tasks asynchronously. You can provide a -1 timeout
160  * to obtain an infinite timeout.
161  *
162  * @param task a memory location for storing a #msg_task_t.
163  * @param alias name of the mailbox to receive the task from
164  * @param timeout is the maximum wait time for completion (provide -1 for no timeout)
165  * @param host a #msg_host_t host from where the task was sent
166  *
167  * @return Returns
168  * #MSG_OK if the task was successfully received,
169  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
170  */
171 msg_error_t MSG_task_receive_ext(msg_task_t * task, const char *alias, double timeout, msg_host_t host)
172 {
173   XBT_DEBUG("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'", alias);
174   return MSG_task_receive_ext_bounded(task, alias, timeout, host, -1.0);
175 }
176
177 /**
178  * @brief Receives a task from a mailbox from a specific host with a given timeout  and at a given rate.
179  *
180  * @param task a memory location for storing a #msg_task_t.
181  * @param alias name of the mailbox to receive the task from
182  * @param timeout is the maximum wait time for completion (provide -1 for no timeout)
183  * @param host a #msg_host_t host from where the task was sent
184  * @param rate limit the reception to rate bandwidth (byte/sec)
185  *
186  * The rate parameter can be used to receive a task with a limited bandwidth (smaller than the physical available
187  * value). Use MSG_task_receive_ext() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
188  *
189  * @return Returns
190  * #MSG_OK if the task was successfully received,
191  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
192  */
193 msg_error_t MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, double timeout, msg_host_t host,
194                                          double rate)
195 {
196   XBT_DEBUG("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'", alias);
197   msg_error_t ret = MSG_OK;
198   /* We no longer support getting a task from a specific host */
199   if (host)
200     THROW_UNIMPLEMENTED;
201
202   /* Sanity check */
203   xbt_assert(task, "Null pointer for the task storage");
204
205   if (*task)
206     XBT_WARN("Asked to write the received task in a non empty struct -- proceeding.");
207
208   /* Try to receive it by calling SIMIX network layer */
209   try {
210     void* payload;
211     simgrid::s4u::Mailbox::by_name(alias)
212         ->get_init()
213         ->set_dst_data(&payload, sizeof(msg_task_t*))
214         ->set_rate(rate)
215         ->wait_for(timeout);
216     *task = static_cast<msg_task_t>(payload);
217     XBT_DEBUG("Got task %s from %s", (*task)->get_cname(), alias);
218     (*task)->set_not_used();
219   } catch (simgrid::HostFailureException& e) {
220     ret = MSG_HOST_FAILURE;
221   } catch (simgrid::TimeoutError& e) {
222     ret = MSG_TIMEOUT;
223   } catch (simgrid::CancelException& e) {
224     ret = MSG_TASK_CANCELED;
225   } catch (xbt_ex& e) {
226     if (e.category == network_error)
227       ret = MSG_TRANSFER_FAILURE;
228     else
229       throw;
230   }
231
232   if (TRACE_actor_is_enabled() && ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) {
233     container_t process_container = simgrid::instr::Container::by_name(instr_pid(MSG_process_self()));
234
235     std::string key = std::string("p") + std::to_string((*task)->get_id());
236     simgrid::instr::Container::get_root()->get_link("ACTOR_TASK_LINK")->end_event(process_container, "SR", key);
237   }
238   return ret;
239 }
240
241
242 /**
243  * @brief Starts listening for receiving a task from an asynchronous communication.
244  *
245  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
246  *
247  * @param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
248  * @param name of the mailbox to receive the task on
249  * @return the msg_comm_t communication created
250  */
251 msg_comm_t MSG_task_irecv(msg_task_t *task, const char *name)
252 {
253   return MSG_task_irecv_bounded(task, name, -1.0);
254 }
255
256 /**
257  * @brief Starts listening for receiving a task from an asynchronous communication at a given rate.
258  *
259  * The rate parameter can be used to receive a task with a limited
260  * bandwidth (smaller than the physical available value). Use
261  * MSG_task_irecv() if you don't limit the rate (or pass -1 as a rate
262  * value do disable this feature).
263  *
264  * @param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
265  * @param name of the mailbox to receive the task on
266  * @param rate limit the bandwidth to the given rate (byte/sec)
267  * @return the msg_comm_t communication created
268  */
269 msg_comm_t MSG_task_irecv_bounded(msg_task_t *task, const char *name, double rate)
270 {
271   simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::by_name(name);
272
273   /* FIXME: these functions are not traceable */
274   /* Sanity check */
275   xbt_assert(task, "Null pointer for the task storage");
276
277   if (*task)
278     XBT_CRITICAL("MSG_task_irecv() was asked to write in a non empty task struct.");
279
280   /* Try to receive it by calling SIMIX network layer */
281   simgrid::s4u::CommPtr comm = simgrid::s4u::Mailbox::by_name(name)
282                                    ->get_init()
283                                    ->set_dst_data((void**)task, sizeof(msg_task_t*))
284                                    ->set_rate(rate)
285                                    ->start();
286
287   return new simgrid::msg::Comm(nullptr, task, comm);
288 }
289
290 /**
291  * @brief Checks whether a communication is done, and if yes, finalizes it.
292  * @param comm the communication to test
293  * @return 'true' if the communication is finished
294  * (but it may have failed, use MSG_comm_get_status() to know its status)
295  * or 'false' if the communication is not finished yet
296  * If the status is 'false', don't forget to use MSG_process_sleep() after the test.
297  */
298 int MSG_comm_test(msg_comm_t comm)
299 {
300   bool finished = false;
301
302   try {
303     finished = comm->s_comm->test();
304     if (finished && comm->task_received != nullptr) {
305       /* I am the receiver */
306       (*comm->task_received)->set_not_used();
307     }
308   } catch (simgrid::TimeoutError& e) {
309     comm->status = MSG_TIMEOUT;
310     finished     = true;
311   } catch (simgrid::CancelException& e) {
312     comm->status = MSG_TASK_CANCELED;
313     finished     = true;
314   }
315   catch (xbt_ex& e) {
316     if (e.category == network_error) {
317       comm->status = MSG_TRANSFER_FAILURE;
318       finished     = true;
319     } else {
320       throw;
321     }
322   }
323
324   return finished;
325 }
326
327 /**
328  * @brief This function checks if a communication is finished.
329  * @param comms a vector of communications
330  * @return the position of the finished communication if any
331  * (but it may have failed, use MSG_comm_get_status() to know its status), or -1 if none is finished
332  */
333 int MSG_comm_testany(xbt_dynar_t comms)
334 {
335   int finished_index = -1;
336
337   /* Create the equivalent array with SIMIX objects: */
338   std::vector<simgrid::kernel::activity::CommImpl*> s_comms;
339   s_comms.reserve(xbt_dynar_length(comms));
340   msg_comm_t comm;
341   unsigned int cursor;
342   xbt_dynar_foreach(comms, cursor, comm) {
343     s_comms.push_back(static_cast<simgrid::kernel::activity::CommImpl*>(comm->s_comm->get_impl().get()));
344   }
345
346   msg_error_t status = MSG_OK;
347   try {
348     finished_index = simcall_comm_testany(s_comms.data(), s_comms.size());
349   } catch (simgrid::TimeoutError& e) {
350     finished_index = e.value;
351     status         = MSG_TIMEOUT;
352   } catch (simgrid::CancelException& e) {
353     finished_index = e.value;
354     status         = MSG_TASK_CANCELED;
355   }
356   catch (xbt_ex& e) {
357     if (e.category != network_error)
358       throw;
359     finished_index = e.value;
360     status         = MSG_TRANSFER_FAILURE;
361   }
362
363   if (finished_index != -1) {
364     comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
365     /* the communication is finished */
366     comm->status = status;
367
368     if (status == MSG_OK && comm->task_received != nullptr) {
369       /* I am the receiver */
370       (*comm->task_received)->set_not_used();
371     }
372   }
373
374   return finished_index;
375 }
376
377 /** @brief Destroys the provided communication. */
378 void MSG_comm_destroy(msg_comm_t comm)
379 {
380   delete comm;
381 }
382
383 /** @brief Wait for the completion of a communication.
384  *
385  * It takes two parameters.
386  * @param comm the communication to wait.
387  * @param timeout Wait until the communication terminates or the timeout occurs.
388  *                You can provide a -1 timeout to obtain an infinite timeout.
389  * @return msg_error_t
390  */
391 msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
392 {
393   try {
394     comm->s_comm->wait_for(timeout);
395
396     if (comm->task_received != nullptr) {
397       /* I am the receiver */
398       (*comm->task_received)->set_not_used();
399     }
400
401     /* FIXME: these functions are not traceable */
402   } catch (simgrid::TimeoutError& e) {
403     comm->status = MSG_TIMEOUT;
404   } catch (simgrid::CancelException& e) {
405     comm->status = MSG_TASK_CANCELED;
406   }
407   catch (xbt_ex& e) {
408     if (e.category == network_error)
409       comm->status = MSG_TRANSFER_FAILURE;
410     else
411       throw;
412   }
413
414   return comm->status;
415 }
416
417 /** @brief This function is called by a sender and permit to wait for each communication
418  *
419  * @param comm a vector of communication
420  * @param nb_elem is the size of the comm vector
421  * @param timeout for each call of MSG_comm_wait
422  */
423 void MSG_comm_waitall(msg_comm_t * comm, int nb_elem, double timeout)
424 {
425   for (int i = 0; i < nb_elem; i++)
426     MSG_comm_wait(comm[i], timeout);
427 }
428
429 /** @brief This function waits for the first communication finished in a list.
430  * @param comms a vector of communications
431  * @return the position of the first finished communication
432  * (but it may have failed, use MSG_comm_get_status() to know its status)
433  */
434 int MSG_comm_waitany(xbt_dynar_t comms)
435 {
436   int finished_index = -1;
437
438   /* Create the equivalent array with SIMIX objects: */
439   std::vector<simgrid::kernel::activity::CommImpl*> s_comms;
440   s_comms.reserve(xbt_dynar_length(comms));
441   msg_comm_t comm;
442   unsigned int cursor;
443   xbt_dynar_foreach(comms, cursor, comm) {
444     s_comms.push_back(static_cast<simgrid::kernel::activity::CommImpl*>(comm->s_comm->get_impl().get()));
445   }
446
447   msg_error_t status = MSG_OK;
448   try {
449     finished_index = simcall_comm_waitany(s_comms.data(), s_comms.size(), -1);
450   } catch (simgrid::TimeoutError& e) {
451     finished_index = e.value;
452     status         = MSG_TIMEOUT;
453   } catch (simgrid::CancelException& e) {
454     finished_index = e.value;
455     status         = MSG_TASK_CANCELED;
456   }
457   catch(xbt_ex& e) {
458     if (e.category == network_error) {
459       finished_index = e.value;
460       status         = MSG_TRANSFER_FAILURE;
461     } else {
462       throw;
463     }
464   }
465
466   xbt_assert(finished_index != -1, "WaitAny returned -1");
467
468   comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
469   /* the communication is finished */
470   comm->status = status;
471
472   if (comm->task_received != nullptr) {
473     /* I am the receiver */
474     (*comm->task_received)->set_not_used();
475   }
476
477   return finished_index;
478 }
479
480 /**
481  * @brief Returns the error (if any) that occurred during a finished communication.
482  * @param comm a finished communication
483  * @return the status of the communication, or #MSG_OK if no error occurred during the communication
484  */
485 msg_error_t MSG_comm_get_status(msg_comm_t comm) {
486
487   return comm->status;
488 }
489
490 /** @brief Get a task (#msg_task_t) from a communication
491  *
492  * @param comm the communication where to get the task
493  * @return the task from the communication
494  */
495 msg_task_t MSG_comm_get_task(msg_comm_t comm)
496 {
497   xbt_assert(comm, "Invalid parameter");
498
499   return comm->task_received ? *comm->task_received : comm->task_sent;
500 }
501
502 /**
503  * @brief This function is called by SIMIX in kernel mode to copy the data of a comm.
504  * @param comm the comm
505  * @param buff the data copied
506  * @param buff_size size of the buffer
507  */
508 void MSG_comm_copy_data_from_SIMIX(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
509 {
510   SIMIX_comm_copy_pointer_callback(comm, buff, buff_size);
511
512   // notify the user callback if any
513   if (msg_global->task_copy_callback) {
514     msg_task_t task = static_cast<msg_task_t>(buff);
515     msg_global->task_copy_callback(task, comm->src_actor_->ciface(), comm->dst_actor_->ciface());
516   }
517 }
518
519 /**
520  * @brief Sends a task to a mailbox
521  *
522  * This is a blocking function, the execution flow will be blocked until the task is sent (and received on the other
523  * side if #MSG_task_receive is used).
524  * See #MSG_task_isend for sending tasks asynchronously.
525  *
526  * @param task the task to be sent
527  * @param alias the mailbox name to where the task is sent
528  *
529  * @return Returns #MSG_OK if the task was successfully sent,
530  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
531  */
532 msg_error_t MSG_task_send(msg_task_t task, const char *alias)
533 {
534   XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
535   return MSG_task_send_with_timeout(task, alias, -1);
536 }
537
538 /**
539  * @brief Sends a task to a mailbox with a maximum rate
540  *
541  * This is a blocking function, the execution flow will be blocked until the task is sent. The maxrate parameter allows
542  * the application to limit the bandwidth utilization of network links when sending the task.
543  *
544  * The maxrate parameter can be used to send a task with a limited bandwidth (smaller than the physical available
545  * value). Use MSG_task_send() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
546  *
547  * @param task the task to be sent
548  * @param alias the mailbox name to where the task is sent
549  * @param maxrate the maximum communication rate for sending this task (byte/sec)
550  *
551  * @return Returns #MSG_OK if the task was successfully sent,
552  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
553  */
554 msg_error_t MSG_task_send_bounded(msg_task_t task, const char *alias, double maxrate)
555 {
556   task->set_rate(maxrate);
557   return MSG_task_send(task, alias);
558 }
559
560 /**
561  * @brief Sends a task to a mailbox with a timeout
562  *
563  * This is a blocking function, the execution flow will be blocked until the task is sent or the timeout is achieved.
564  *
565  * @param task the task to be sent
566  * @param alias the mailbox name to where the task is sent
567  * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
568  *
569  * @return Returns #MSG_OK if the task was successfully sent,
570  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
571  */
572 msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, double timeout)
573 {
574   msg_error_t ret = MSG_OK;
575   /* Try to send it */
576   try {
577     simgrid::s4u::CommPtr comm = task->send_async(alias, nullptr, false);
578     task->comm = comm;
579     comm->wait_for(timeout);
580   } catch (simgrid::TimeoutError& e) {
581     ret = MSG_TIMEOUT;
582   } catch (simgrid::CancelException& e) {
583     ret = MSG_HOST_FAILURE;
584   } catch (xbt_ex& e) {
585     if (e.category == network_error)
586       ret = MSG_TRANSFER_FAILURE;
587     else
588       throw;
589
590     /* If the send failed, it is not used anymore */
591     task->set_not_used();
592   }
593
594   return ret;
595 }
596
597 /**
598  * @brief Sends a task to a mailbox with a timeout and with a maximum rate
599  *
600  * This is a blocking function, the execution flow will be blocked until the task is sent or the timeout is achieved.
601  *
602  * The maxrate parameter can be used to send a task with a limited bandwidth (smaller than the physical available
603  * value). Use MSG_task_send_with_timeout() if you don't limit the rate (or pass -1 as a rate value do disable this
604  * feature).
605  *
606  * @param task the task to be sent
607  * @param alias the mailbox name to where the task is sent
608  * @param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
609  * @param maxrate the maximum communication rate for sending this task (byte/sec)
610  *
611  * @return Returns #MSG_OK if the task was successfully sent,
612  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
613  */
614 msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alias, double timeout, double maxrate)
615 {
616   task->set_rate(maxrate);
617   return MSG_task_send_with_timeout(task, alias, timeout);
618 }
619
620 /**
621  * @brief Look if there is a communication on a mailbox and return the PID of the sender process.
622  *
623  * @param alias the name of the mailbox to be considered
624  *
625  * @return Returns the PID of sender process,
626  * -1 if there is no communication in the mailbox.#include <cmath>
627  *
628  */
629 int MSG_task_listen_from(const char *alias)
630 {
631   /* looks inside the rdv directly. Not clean. */
632   simgrid::kernel::activity::CommImplPtr comm = simgrid::s4u::Mailbox::by_name(alias)->front();
633
634   if (comm && comm->src_actor_)
635     return comm->src_actor_->get_pid();
636   else
637     return -1;
638 }