Logo AND Algorithmique Numérique Distribuée

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