Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / msg / msg_gos.c
1 /* Copyright (c) 2004-2013. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "msg_private.h"
8 #include "msg_mailbox.h"
9 #include "mc/mc.h"
10 #include "xbt/log.h"
11 #include "xbt/sysdep.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg,
14                                 "Logging specific to MSG (gos)");
15
16 /** \ingroup msg_task_usage
17  * \brief Executes a task and waits for its termination.
18  *
19  * This function is used for describing the behavior of a process. It
20  * takes only one parameter.
21  * \param task a #msg_task_t to execute on the location on which the process is running.
22  * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
23  * or #MSG_HOST_FAILURE otherwise
24  */
25 msg_error_t MSG_task_execute(msg_task_t task)
26 {
27   /* TODO: add this to other locations */
28   msg_host_t host = MSG_process_get_host(MSG_process_self());
29   MSG_host_add_task(host, task);
30
31   msg_error_t ret = MSG_parallel_task_execute(task);
32
33   MSG_host_del_task(host, task);
34
35   return ret;
36 }
37
38 /** \ingroup msg_task_usage
39  * \brief Executes a parallel task and waits for its termination.
40  *
41  * \param task a #msg_task_t to execute on the location on which the process is running.
42  *
43  * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
44  * or #MSG_HOST_FAILURE otherwise
45  */
46 msg_error_t MSG_parallel_task_execute(msg_task_t task)
47 {
48   xbt_ex_t e;
49   simdata_task_t simdata = task->simdata;
50   msg_process_t self = SIMIX_process_self();
51   simdata_process_t p_simdata = SIMIX_process_self_get_data(self);
52   e_smx_state_t comp_state;
53   msg_error_t status = MSG_OK;
54
55 #ifdef HAVE_TRACING
56   TRACE_msg_task_execute_start(task);
57 #endif
58
59   xbt_assert((!simdata->compute) && (task->simdata->isused == 0),
60              "This task is executed somewhere else. Go fix your code! %d",
61              task->simdata->isused);
62
63   XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
64
65   if (simdata->computation_amount == 0 && !simdata->host_nb) {
66 #ifdef HAVE_TRACING
67     TRACE_msg_task_execute_end(task);
68 #endif
69     return MSG_OK;
70   }
71
72
73   TRY {
74
75     simdata->isused=1;
76
77     if (simdata->host_nb > 0) {
78       simdata->compute = simcall_host_parallel_execute(task->name,
79                                                        simdata->host_nb,
80                                                        simdata->host_list,
81                                                        simdata->comp_amount,
82                                                        simdata->comm_amount,
83                                                        1.0, -1.0);
84       XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
85     } else {
86       unsigned long affinity_mask = (unsigned long) xbt_dict_get_or_null_ext(simdata->affinity_mask_db, (char *) p_simdata->m_host, sizeof(msg_host_t));
87       XBT_DEBUG("execute %s@%s with affinity(0x%04lx)", MSG_task_get_name(task), MSG_host_get_name(p_simdata->m_host), affinity_mask);
88
89       simdata->compute = simcall_host_execute(task->name,
90                                               p_simdata->m_host,
91                                               simdata->computation_amount,
92                                               simdata->priority,
93                                               simdata->bound,
94                                               affinity_mask
95                                               );
96
97     }
98 #ifdef HAVE_TRACING
99     simcall_set_category(simdata->compute, task->category);
100 #endif
101     p_simdata->waiting_action = simdata->compute;
102     comp_state = simcall_host_execution_wait(simdata->compute);
103
104     p_simdata->waiting_action = NULL;
105
106     simdata->isused=0;
107
108     XBT_DEBUG("Execution task '%s' finished in state %d",
109               task->name, (int)comp_state);
110   }
111   CATCH(e) {
112     switch (e.category) {
113     case cancel_error:
114       status = MSG_TASK_CANCELED;
115       break;
116     case host_error:
117       status = MSG_HOST_FAILURE;
118       break;
119     default:
120       RETHROW;
121     }
122     xbt_ex_free(e);
123   }
124   /* action ended, set comm and compute = NULL, the actions is already destroyed
125    * in the main function */
126   simdata->computation_amount = 0.0;
127   simdata->comm = NULL;
128   simdata->compute = NULL;
129 #ifdef HAVE_TRACING
130   TRACE_msg_task_execute_end(task);
131 #endif
132
133   MSG_RETURN(status);
134 }
135
136
137 /** \ingroup msg_task_usage
138  * \brief Sleep for the specified number of seconds
139  *
140  * Makes the current process sleep until \a time seconds have elapsed.
141  *
142  * \param nb_sec a number of second
143  */
144 msg_error_t MSG_process_sleep(double nb_sec)
145 {
146   xbt_ex_t e;
147   msg_error_t status = MSG_OK;
148   /*msg_process_t proc = MSG_process_self();*/
149
150 #ifdef HAVE_TRACING
151   TRACE_msg_process_sleep_in(MSG_process_self());
152 #endif
153
154   /* create action to sleep */
155
156   /*proc->simdata->waiting_action = act_sleep;
157
158   FIXME: check if not setting the waiting_action breaks something on msg
159   
160   proc->simdata->waiting_action = NULL;*/
161
162   TRY {
163     simcall_process_sleep(nb_sec);
164   }
165   CATCH(e) {
166     switch (e.category) {
167     case cancel_error:
168       status = MSG_TASK_CANCELED;
169       break;
170     default:
171       RETHROW;
172     }
173     xbt_ex_free(e);
174   }
175
176   #ifdef HAVE_TRACING
177     TRACE_msg_process_sleep_out(MSG_process_self());
178   #endif
179   MSG_RETURN(status);
180 }
181
182 /** \ingroup msg_task_usage
183  * \brief Deprecated function that used to receive a task from a mailbox from a specific host.
184  *
185  * Sorry, this function is not supported anymore. That wouldn't be
186  * impossible to reimplement it, but we are lacking the time to do so ourselves.
187  * If you need this functionality, you can either:
188  *
189  *  - implement the buffering mechanism on the user-level by queuing all messages
190  *    received in the mailbox that do not match your expectation
191  *  - change your application logic to leverage the mailboxes features. For example,
192  *    if you have A receiving messages from B and C, you could have A waiting on
193  *    mailbox "A" most of the time, but on "A#B" when it's waiting for specific
194  *    messages from B and "A#C" when waiting for messages from C. You could even get A
195  *    sometime waiting on all these mailboxes using @ref MSG_comm_waitany. You can find
196  *    an example of use of this function in the @ref MSG_examples section.
197  *  - Provide a proper patch to implement this functionality back in MSG. That wouldn't be
198  *    very difficult actually. Check the function @ref MSG_mailbox_get_task_ext. During its call to
199  *    simcall_comm_recv(), the 5th argument, match_fun, is NULL. Create a function that filters
200  *    messages according to the host (that you will pass as sixth argument to simcall_comm_recv()
201  *    and that your filtering function will receive as first parameter, and then, the filter could
202  *    simply compare the host names, for example. After sufficient testing, provide an example that
203  *    we could add to the distribution, and your first contribution to SimGrid is ready. Thanks in advance.
204  *
205  * \param task a memory location for storing a #msg_task_t.
206  * \param alias name of the mailbox to receive the task from
207  * \param host a #msg_host_t host from where the task was sent
208  *
209  * \return Returns
210  * #MSG_OK if the task was successfully received,
211  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
212  */
213 msg_error_t
214 MSG_task_receive_from_host(msg_task_t * task, const char *alias,
215                            msg_host_t host)
216 {
217   return MSG_task_receive_ext(task, alias, -1, host);
218 }
219
220 /** msg_task_usage
221  *\brief Deprecated function that used to receive a task from a mailbox from a specific host
222  *\brief at a given rate
223  *
224  * \param task a memory location for storing a #msg_task_t.
225  * \param alias name of the mailbox to receive the task from
226  * \param host a #msg_host_t host from where the task was sent
227  * \param rate limit the reception to rate bandwidth
228  *
229  * \return Returns
230  * #MSG_OK if the task was successfully received,
231  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
232  */
233 msg_error_t
234 MSG_task_receive_from_host_bounded(msg_task_t * task, const char *alias,
235                            msg_host_t host, double rate)
236 {
237   return MSG_task_receive_ext_bounded(task, alias, -1, host, rate);
238 }
239
240 /** \ingroup msg_task_usage
241  * \brief Receives a task from a mailbox.
242  *
243  * This is a blocking function, the execution flow will be blocked
244  * until the task is received. See #MSG_task_irecv
245  * for receiving tasks asynchronously.
246  *
247  * \param task a memory location for storing a #msg_task_t.
248  * \param alias name of the mailbox to receive the task from
249  *
250  * \return Returns
251  * #MSG_OK if the task was successfully received,
252  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
253  */
254 msg_error_t MSG_task_receive(msg_task_t * task, const char *alias)
255 {
256   return MSG_task_receive_with_timeout(task, alias, -1);
257 }
258
259 /** \ingroup msg_task_usage
260  * \brief Receives a task from a mailbox at a given rate.
261  *
262  * \param task a memory location for storing a #msg_task_t.
263  * \param alias name of the mailbox to receive the task from
264  *  \param rate limit the reception to rate bandwidth
265  *
266  * \return Returns
267  * #MSG_OK if the task was successfully received,
268  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
269  */
270 msg_error_t MSG_task_receive_bounded(msg_task_t * task, const char *alias, double rate)
271 {
272   return MSG_task_receive_with_timeout_bounded(task, alias, -1, rate);
273 }
274
275 /** \ingroup msg_task_usage
276  * \brief Receives a task from a mailbox with a given timeout.
277  *
278  * This is a blocking function with a timeout, the execution flow will be blocked
279  * until the task is received or the timeout is achieved. See #MSG_task_irecv
280  * for receiving tasks asynchronously.  You can provide a -1 timeout
281  * to obtain an infinite timeout.
282  *
283  * \param task a memory location for storing a #msg_task_t.
284  * \param alias name of the mailbox to receive the task from
285  * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
286  *
287  * \return Returns
288  * #MSG_OK if the task was successfully received,
289  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
290  */
291 msg_error_t
292 MSG_task_receive_with_timeout(msg_task_t * task, const char *alias,
293                               double timeout)
294 {
295   return MSG_task_receive_ext(task, alias, timeout, NULL);
296 }
297
298 /** \ingroup msg_task_usage
299  * \brief Receives a task from a mailbox with a given timeout and at a given rate.
300  *
301  * \param task a memory location for storing a #msg_task_t.
302  * \param alias name of the mailbox to receive the task from
303  * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
304  *  \param rate limit the reception to rate bandwidth
305  *
306  * \return Returns
307  * #MSG_OK if the task was successfully received,
308  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
309  */
310 msg_error_t
311 MSG_task_receive_with_timeout_bounded(msg_task_t * task, const char *alias,
312                               double timeout,double rate)
313 {
314   return MSG_task_receive_ext_bounded(task, alias, timeout, NULL,rate);
315 }
316
317 /** \ingroup msg_task_usage
318  * \brief Receives a task from a mailbox from a specific host with a given timeout.
319  *
320  * This is a blocking function with a timeout, the execution flow will be blocked
321  * until the task is received or the timeout is achieved. See #MSG_task_irecv
322  * for receiving tasks asynchronously. You can provide a -1 timeout
323  * to obtain an infinite timeout.
324  *
325  * \param task a memory location for storing a #msg_task_t.
326  * \param alias name of the mailbox to receive the task from
327  * \param timeout is the maximum wait time for completion (provide -1 for no timeout)
328  * \param host a #msg_host_t host from where the task was sent
329  *
330  * \return Returns
331  * #MSG_OK if the task was successfully received,
332 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
333  */
334 msg_error_t
335 MSG_task_receive_ext(msg_task_t * task, const char *alias, double timeout,
336                      msg_host_t host)
337 {
338   xbt_ex_t e;
339   msg_error_t ret = MSG_OK;
340   XBT_DEBUG
341       ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",
342        alias);
343   TRY {
344     ret = MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task,
345                                    host, timeout);
346   }
347   CATCH(e) {
348     switch (e.category) {
349     case cancel_error:          /* may be thrown by MSG_mailbox_get_by_alias */
350       ret = MSG_HOST_FAILURE;
351       break;
352     default:
353       RETHROW;
354     }
355     xbt_ex_free(e);
356   }
357   return ret;
358 }
359
360 /** \ingroup msg_task_usage
361  * \brief Receives a task from a mailbox from a specific host with a given timeout
362  *  and at a given rate.
363  *
364  * \param task a memory location for storing a #msg_task_t.
365  * \param alias name of the mailbox to receive the task from
366  * \param timeout is the maximum wait time for completion (provide -1 for no timeout)
367  * \param host a #msg_host_t host from where the task was sent
368  * \param rate limit the reception to rate bandwidth
369  *
370  * \return Returns
371  * #MSG_OK if the task was successfully received,
372 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
373  */
374 msg_error_t
375 MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, double timeout,
376                      msg_host_t host, double rate)
377 {
378   XBT_DEBUG
379       ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",
380        alias);
381   return MSG_mailbox_get_task_ext_bounded(MSG_mailbox_get_by_alias(alias), task,
382                                   host, timeout, rate);
383 }
384
385 /** \ingroup msg_task_usage
386  * \brief Sends a task on a mailbox.
387  *
388  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
389  * to end the communication.
390  *
391  * \param task a #msg_task_t to send on another location.
392  * \param alias name of the mailbox to sent the task to
393  * \return the msg_comm_t communication created
394  */
395 msg_comm_t MSG_task_isend(msg_task_t task, const char *alias)
396 {
397   return MSG_task_isend_with_matching(task,alias,NULL,NULL);
398 }
399
400 /** \ingroup msg_task_usage
401  * \brief Sends a task on a mailbox with a maximum rate
402  *
403  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
404  * to end the communication. The maxrate parameter allows the application
405  * to limit the bandwidth utilization of network links when sending the task.
406  *
407  * \param task a #msg_task_t to send on another location.
408  * \param alias name of the mailbox to sent the task to
409  * \param maxrate the maximum communication rate for sending this task .
410  * \return the msg_comm_t communication created
411  */
412 msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char *alias, double maxrate)
413 {
414   task->simdata->rate = maxrate;
415   return MSG_task_isend_with_matching(task,alias,NULL,NULL);
416 }
417
418
419 /** \ingroup msg_task_usage
420  * \brief Sends a task on a mailbox, with support for matching requests
421  *
422  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
423  * to end the communication.
424  *
425  * \param task a #msg_task_t to send on another location.
426  * \param alias name of the mailbox to sent the task to
427  * \param match_fun boolean function which parameters are:
428  *        - match_data_provided_here
429  *        - match_data_provided_by_other_side_if_any
430  *        - the_smx_action_describing_the_other_side
431  * \param match_data user provided data passed to match_fun
432  * \return the msg_comm_t communication created
433  */
434 XBT_INLINE msg_comm_t MSG_task_isend_with_matching(msg_task_t task, const char *alias,
435     int (*match_fun)(void*,void*, smx_action_t),
436     void *match_data)
437 {
438   simdata_task_t t_simdata = NULL;
439   msg_process_t process = MSG_process_self();
440   msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
441
442 #ifdef HAVE_TRACING
443   int call_end = TRACE_msg_task_put_start(task);
444 #endif
445
446   /* Prepare the task to send */
447   t_simdata = task->simdata;
448   t_simdata->sender = process;
449   t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
450
451   xbt_assert(t_simdata->isused == 0,
452               "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
453
454   t_simdata->isused = 1;
455   t_simdata->comm = NULL;
456   msg_global->sent_msg++;
457
458   /* Send it by calling SIMIX network layer */
459   msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
460   comm->task_sent = task;
461   comm->task_received = NULL;
462   comm->status = MSG_OK;
463   comm->s_comm =
464     simcall_comm_isend(mailbox, t_simdata->message_size,
465                          t_simdata->rate, task, sizeof(void *), match_fun, NULL, match_data, 0);
466   t_simdata->comm = comm->s_comm; /* FIXME: is the field t_simdata->comm still useful? */
467 #ifdef HAVE_TRACING
468     if (TRACE_is_enabled()) {
469       simcall_set_category(comm->s_comm, task->category);
470     }
471 #endif
472
473 #ifdef HAVE_TRACING
474   if (call_end)
475     TRACE_msg_task_put_end();
476 #endif
477
478   return comm;
479 }
480
481 /** \ingroup msg_task_usage
482  * \brief Sends a task on a mailbox.
483  *
484  * This is a non blocking detached send function.
485  * Think of it as a best effort send. Keep in mind that the third parameter
486  * is only called if the communication fails. If the communication does work,
487  * it is responsibility of the receiver code to free anything related to
488  * the task, as usual. More details on this can be obtained on
489  * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
490  * in the SimGrid-user mailing list archive.
491  *
492  * \param task a #msg_task_t to send on another location.
493  * \param alias name of the mailbox to sent the task to
494  * \param cleanup a function to destroy the task if the
495  * communication fails, e.g. MSG_task_destroy
496  * (if NULL, no function will be called)
497  */
498 void MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup)
499 {
500   simdata_task_t t_simdata = NULL;
501   msg_process_t process = MSG_process_self();
502   msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
503
504   /* Prepare the task to send */
505   t_simdata = task->simdata;
506   t_simdata->sender = process;
507   t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
508
509   xbt_assert(t_simdata->isused == 0,
510               "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
511
512   t_simdata->isused = 1;
513   t_simdata->comm = NULL;
514   msg_global->sent_msg++;
515
516 #ifdef HAVE_TRACING
517   int call_end = TRACE_msg_task_put_start(task);
518 #endif
519
520   /* Send it by calling SIMIX network layer */
521   smx_action_t comm = simcall_comm_isend(mailbox, t_simdata->message_size,
522                        t_simdata->rate, task, sizeof(void *), NULL, cleanup, NULL, 1);
523   t_simdata->comm = comm;
524 #ifdef HAVE_TRACING
525     if (TRACE_is_enabled()) {
526       simcall_set_category(comm, task->category);
527     }
528 #endif
529
530 #ifdef HAVE_TRACING
531   if (call_end)
532     TRACE_msg_task_put_end();
533 #endif
534 }
535
536
537 /** \ingroup msg_task_usage
538  * \brief Sends a task on a mailbox with a maximal rate.
539  *
540  * This is a non blocking detached send function.
541  * Think of it as a best effort send. Keep in mind that the third parameter
542  * is only called if the communication fails. If the communication does work,
543  * it is responsibility of the receiver code to free anything related to
544  * the task, as usual. More details on this can be obtained on
545  * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
546  * in the SimGrid-user mailing list archive.
547  *
548  * \param task a #msg_task_t to send on another location.
549  * \param alias name of the mailbox to sent the task to
550  * \param cleanup a function to destroy the task if the
551  * communication fails, e.g. MSG_task_destroy
552  * (if NULL, no function will be called)
553  * \param maxrate the maximum communication rate for sending this task
554  * 
555  */
556 void MSG_task_dsend_bounded(msg_task_t task, const char *alias, void_f_pvoid_t cleanup, double maxrate)
557 {
558   task->simdata->rate = maxrate;
559   
560   simdata_task_t t_simdata = NULL;
561   msg_process_t process = MSG_process_self();
562   msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
563
564   /* Prepare the task to send */
565   t_simdata = task->simdata;
566   t_simdata->sender = process;
567   t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
568
569   xbt_assert(t_simdata->isused == 0,
570               "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
571
572   t_simdata->isused = 1;
573   t_simdata->comm = NULL;
574   msg_global->sent_msg++;
575
576 #ifdef HAVE_TRACING
577   int call_end = TRACE_msg_task_put_start(task);
578 #endif
579
580   /* Send it by calling SIMIX network layer */
581   smx_action_t comm = simcall_comm_isend(mailbox, t_simdata->message_size,
582                        t_simdata->rate, task, sizeof(void *), NULL, cleanup, NULL, 1);
583   t_simdata->comm = comm;
584 #ifdef HAVE_TRACING
585     if (TRACE_is_enabled()) {
586       simcall_set_category(comm, task->category);
587     }
588 #endif
589
590 #ifdef HAVE_TRACING
591   if (call_end)
592     TRACE_msg_task_put_end();
593 #endif
594 }
595
596 /** \ingroup msg_task_usage
597  * \brief Starts listening for receiving a task from an asynchronous communication.
598  *
599  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
600  * to end the communication.
601  * 
602  * \param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
603  * \param name of the mailbox to receive the task on
604  * \return the msg_comm_t communication created
605  */
606 msg_comm_t MSG_task_irecv(msg_task_t *task, const char *name)
607 {
608   smx_rdv_t rdv = MSG_mailbox_get_by_alias(name);
609
610   /* FIXME: these functions are not traceable */
611
612   /* Sanity check */
613   xbt_assert(task, "Null pointer for the task storage");
614
615   if (*task)
616     XBT_CRITICAL
617         ("MSG_task_irecv() was asked to write in a non empty task struct.");
618
619   /* Try to receive it by calling SIMIX network layer */
620   msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
621   comm->task_sent = NULL;
622   comm->task_received = task;
623   comm->status = MSG_OK;
624   comm->s_comm = simcall_comm_irecv(rdv, task, NULL, NULL, NULL);
625
626   return comm;
627 }
628
629 /** \ingroup msg_task_usage
630  * \brief Starts listening for receiving a task from an asynchronous communication
631  * at a given rate.
632  *
633  * \param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
634  * \param name of the mailbox to receive the task on
635  * \param rate limit the bandwidth to the given rate
636  * \return the msg_comm_t communication created
637  */
638 msg_comm_t MSG_task_irecv_bounded(msg_task_t *task, const char *name, double rate)
639 {
640
641
642   smx_rdv_t rdv = MSG_mailbox_get_by_alias(name);
643
644   /* FIXME: these functions are not traceable */
645
646   /* Sanity check */
647   xbt_assert(task, "Null pointer for the task storage");
648
649   if (*task)
650     XBT_CRITICAL
651         ("MSG_task_irecv() was asked to write in a non empty task struct.");
652
653   /* Try to receive it by calling SIMIX network layer */
654   msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
655   comm->task_sent = NULL;
656   comm->task_received = task;
657   comm->status = MSG_OK;
658   comm->s_comm = simcall_comm_irecv_bounded(rdv, task, NULL, NULL, NULL, rate);
659
660   return comm;
661 }
662
663 /** \ingroup msg_task_usage
664  * \brief Checks whether a communication is done, and if yes, finalizes it.
665  * \param comm the communication to test
666  * \return TRUE if the communication is finished
667  * (but it may have failed, use MSG_comm_get_status() to know its status)
668  * or FALSE if the communication is not finished yet
669  * If the status is FALSE, don't forget to use MSG_process_sleep() after the test.
670  */
671 int MSG_comm_test(msg_comm_t comm)
672 {
673   xbt_ex_t e;
674   int finished = 0;
675
676   TRY {
677     finished = simcall_comm_test(comm->s_comm);
678
679     if (finished && comm->task_received != NULL) {
680       /* I am the receiver */
681       (*comm->task_received)->simdata->isused = 0;
682     }
683   }
684   CATCH(e) {
685     switch (e.category) {
686       case network_error:
687         comm->status = MSG_TRANSFER_FAILURE;
688         finished = 1;
689         break;
690
691       case timeout_error:
692         comm->status = MSG_TIMEOUT;
693         finished = 1;
694         break;
695
696       default:
697         RETHROW;
698     }
699     xbt_ex_free(e);
700   }
701
702   return finished;
703 }
704
705 /** \ingroup msg_task_usage
706  * \brief This function checks if a communication is finished.
707  * \param comms a vector of communications
708  * \return the position of the finished communication if any
709  * (but it may have failed, use MSG_comm_get_status() to know its status),
710  * or -1 if none is finished
711  */
712 int MSG_comm_testany(xbt_dynar_t comms)
713 {
714   xbt_ex_t e;
715   int finished_index = -1;
716
717   /* create the equivalent dynar with SIMIX objects */
718   xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
719   msg_comm_t comm;
720   unsigned int cursor;
721   xbt_dynar_foreach(comms, cursor, comm) {
722     xbt_dynar_push(s_comms, &comm->s_comm);
723   }
724
725   msg_error_t status = MSG_OK;
726   TRY {
727     finished_index = simcall_comm_testany(s_comms);
728   }
729   CATCH(e) {
730     switch (e.category) {
731       case network_error:
732         finished_index = e.value;
733         status = MSG_TRANSFER_FAILURE;
734         break;
735
736       case timeout_error:
737         finished_index = e.value;
738         status = MSG_TIMEOUT;
739         break;
740
741       default:
742         RETHROW;
743     }
744     xbt_ex_free(e);
745   }
746   xbt_dynar_free(&s_comms);
747
748   if (finished_index != -1) {
749     comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
750     /* the communication is finished */
751     comm->status = status;
752
753     if (status == MSG_OK && comm->task_received != NULL) {
754       /* I am the receiver */
755       (*comm->task_received)->simdata->isused = 0;
756     }
757   }
758
759   return finished_index;
760 }
761
762 /** \ingroup msg_task_usage
763  * \brief Destroys a communication.
764  * \param comm the communication to destroy.
765  */
766 void MSG_comm_destroy(msg_comm_t comm)
767 {
768   xbt_free(comm);
769 }
770
771 /** \ingroup msg_task_usage
772  * \brief Wait for the completion of a communication.
773  *
774  * It takes two parameters.
775  * \param comm the communication to wait.
776  * \param timeout Wait until the communication terminates or the timeout 
777  * occurs. You can provide a -1 timeout to obtain an infinite timeout.
778  * \return msg_error_t
779  */
780 msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
781 {
782   xbt_ex_t e;
783   TRY {
784     simcall_comm_wait(comm->s_comm, timeout);
785
786     if (comm->task_received != NULL) {
787       /* I am the receiver */
788       (*comm->task_received)->simdata->isused = 0;
789     }
790
791     /* FIXME: these functions are not traceable */
792   }
793   CATCH(e) {
794     switch (e.category) {
795     case network_error:
796       comm->status = MSG_TRANSFER_FAILURE;
797       break;
798     case timeout_error:
799       comm->status = MSG_TIMEOUT;
800       break;
801     default:
802       RETHROW;
803     }
804     xbt_ex_free(e);
805   }
806
807   return comm->status;
808 }
809
810 /** \ingroup msg_task_usage
811 * \brief This function is called by a sender and permit to wait for each communication
812 *
813 * \param comm a vector of communication
814 * \param nb_elem is the size of the comm vector
815 * \param timeout for each call of MSG_comm_wait
816 */
817 void MSG_comm_waitall(msg_comm_t * comm, int nb_elem, double timeout)
818 {
819   int i = 0;
820   for (i = 0; i < nb_elem; i++) {
821     MSG_comm_wait(comm[i], timeout);
822   }
823 }
824
825 /** \ingroup msg_task_usage
826  * \brief This function waits for the first communication finished in a list.
827  * \param comms a vector of communications
828  * \return the position of the first finished communication
829  * (but it may have failed, use MSG_comm_get_status() to know its status)
830  */
831 int MSG_comm_waitany(xbt_dynar_t comms)
832 {
833   xbt_ex_t e;
834   int finished_index = -1;
835
836   /* create the equivalent dynar with SIMIX objects */
837   xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
838   msg_comm_t comm;
839   unsigned int cursor;
840   xbt_dynar_foreach(comms, cursor, comm) {
841     xbt_dynar_push(s_comms, &comm->s_comm);
842   }
843
844   msg_error_t status = MSG_OK;
845   TRY {
846     finished_index = simcall_comm_waitany(s_comms);
847   }
848   CATCH(e) {
849     switch (e.category) {
850       case network_error:
851         finished_index = e.value;
852         status = MSG_TRANSFER_FAILURE;
853         break;
854
855       case timeout_error:
856         finished_index = e.value;
857         status = MSG_TIMEOUT;
858         break;
859
860       default:
861         RETHROW;
862     }
863     xbt_ex_free(e);
864   }
865
866   xbt_assert(finished_index != -1, "WaitAny returned -1");
867   xbt_dynar_free(&s_comms);
868
869   comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
870   /* the communication is finished */
871   comm->status = status;
872
873   if (comm->task_received != NULL) {
874     /* I am the receiver */
875     (*comm->task_received)->simdata->isused = 0;
876   }
877
878   return finished_index;
879 }
880
881 /**
882  * \ingroup msg_task_usage
883  * \brief Returns the error (if any) that occured during a finished communication.
884  * \param comm a finished communication
885  * \return the status of the communication, or #MSG_OK if no error occured
886  * during the communication
887  */
888 msg_error_t MSG_comm_get_status(msg_comm_t comm) {
889
890   return comm->status;
891 }
892
893 /** \ingroup msg_task_usage
894  * \brief Get a task (#msg_task_t) from a communication
895  *
896  * \param comm the communication where to get the task
897  * \return the task from the communication
898  */
899 msg_task_t MSG_comm_get_task(msg_comm_t comm)
900 {
901   xbt_assert(comm, "Invalid parameter");
902
903   return comm->task_received ? *comm->task_received : comm->task_sent;
904 }
905
906 /**
907  * \brief This function is called by SIMIX in kernel mode to copy the data of a comm.
908  * \param comm the comm
909  * \param buff the data copied
910  * \param buff_size size of the buffer
911  */
912 void MSG_comm_copy_data_from_SIMIX(smx_action_t comm, void* buff, size_t buff_size) {
913
914   // copy the task
915   SIMIX_comm_copy_pointer_callback(comm, buff, buff_size);
916
917   // notify the user callback if any
918   if (msg_global->task_copy_callback) {
919     msg_task_t task = buff;
920     msg_global->task_copy_callback(task,
921         simcall_comm_get_src_proc(comm), simcall_comm_get_dst_proc(comm));
922   }
923 }
924
925 /** \ingroup msg_task_usage
926  * \brief Sends a task to a mailbox
927  *
928  * This is a blocking function, the execution flow will be blocked
929  * until the task is sent (and received in the other side if #MSG_task_receive is used).
930  * See #MSG_task_isend for sending tasks asynchronously.
931  *
932  * \param task the task to be sent
933  * \param alias the mailbox name to where the task is sent
934  *
935  * \return Returns #MSG_OK if the task was successfully sent,
936  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
937  */
938 msg_error_t MSG_task_send(msg_task_t task, const char *alias)
939 {
940   XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
941   return MSG_task_send_with_timeout(task, alias, -1);
942 }
943
944 /** \ingroup msg_task_usage
945  * \brief Sends a task to a mailbox with a maximum rate
946  *
947  * This is a blocking function, the execution flow will be blocked
948  * until the task is sent. The maxrate parameter allows the application
949  * to limit the bandwidth utilization of network links when sending the task.
950  *
951  * \param task the task to be sent
952  * \param alias the mailbox name to where the task is sent
953  * \param maxrate the maximum communication rate for sending this task
954  *
955  * \return Returns #MSG_OK if the task was successfully sent,
956  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
957  */
958 msg_error_t
959 MSG_task_send_bounded(msg_task_t task, const char *alias, double maxrate)
960 {
961   task->simdata->rate = maxrate;
962   return MSG_task_send(task, alias);
963 }
964
965 /** \ingroup msg_task_usage
966  * \brief Sends a task to a mailbox with a timeout
967  *
968  * This is a blocking function, the execution flow will be blocked
969  * until the task is sent or the timeout is achieved.
970  *
971  * \param task the task to be sent
972  * \param alias the mailbox name to where the task is sent
973  * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
974  *
975  * \return Returns #MSG_OK if the task was successfully sent,
976  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
977  */
978 msg_error_t
979 MSG_task_send_with_timeout(msg_task_t task, const char *alias,
980                            double timeout)
981 {
982   return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias),
983                                       task, timeout);
984 }
985
986 /** \ingroup msg_task_usage
987  * \brief Sends a task to a mailbox with a timeout and with a maximum rate
988  *
989  * This is a blocking function, the execution flow will be blocked
990  * until the task is sent or the timeout is achieved.
991  *
992  * \param task the task to be sent
993  * \param alias the mailbox name to where the task is sent
994  * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
995  * \param maxrate the maximum communication rate for sending this task
996  *
997  * \return Returns #MSG_OK if the task was successfully sent,
998  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
999  */
1000 msg_error_t
1001 MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alias,
1002                            double timeout, double maxrate)
1003 {
1004   task->simdata->rate = maxrate;
1005   return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias),
1006                                       task, timeout);
1007 }
1008
1009 /** \ingroup msg_task_usage
1010  * \brief Check if there is a communication going on in a mailbox.
1011  *
1012  * \param alias the name of the mailbox to be considered
1013  *
1014  * \return Returns 1 if there is a communication, 0 otherwise
1015  */
1016 int MSG_task_listen(const char *alias)
1017 {
1018   return !MSG_mailbox_is_empty(MSG_mailbox_get_by_alias(alias));
1019 }
1020
1021 /** \ingroup msg_task_usage
1022  * \brief Check the number of communication actions of a given host pending in a mailbox.
1023  *
1024  * \param alias the name of the mailbox to be considered
1025  * \param host the host to check for communication
1026  *
1027  * \return Returns the number of pending communication actions of the host in the
1028  * given mailbox, 0 if there is no pending communication actions.
1029  *
1030  */
1031 int MSG_task_listen_from_host(const char *alias, msg_host_t host)
1032 {
1033   return
1034       MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias
1035                                                (alias), host);
1036 }
1037
1038 /** \ingroup msg_task_usage
1039  * \brief Look if there is a communication on a mailbox and return the
1040  * PID of the sender process.
1041  *
1042  * \param alias the name of the mailbox to be considered
1043  *
1044  * \return Returns the PID of sender process,
1045  * -1 if there is no communication in the mailbox.
1046  */
1047 int MSG_task_listen_from(const char *alias)
1048 {
1049   msg_task_t task;
1050
1051   if (NULL ==
1052       (task = MSG_mailbox_get_head(MSG_mailbox_get_by_alias(alias))))
1053     return -1;
1054
1055   return MSG_process_get_PID(task->simdata->sender);
1056 }
1057
1058 /** \ingroup msg_task_usage
1059  * \brief Sets the tracing category of a task.
1060  *
1061  * This function should be called after the creation of
1062  * a MSG task, to define the category of that task. The
1063  * first parameter task must contain a task that was
1064  * created with the function #MSG_task_create. The second
1065  * parameter category must contain a category that was
1066  * previously declared with the function #TRACE_category
1067  * (or with #TRACE_category_with_color).
1068  *
1069  * See \ref tracing for details on how to trace
1070  * the (categorized) resource utilization.
1071  *
1072  * \param task the task that is going to be categorized
1073  * \param category the name of the category to be associated to the task
1074  *
1075  * \see MSG_task_get_category, TRACE_category, TRACE_category_with_color
1076  */
1077 void MSG_task_set_category (msg_task_t task, const char *category)
1078 {
1079 #ifdef HAVE_TRACING
1080   TRACE_msg_set_task_category (task, category);
1081 #endif
1082 }
1083
1084 /** \ingroup msg_task_usage
1085  *
1086  * \brief Gets the current tracing category of a task.
1087  *
1088  * \param task the task to be considered
1089  *
1090  * \see MSG_task_set_category
1091  *
1092  * \return Returns the name of the tracing category of the given task, NULL otherwise
1093  */
1094 const char *MSG_task_get_category (msg_task_t task)
1095 {
1096 #ifdef HAVE_TRACING
1097   return task->category;
1098 #else
1099   return NULL;
1100 #endif
1101 }
1102
1103 /**
1104  * \brief Returns the value of a given AS or router property
1105  *
1106  * \param asr the name of a router or AS
1107  * \param name a property name
1108  * \return value of a property (or NULL if property not set)
1109  */
1110 const char *MSG_as_router_get_property_value(const char* asr, const char *name)
1111 {
1112   return xbt_dict_get_or_null(MSG_as_router_get_properties(asr), name);
1113 }
1114
1115 /**
1116  * \brief Returns a xbt_dict_t consisting of the list of properties assigned to
1117  * a the AS or router
1118  *
1119  * \param asr the name of a router or AS
1120  * \return a dict containing the properties
1121  */
1122 xbt_dict_t MSG_as_router_get_properties(const char* asr)
1123 {
1124   return (simcall_asr_get_properties(asr));
1125 }
1126
1127 /**
1128  * \brief Change the value of a given AS or router
1129  *
1130  * \param asr the name of a router or AS
1131  * \param name a property name
1132  * \param value what to change the property to
1133  * \param free_ctn the freeing function to use to kill the value on need
1134  */
1135 void MSG_as_router_set_property_value(const char* asr, const char *name, char *value,void_f_pvoid_t free_ctn) {
1136   xbt_dict_set(MSG_as_router_get_properties(asr), name, value,free_ctn);
1137 }
1138
1139 #ifdef MSG_USE_DEPRECATED
1140 /** \ingroup msg_deprecated_functions
1141  *
1142  * \brief Return the last value returned by a MSG function (except
1143  * MSG_get_errno...).
1144  */
1145 msg_error_t MSG_get_errno(void)
1146 {
1147   return PROCESS_GET_ERRNO();
1148 }
1149
1150 /** \ingroup msg_deprecated_functions
1151  * \brief Put a task on a channel of an host and waits for the end of the
1152  * transmission.
1153  *
1154  * This function is used for describing the behavior of a process. It
1155  * takes three parameter.
1156  * \param task a #msg_task_t to send on another location. This task
1157  will not be usable anymore when the function will return. There is
1158  no automatic task duplication and you have to save your parameters
1159  before calling this function. Tasks are unique and once it has been
1160  sent to another location, you should not access it anymore. You do
1161  not need to call MSG_task_destroy() but to avoid using, as an
1162  effect of inattention, this task anymore, you definitely should
1163  renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
1164  can be transfered iff it has been correctly created with
1165  MSG_task_create().
1166  * \param dest the destination of the message
1167  * \param channel the channel on which the process should put this
1168  task. This value has to be >=0 and < than the maximal number of
1169  channels fixed with MSG_set_channel_number().
1170  * \return #MSG_HOST_FAILURE if the host on which
1171  * this function was called was shut down,
1172  * #MSG_TRANSFER_FAILURE if the transfer could not be properly done
1173  * (network failure, dest failure) or #MSG_OK if it succeeded.
1174  */
1175 msg_error_t MSG_task_put(msg_task_t task, msg_host_t dest, m_channel_t channel)
1176 {
1177   XBT_WARN("DEPRECATED! Now use MSG_task_send");
1178   return MSG_task_put_with_timeout(task, dest, channel, -1.0);
1179 }
1180
1181 /** \ingroup msg_deprecated_functions
1182  * \brief Does exactly the same as MSG_task_put but with a bounded transmition
1183  * rate.
1184  *
1185  * \sa MSG_task_put
1186  */
1187 msg_error_t
1188 MSG_task_put_bounded(msg_task_t task, msg_host_t dest, m_channel_t channel,
1189                      double maxrate)
1190 {
1191   XBT_WARN("DEPRECATED! Now use MSG_task_send_bounded");
1192   task->simdata->rate = maxrate;
1193   return MSG_task_put(task, dest, channel);
1194 }
1195
1196 /** \ingroup msg_deprecated_functions
1197  *
1198  * \brief Put a task on a channel of an
1199  * host (with a timeout on the waiting of the destination host) and
1200  * waits for the end of the transmission.
1201  *
1202  * This function is used for describing the behavior of a process. It
1203  * takes four parameter.
1204  * \param task a #msg_task_t to send on another location. This task
1205  will not be usable anymore when the function will return. There is
1206  no automatic task duplication and you have to save your parameters
1207  before calling this function. Tasks are unique and once it has been
1208  sent to another location, you should not access it anymore. You do
1209  not need to call MSG_task_destroy() but to avoid using, as an
1210  effect of inattention, this task anymore, you definitely should
1211  renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
1212  can be transfered iff it has been correctly created with
1213  MSG_task_create().
1214  * \param dest the destination of the message
1215  * \param channel the channel on which the process should put this
1216  task. This value has to be >=0 and < than the maximal number of
1217  channels fixed with MSG_set_channel_number().
1218  * \param timeout the maximum time to wait for a task before giving
1219  up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
1220  will not be modified
1221  * \return #MSG_HOST_FAILURE if the host on which
1222 this function was called was shut down,
1223 #MSG_TRANSFER_FAILURE if the transfer could not be properly done
1224 (network failure, dest failure, timeout...) or #MSG_OK if the communication succeeded.
1225  */
1226 msg_error_t
1227 MSG_task_put_with_timeout(msg_task_t task, msg_host_t dest,
1228                           m_channel_t channel, double timeout)
1229 {
1230   XBT_WARN("DEPRECATED! Now use MSG_task_send_with_timeout");
1231   xbt_assert((channel >= 0)
1232               && (channel < msg_global->max_channel), "Invalid channel %d",
1233               channel);
1234
1235   XBT_DEBUG("MSG_task_put_with_timout: Trying to send a task to '%s'", SIMIX_host_get_name(dest->smx_host));
1236   return
1237       MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_channel
1238                                    (dest, channel), task, timeout);
1239 }
1240
1241 /** \ingroup msg_deprecated_functions
1242  * \brief Test whether there is a pending communication on a channel, and who sent it.
1243  *
1244  * It takes one parameter.
1245  * \param channel the channel on which the process should be
1246  listening. This value has to be >=0 and < than the maximal
1247  number of channels fixed with MSG_set_channel_number().
1248  * \return -1 if there is no pending communication and the PID of the process who sent it otherwise
1249  */
1250 int MSG_task_probe_from(m_channel_t channel)
1251 {
1252   XBT_WARN("DEPRECATED! Now use MSG_task_listen_from");
1253   msg_task_t task;
1254
1255   xbt_assert((channel >= 0)
1256               && (channel < msg_global->max_channel), "Invalid channel %d",
1257               channel);
1258
1259   if (NULL ==
1260       (task =
1261        MSG_mailbox_get_head(MSG_mailbox_get_by_channel
1262                             (MSG_host_self(), channel))))
1263     return -1;
1264
1265   return MSG_process_get_PID(task->simdata->sender);
1266 }
1267
1268 /** \ingroup msg_deprecated_functions
1269  * \brief Test whether there is a pending communication on a channel.
1270  *
1271  * It takes one parameter.
1272  * \param channel the channel on which the process should be
1273  listening. This value has to be >=0 and < than the maximal
1274  number of channels fixed with MSG_set_channel_number().
1275  * \return 1 if there is a pending communication and 0 otherwise
1276  */
1277 int MSG_task_Iprobe(m_channel_t channel)
1278 {
1279   XBT_WARN("DEPRECATED!");
1280   xbt_assert((channel >= 0)
1281               && (channel < msg_global->max_channel), "Invalid channel %d",
1282               channel);
1283
1284   return
1285       !MSG_mailbox_is_empty(MSG_mailbox_get_by_channel
1286                             (MSG_host_self(), channel));
1287 }
1288
1289 /** \ingroup msg_deprecated_functions
1290
1291  * \brief Return the number of tasks waiting to be received on a \a
1292  channel and sent by \a host.
1293  *
1294  * It takes two parameters.
1295  * \param channel the channel on which the process should be
1296  listening. This value has to be >=0 and < than the maximal
1297  number of channels fixed with MSG_set_channel_number().
1298  * \param host the host that is to be watched.
1299  * \return the number of tasks waiting to be received on \a channel
1300  and sent by \a host.
1301  */
1302 int MSG_task_probe_from_host(int channel, msg_host_t host)
1303 {
1304   XBT_WARN("DEPRECATED! Now use MSG_task_listen_from_host");
1305   xbt_assert((channel >= 0)
1306               && (channel < msg_global->max_channel), "Invalid channel %d",
1307               channel);
1308
1309   return
1310       MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_channel
1311                                                (MSG_host_self(), channel),
1312                                                host);
1313
1314 }
1315
1316 /** \ingroup msg_deprecated_functions
1317  * \brief Listen on \a channel and waits for receiving a task from \a host.
1318  *
1319  * It takes three parameters.
1320  * \param task a memory location for storing a #msg_task_t. It will
1321  hold a task when this function will return. Thus \a task should not
1322  be equal to \c NULL and \a *task should be equal to \c NULL. If one of
1323  those two condition does not hold, there will be a warning message.
1324  * \param channel the channel on which the process should be
1325  listening. This value has to be >=0 and < than the maximal
1326  number of channels fixed with MSG_set_channel_number().
1327  * \param host the host that is to be watched.
1328  * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
1329  */
1330 msg_error_t
1331 MSG_task_get_from_host(msg_task_t * task, m_channel_t channel, msg_host_t host)
1332 {
1333   XBT_WARN("DEPRECATED! Now use MSG_task_receive_from_host");
1334   return MSG_task_get_ext(task, channel, -1, host);
1335 }
1336
1337 /** \ingroup msg_deprecated_functions
1338  * \brief Listen on a channel and wait for receiving a task.
1339  *
1340  * It takes two parameters.
1341  * \param task a memory location for storing a #msg_task_t. It will
1342  hold a task when this function will return. Thus \a task should not
1343  be equal to \c NULL and \a *task should be equal to \c NULL. If one of
1344  those two condition does not hold, there will be a warning message.
1345  * \param channel the channel on which the process should be
1346  listening. This value has to be >=0 and < than the maximal
1347  number of channels fixed with MSG_set_channel_number().
1348  * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
1349  */
1350 msg_error_t MSG_task_get(msg_task_t * task, m_channel_t channel)
1351 {
1352   XBT_WARN("DEPRECATED! Now use MSG_task_receive");
1353   return MSG_task_get_with_timeout(task, channel, -1);
1354 }
1355
1356 /** \ingroup msg_deprecated_functions
1357  * \brief Listen on a channel and wait for receiving a task with a timeout.
1358  *
1359  * It takes three parameters.
1360  * \param task a memory location for storing a #msg_task_t. It will
1361  hold a task when this function will return. Thus \a task should not
1362  be equal to \c NULL and \a *task should be equal to \c NULL. If one of
1363  those two condition does not hold, there will be a warning message.
1364  * \param channel the channel on which the process should be
1365  listening. This value has to be >=0 and < than the maximal
1366  number of channels fixed with MSG_set_channel_number().
1367  * \param max_duration the maximum time to wait for a task before giving
1368  up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
1369  will not be modified and will still be
1370  equal to \c NULL when returning.
1371  * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
1372  */
1373 msg_error_t
1374 MSG_task_get_with_timeout(msg_task_t * task, m_channel_t channel,
1375                           double max_duration)
1376 {
1377   XBT_WARN("DEPRECATED! Now use MSG_task_receive_with_timeout");
1378   return MSG_task_get_ext(task, channel, max_duration, NULL);
1379 }
1380
1381 msg_error_t
1382 MSG_task_get_ext(msg_task_t * task, m_channel_t channel, double timeout,
1383                  msg_host_t host)
1384 {
1385   XBT_WARN("DEPRECATED! Now use MSG_task_receive_ext");
1386   xbt_assert((channel >= 0)
1387               && (channel < msg_global->max_channel), "Invalid channel %d",
1388               channel);
1389
1390   return
1391       MSG_mailbox_get_task_ext(MSG_mailbox_get_by_channel
1392                                (MSG_host_self(), channel), task, host,
1393                                timeout);
1394 }
1395
1396 #endif