Logo AND Algorithmique Numérique Distribuée

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