Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d42275c9f9b889ce22f5b22622e164804a644bb3
[simgrid.git] / src / simix / smx_user.c
1 /* smx_user.c - public interface to simix                                   */
2
3 /* Copyright (c) 2010-2012. Da SimGrid team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "smx_private.h"
9 #include "mc/mc.h"
10 #include "xbt/ex.h"
11 #include <math.h>         /* isfinite() */
12
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
14
15 /* generate strings from the enumeration values */
16 static const char* simcall_names[] = {
17 SIMCALL_LIST(SIMCALL_STRING_TYPE, SIMCALL_SEP_COMMA)
18 [SIMCALL_NONE] = "NONE"
19 };
20
21 SIMCALL_LIST(SIMCALL_FUNC, SIMCALL_SEP_NOTHING)
22
23 /**
24  * \ingroup simix_host_management
25  * \brief Returns a host given its name.
26  *
27  * \param name The name of the host to get
28  * \return The corresponding host
29  */
30 smx_host_t simcall_host_get_by_name(const char *name)
31 {
32   return simcall_BODY_host_get_by_name(name);
33 }
34
35 /**
36  * \ingroup simix_host_management
37  * \brief Returns the name of a host.
38  *
39  * \param host A SIMIX host
40  * \return The name of this host
41  */
42 const char* simcall_host_get_name(smx_host_t host)
43 {
44   return simcall_BODY_host_get_name(host);
45 }
46
47 /**
48  * \ingroup simix_host_management
49  * \brief Returns a dict of the properties assigned to a host.
50  *
51  * \param host A host
52  * \return The properties of this host
53  */
54 xbt_dict_t simcall_host_get_properties(smx_host_t host)
55 {
56   return simcall_BODY_host_get_properties(host);
57 }
58
59 /**
60  * \ingroup simix_host_management
61  * \brief Returns a dict of the properties assigned to a router or AS.
62  *
63  * \param name The name of the router or AS
64  * \return The properties
65  */
66 xbt_dict_t simcall_asr_get_properties(const char *name)
67 {
68   return simcall_BODY_asr_get_properties(name);
69 }
70
71
72 /**
73  * \ingroup simix_host_management
74  * \brief Returns the speed of the processor.
75  *
76  * The speed returned does not take into account the current load on the machine.
77  * \param host A SIMIX host
78  * \return The speed of this host (in Mflop/s)
79  */
80 double simcall_host_get_speed(smx_host_t host)
81 {
82   return simcall_BODY_host_get_speed(host);
83 }
84
85 /**
86  * \ingroup simix_host_management
87  * \brief Returns the number of core of the processor.
88  *
89  * \param host A SIMIX host
90  * \return The number of core
91  */
92 int simcall_host_get_core(smx_host_t host)
93 {
94   return simcall_BODY_host_get_core(host);
95 }
96
97
98
99 /**
100  * \ingroup simix_host_management
101  * \brief Returns the available speed of the processor.
102  *
103  * \return Speed currently available (in Mflop/s)
104  */
105 double simcall_host_get_available_speed(smx_host_t host)
106 {
107   return simcall_BODY_host_get_available_speed(host);
108 }
109
110 /**
111  * \ingroup simix_host_management
112  * \brief Returns the state of a host.
113  *
114  * Two states are possible: 1 if the host is active or 0 if it has crashed.
115  * \param host A SIMIX host
116  * \return 1 if the host is available, 0 otherwise
117  */
118 int simcall_host_get_state(smx_host_t host)
119 {
120   return simcall_BODY_host_get_state(host);
121 }
122
123 /**
124  * \ingroup simix_host_management
125  * \brief Returns the user data associated to a host.
126  *
127  * \param host SIMIX host
128  * \return the user data of this host
129  */
130 void* simcall_host_get_data(smx_host_t host)
131 {
132   return simcall_BODY_host_get_data(host);
133 }
134
135 /**
136  * \ingroup simix_host_management
137  * \brief Sets the user data associated to a host.
138  *
139  * The host must not have previous user data associated to it.
140  * \param host A SIMIX host
141  * \param data The user data to set
142  */
143 void simcall_host_set_data(smx_host_t host, void *data)
144 {
145   simcall_host_set_data(host, data);
146 }
147
148 /**
149  * \ingroup simix_host_management
150  * \brief Creates an action that executes some computation of an host.
151  *
152  * This function creates a SURF action and allocates the data necessary
153  * to create the SIMIX action. It can raise a host_error exception if the host crashed.
154  *
155  * \param name Name of the execution action to create
156  * \param host SIMIX host where the action will be executed
157  * \param computation_amount amount Computation amount (in bytes)
158  * \param priority computation priority
159  * \return A new SIMIX execution action
160  */
161
162 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
163                                     double computation_amount,
164                                     double priority)
165 {
166   /* checking for infinite values */
167   xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
168   xbt_assert(isfinite(priority), "priority is not finite!");
169   
170   return simcall_BODY_host_execute(name, host, computation_amount, priority);
171 }
172
173 /**
174  * \ingroup simix_host_management
175  * \brief Creates an action that may involve parallel computation on
176  * several hosts and communication between them.
177  *
178  * \param name Name of the execution action to create
179  * \param host_nb Number of hosts where the action will be executed
180  * \param host_list Array (of size host_nb) of hosts where the action will be executed
181  * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
182  * \param communication_amount Array (of size host_nb * host_nb) representing the communication
183  * amount between each pair of hosts
184  * \param amount the SURF action amount
185  * \param rate the SURF action rate
186  * \return A new SIMIX execution action
187  */
188 smx_action_t simcall_host_parallel_execute(const char *name,
189                                          int host_nb,
190                                          smx_host_t *host_list,
191                                          double *computation_amount,
192                                          double *communication_amount,
193                                          double amount,
194                                          double rate)
195 {
196   int i,j;
197   /* checking for infinite values */
198   for (i = 0 ; i < host_nb ; ++i) {
199      xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
200      for (j = 0 ; j < host_nb ; ++j) {
201         xbt_assert(isfinite(communication_amount[i + host_nb * j]), 
202              "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
203      }   
204   }   
205  
206   xbt_assert(isfinite(amount), "amount is not finite!");
207   xbt_assert(isfinite(rate), "rate is not finite!");
208   
209   return simcall_BODY_host_parallel_execute(name, host_nb, host_list,
210                                             computation_amount,
211                                             communication_amount,
212                                             amount, rate);
213
214 }
215
216 /**
217  * \ingroup simix_host_management
218  * \brief Destroys an execution action.
219  *
220  * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
221  * \param execution The execution action to destroy
222  */
223 void simcall_host_execution_destroy(smx_action_t execution)
224 {
225   simcall_BODY_host_execution_destroy(execution);
226 }
227
228 /**
229  * \ingroup simix_host_management
230  * \brief Cancels an execution action.
231  *
232  * This functions stops the execution. It calls a surf function.
233  * \param execution The execution action to cancel
234  */
235 void simcall_host_execution_cancel(smx_action_t execution)
236 {
237   simcall_BODY_host_execution_cancel(execution);
238 }
239
240 /**
241  * \ingroup simix_host_management
242  * \brief Returns how much of an execution action remains to be done.
243  *
244  * \param execution The execution action
245  * \return The remaining amount
246  */
247 double simcall_host_execution_get_remains(smx_action_t execution)
248 {
249   return simcall_BODY_host_execution_get_remains(execution);
250 }
251
252 /**
253  * \ingroup simix_host_management
254  * \brief Returns the state of an execution action.
255  *
256  * \param execution The execution action
257  * \return The state
258  */
259 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
260 {
261   return simcall_BODY_host_execution_get_state(execution);
262 }
263
264 /**
265  * \ingroup simix_host_management
266  * \brief Changes the priority of an execution action.
267  *
268  * This functions changes the priority only. It calls a surf function.
269  * \param execution The execution action
270  * \param priority The new priority
271  */
272 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
273 {
274   /* checking for infinite values */
275   xbt_assert(isfinite(priority), "priority is not finite!");
276   
277   simcall_BODY_host_execution_set_priority(execution, priority);
278 }
279
280 /**
281  * \ingroup simix_host_management
282  * \brief Waits for the completion of an execution action and destroy it.
283  *
284  * \param execution The execution action
285  */
286 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
287 {
288   return simcall_BODY_host_execution_wait(execution);
289 }
290
291 /**
292  * \ingroup simix_process_management
293  * \brief Creates and runs a new SIMIX process.
294  *
295  * The structure and the corresponding thread are created and put in the list of ready processes.
296  *
297  * \param process the process created will be stored in this pointer
298  * \param name a name for the process. It is for user-level information and can be NULL.
299  * \param code the main function of the process
300  * \param data a pointer to any data one may want to attach to the new object. It is for user-level information and can be NULL.
301  * It can be retrieved with the function \ref simcall_process_get_data.
302  * \param hostname name of the host where the new agent is executed.
303  * \param kill_time time when the process is killed
304  * \param argc first argument passed to \a code
305  * \param argv second argument passed to \a code
306  * \param properties the properties of the process
307  * \param auto_restart either it is autorestarting or not.
308  */
309 void simcall_process_create(smx_process_t *process, const char *name,
310                               xbt_main_func_t code,
311                               void *data,
312                               const char *hostname,
313                               double kill_time,
314                               int argc, char **argv,
315                               xbt_dict_t properties,
316                               int auto_restart)
317 {
318   simcall_BODY_process_create(process, name, code, data, hostname,
319                               kill_time, argc, argv, properties,
320                               auto_restart);
321 }
322
323 /**
324  * \ingroup simix_process_management
325  * \brief Kills a SIMIX process.
326  *
327  * This function simply kills a  process.
328  *
329  * \param process poor victim
330  */
331 void simcall_process_kill(smx_process_t process)
332 {
333   simcall_BODY_process_kill(process);
334 }
335
336 /**
337  * \ingroup simix_process_management
338  * \brief Kills all SIMIX processes.
339  */
340 void simcall_process_killall(int reset_pid)
341 {
342   simcall_BODY_process_killall(reset_pid);
343 }
344
345 /**
346  * \ingroup simix_process_management
347  * \brief Cleans up a SIMIX process.
348  * \param process poor victim (must have already been killed)
349  */
350 void simcall_process_cleanup(smx_process_t process)
351 {
352   simcall_BODY_process_cleanup(process);
353 }
354
355 /**
356  * \ingroup simix_process_management
357  * \brief Migrates an agent to another location.
358  *
359  * This function changes the value of the host on which \a process is running.
360  *
361  * \param process the process to migrate
362  * \param dest name of the new host
363  */
364 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
365 {
366   simcall_BODY_process_change_host(process, dest);
367 }
368
369 /**
370  * \ingroup simix_process_management
371  * \brief Suspends a process.
372  *
373  * This function suspends the process by suspending the action
374  * it was waiting for completion.
375  *
376  * \param process a SIMIX process
377  */
378 void simcall_process_suspend(smx_process_t process)
379 {
380   xbt_assert(process, "Invalid parameters");
381
382   simcall_BODY_process_suspend(process);
383 }
384
385 /**
386  * \ingroup simix_process_management
387  * \brief Resumes a suspended process.
388  *
389  * This function resumes a suspended process by resuming the action
390  * it was waiting for completion.
391  *
392  * \param process a SIMIX process
393  */
394 void simcall_process_resume(smx_process_t process)
395 {
396   simcall_BODY_process_resume(process);
397 }
398
399 /**
400  * \ingroup simix_process_management
401  * \brief Returns the amount of SIMIX processes in the system
402  *
403  * Maestro internal process is not counted, only user code processes are
404  */
405 int simcall_process_count(void)
406 {
407   return simcall_BODY_process_count();
408 }
409
410 /**
411  * \ingroup simix_process_management
412  * \brief Return the PID of a #smx_process_t.
413  * \param process a SIMIX process
414  * \return the PID of this process
415  */
416 int simcall_process_get_PID(smx_process_t process)
417 {
418   if (process == SIMIX_process_self()) {
419     /* avoid a simcall if this function is called by the process itself */
420     return SIMIX_process_get_PID(process);
421   }
422
423   return simcall_BODY_process_get_PID(process);
424 }
425
426 /**
427  * \ingroup simix_process_management
428  * \brief Return the parent PID of a #smx_process_t.
429  * \param process a SIMIX process
430  * \return the PID of this process parenrt
431  */
432 int simcall_process_get_PPID(smx_process_t process)
433 {
434   if (process == SIMIX_process_self()) {
435     /* avoid a simcall if this function is called by the process itself */
436     return SIMIX_process_get_PPID(process);
437   }
438
439   return simcall_BODY_process_get_PPID(process);
440 }
441
442 /**
443  * \ingroup simix_process_management
444  * \brief Return the user data of a #smx_process_t.
445  * \param process a SIMIX process
446  * \return the user data of this process
447  */
448 void* simcall_process_get_data(smx_process_t process)
449 {
450   if (process == SIMIX_process_self()) {
451     /* avoid a simcall if this function is called by the process itself */
452     return SIMIX_process_get_data(process);
453   }
454
455   return simcall_BODY_process_get_data(process);
456 }
457
458 /**
459  * \ingroup simix_process_management
460  * \brief Set the user data of a #smx_process_t.
461  *
462  * This functions sets the user data associated to \a process.
463  * \param process SIMIX process
464  * \param data User data
465  */
466 void simcall_process_set_data(smx_process_t process, void *data)
467 {
468   if (process == SIMIX_process_self()) {
469     /* avoid a simcall if this function is called by the process itself */
470     SIMIX_process_self_set_data(process, data);
471   }
472   else {
473     simcall_BODY_process_set_data(process, data);
474   }
475 }
476
477 /**
478  * \ingroup simix_process_management
479  * \brief Set the kill time of a process.
480  * \param process a process
481  * \param kill_time a double
482  */
483 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
484 {
485
486   if (kill_time > SIMIX_get_clock()) {
487     if (simix_global->kill_process_function) {
488       XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
489           sg_host_name(process->smx_host));
490       SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
491     }
492   }
493 }
494
495 /**
496  * \ingroup simix_process_management
497  * \brief Return the location on which an agent is running.
498  *
499  * This functions returns the smx_host_t corresponding to the location on which
500  * \a process is running.
501  * \param process SIMIX process
502  * \return SIMIX host
503  */
504 smx_host_t simcall_process_get_host(smx_process_t process)
505 {
506   return simcall_BODY_process_get_host(process);
507 }
508
509 /**
510  * \ingroup simix_process_management
511  * \brief Return the name of an agent.
512  *
513  * This functions checks whether \a process is a valid pointer or not and return its name.
514  * \param process SIMIX process
515  * \return The process name
516  */
517 const char* simcall_process_get_name(smx_process_t process)
518 {
519   if (process == SIMIX_process_self()) {
520     /* avoid a simcall if this function is called by the process itself */
521     return process->name;
522   }
523   return simcall_BODY_process_get_name(process);
524 }
525
526 /**
527  * \ingroup simix_process_management
528  * \brief Returns true if the process is suspended .
529  *
530  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
531  * \param process SIMIX process
532  * \return 1, if the process is suspended, else 0.
533  */
534 int simcall_process_is_suspended(smx_process_t process)
535 {
536   return  simcall_BODY_process_is_suspended(process);
537 }
538
539 /**
540  * \ingroup simix_process_management
541  * \brief Return the properties
542  *
543  * This functions returns the properties associated with this process
544  */
545 xbt_dict_t simcall_process_get_properties(smx_process_t process)
546 {
547   return simcall_BODY_process_get_properties(process);
548 }
549 /**
550  * \ingroup simix_process_management
551  * \brief Add an on_exit function
552  * Add an on_exit function which will be executed when the process exits/is killed.
553  */
554 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
555 {
556   simcall_BODY_process_on_exit(process, fun, data);
557 }
558 /**
559  * \ingroup simix_process_management
560  * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
561  * Will restart the process when the host comes back up if auto_restart is set to 1.
562  */
563
564 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
565 {
566   simcall_BODY_process_auto_restart_set(process, auto_restart);
567 }
568
569 /**
570  * \ingroup simix_process_management
571  * \brief Restarts the process, killing it and starting it again from scratch.
572  */
573 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
574 {
575   return simcall_BODY_process_restart(process);
576 }
577 /**
578  * \ingroup simix_process_management
579  * \brief Creates a new sleep SIMIX action.
580  *
581  * This function creates a SURF action and allocates the data necessary
582  * to create the SIMIX action. It can raise a host_error exception if the
583  * host crashed. The default SIMIX name of the action is "sleep".
584  *
585  *   \param duration Time duration of the sleep.
586  *   \return A result telling whether the sleep was successful
587  */
588 e_smx_state_t simcall_process_sleep(double duration)
589 {
590   /* checking for infinite values */
591   xbt_assert(isfinite(duration), "duration is not finite!");
592   return simcall_BODY_process_sleep(duration);
593 }
594
595 /**
596  *  \ingroup simix_rdv_management
597  *  \brief Creates a new rendez-vous point
598  *  \param name The name of the rendez-vous point
599  *  \return The created rendez-vous point
600  */
601 smx_rdv_t simcall_rdv_create(const char *name)
602 {
603   return simcall_BODY_rdv_create(name);
604 }
605
606
607 /**
608  *  \ingroup simix_rdv_management
609  *  \brief Destroy a rendez-vous point
610  *  \param rdv The rendez-vous point to destroy
611  */
612 void simcall_rdv_destroy(smx_rdv_t rdv)
613 {
614   simcall_BODY_rdv_destroy(rdv);
615 }
616 /**
617  *  \ingroup simix_rdv_management
618  *  \brief Returns a rendez-vous point knowing its name
619  */
620 smx_rdv_t simcall_rdv_get_by_name(const char *name)
621 {
622   xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
623
624   /* FIXME: this is a horrible loss of performance, so we hack it out by
625    * skipping the simcall (for now). It works in parallel, it won't work on
626    * distributed but probably we will change MSG for that. */
627
628   /*
629   smx_simcall_t simcall = simcall_mine();
630   simcall->call = SIMCALL_RDV_GEY_BY_NAME;
631   simcall->rdv_get_by_name.name = name;
632   SIMIX_simcall_push(simcall->issuer);
633   return simcall->rdv_get_by_name.result;*/
634
635   return SIMIX_rdv_get_by_name(name);
636 }
637
638 /**
639  *  \ingroup simix_rdv_management
640  *  \brief Counts the number of communication actions of a given host pending
641  *         on a rendez-vous point.
642  *  \param rdv The rendez-vous point
643  *  \param host The host to be counted
644  *  \return The number of comm actions pending in the rdv
645  */
646 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
647 {
648   return simcall_BODY_rdv_comm_count_by_host(rdv, host);
649 }
650
651 /**
652  *  \ingroup simix_rdv_management
653  *  \brief returns the communication at the head of the rendez-vous
654  *  \param rdv The rendez-vous point
655  *  \return The communication or NULL if empty
656  */
657 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
658 {
659   return simcall_BODY_rdv_get_head(rdv);
660 }
661
662 void simcall_rdv_set_receiver(smx_rdv_t rdv, smx_process_t process)
663 {
664   simcall_BODY_rdv_set_receiver(rdv, process);
665 }
666
667 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
668 {
669   return simcall_BODY_rdv_get_receiver(rdv);
670 }
671
672 /**
673  * \ingroup simix_comm_management
674  */
675 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
676                          void *src_buff, size_t src_buff_size,
677                          int (*match_fun)(void *, void *, smx_action_t), void *data,
678                          double timeout)
679 {
680   /* checking for infinite values */
681   xbt_assert(isfinite(task_size), "task_size is not finite!");
682   xbt_assert(isfinite(rate), "rate is not finite!");
683   xbt_assert(isfinite(timeout), "timeout is not finite!");
684   
685   xbt_assert(rdv, "No rendez-vous point defined for send");
686
687   if (MC_is_active()) {
688     /* the model-checker wants two separate simcalls */
689     smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
690         src_buff, src_buff_size, match_fun, NULL, data, 0);
691     simcall_comm_wait(comm, timeout);
692   }
693   else {
694     simcall_BODY_comm_send(rdv, task_size, rate, src_buff, src_buff_size,
695                          match_fun, data, timeout);
696   }
697 }
698
699 /**
700  * \ingroup simix_comm_management
701  */
702 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
703                               void *src_buff, size_t src_buff_size,
704                               int (*match_fun)(void *, void *, smx_action_t),
705                               void (*clean_fun)(void *),
706                               void *data,
707                               int detached)
708 {
709   /* checking for infinite values */
710   xbt_assert(isfinite(task_size), "task_size is not finite!");
711   xbt_assert(isfinite(rate), "rate is not finite!");
712   
713   xbt_assert(rdv, "No rendez-vous point defined for isend");
714
715   return simcall_BODY_comm_isend(rdv, task_size, rate, src_buff,
716                                  src_buff_size, match_fun,
717                                  clean_fun, data, detached);
718 }
719 /**
720  * \ingroup simix_comm_management
721  */
722 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
723                          int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
724 {
725   xbt_assert(isfinite(timeout), "timeout is not finite!");
726   xbt_assert(rdv, "No rendez-vous point defined for recv");
727
728   if (MC_is_active()) {
729     /* the model-checker wants two separate simcalls */
730     smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
731         match_fun, data);
732     simcall_comm_wait(comm, timeout);
733   }
734   else {
735     simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
736                            match_fun, data, timeout);
737   }
738 }
739 /**
740  * \ingroup simix_comm_management
741  */
742 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
743                                   int (*match_fun)(void *, void *, smx_action_t), void *data)
744 {
745   xbt_assert(rdv, "No rendez-vous point defined for irecv");
746
747   return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size, 
748                                  match_fun, data);
749 }
750
751
752 /**
753  * \ingroup simix_comm_management
754  */
755 void simcall_comm_recv_bounded(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
756                          int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout, double rate)
757 {
758   xbt_assert(isfinite(timeout), "timeout is not finite!");
759   xbt_assert(rdv, "No rendez-vous point defined for recv");
760
761   if (MC_is_active()) {
762     /* the model-checker wants two separate simcalls */
763     smx_action_t comm = simcall_comm_irecv_bounded(rdv, dst_buff, dst_buff_size,
764         match_fun, data, rate);
765     simcall_comm_wait(comm, timeout);
766   }
767   else {
768     simcall_BODY_comm_recv_bounded(rdv, dst_buff, dst_buff_size,
769                            match_fun, data, timeout, rate);
770   }
771 }
772 /**
773  * \ingroup simix_comm_management
774  */
775 smx_action_t simcall_comm_irecv_bounded(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
776                                   int (*match_fun)(void *, void *, smx_action_t), void *data, double rate)
777 {
778   xbt_assert(rdv, "No rendez-vous point defined for irecv");
779
780   return simcall_BODY_comm_irecv_bounded(rdv, dst_buff, dst_buff_size,
781                                  match_fun, data, rate);
782 }
783
784
785 /**
786  * \ingroup simix_comm_management
787  */
788 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
789                                 int (*match_fun)(void *, void *, smx_action_t), void *data)
790 {
791   xbt_assert(rdv, "No rendez-vous point defined for iprobe");
792
793   return simcall_BODY_comm_iprobe(rdv, src, tag, match_fun, data);
794 }
795
796 void simcall_comm_destroy(smx_action_t comm)
797 {
798   xbt_assert(comm, "Invalid parameter");
799
800   /* FIXME remove this simcall type: comms are auto-destroyed now */
801
802   /*
803   smx_simcall_t simcall = simcall_mine();
804
805   simcall->call = SIMCALL_COMM_DESTROY;
806   simcall->comm_destroy.comm = comm;
807
808   SIMIX_simcall_push(simcall->issuer);
809   */
810 }
811
812 /**
813  * \ingroup simix_comm_management
814  */
815 void simcall_comm_cancel(smx_action_t comm)
816 {
817   simcall_BODY_comm_cancel(comm);
818 }
819
820 /**
821  * \ingroup simix_comm_management
822  */
823 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
824 {
825   return simcall_BODY_comm_waitany(comms);
826 }
827
828 /**
829  * \ingroup simix_comm_management
830  */
831 int simcall_comm_testany(xbt_dynar_t comms)
832 {
833   if (xbt_dynar_is_empty(comms))
834     return -1;
835   return simcall_BODY_comm_testany(comms);
836 }
837
838 /**
839  * \ingroup simix_comm_management
840  */
841 void simcall_comm_wait(smx_action_t comm, double timeout)
842 {
843   xbt_assert(isfinite(timeout), "timeout is not finite!");
844   simcall_BODY_comm_wait(comm, timeout);
845 }
846
847 #ifdef HAVE_TRACING
848 /**
849  * \brief Set the category of an action.
850  *
851  * This functions changes the category only. It calls a surf function.
852  * \param execution The execution action
853  * \param category The tracing category
854  */
855 void simcall_set_category(smx_action_t action, const char *category)
856 {
857   if (category == NULL) {
858     return;
859   }
860   simcall_BODY_set_category(action, category);
861 }
862 #endif
863
864 /**
865  * \ingroup simix_comm_management
866  *
867  */
868 int simcall_comm_test(smx_action_t comm)
869 {
870   return simcall_BODY_comm_test(comm);
871 }
872
873 /**
874  * \ingroup simix_comm_management
875  *
876  */
877 double simcall_comm_get_remains(smx_action_t comm)
878 {
879   return simcall_BODY_comm_get_remains(comm);
880 }
881
882 /**
883  * \ingroup simix_comm_management
884  *
885  */
886 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
887 {
888   return simcall_BODY_comm_get_state(comm);
889 }
890
891 /**
892  * \ingroup simix_comm_management
893  *
894  */
895 void *simcall_comm_get_src_data(smx_action_t comm)
896 {
897   return simcall_BODY_comm_get_src_data(comm);
898 }
899
900 /**
901  * \ingroup simix_comm_management
902  *
903  */
904 void *simcall_comm_get_dst_data(smx_action_t comm)
905 {
906   return simcall_BODY_comm_get_dst_data(comm);
907 }
908
909 /**
910  * \ingroup simix_comm_management
911  *
912  */
913 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
914 {
915   return simcall_BODY_comm_get_src_proc(comm);
916 }
917
918 /**
919  * \ingroup simix_comm_management
920  *
921  */
922 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
923 {
924   return simcall_BODY_comm_get_dst_proc(comm);  
925 }
926
927 #ifdef HAVE_LATENCY_BOUND_TRACKING
928 int simcall_comm_is_latency_bounded(smx_action_t comm)
929 {
930   return simcall_BODY_comm_is_latency_bounded(comm);
931 }
932 #endif
933
934 /**
935  * \ingroup simix_synchro_management
936  *
937  */
938 smx_mutex_t simcall_mutex_init(void)
939 {
940   if(!simix_global) {
941     fprintf(stderr,"You must run MSG_init before using MSG\n"); // We can't use xbt_die since we may get there before the initialization
942     xbt_abort();
943   }
944   return simcall_BODY_mutex_init();
945 }
946
947 /**
948  * \ingroup simix_synchro_management
949  *
950  */
951 void simcall_mutex_destroy(smx_mutex_t mutex)
952 {
953   simcall_BODY_mutex_destroy(mutex);
954 }
955
956 /**
957  * \ingroup simix_synchro_management
958  *
959  */
960 void simcall_mutex_lock(smx_mutex_t mutex)
961 {
962   simcall_BODY_mutex_lock(mutex);  
963 }
964
965 /**
966  * \ingroup simix_synchro_management
967  *
968  */
969 int simcall_mutex_trylock(smx_mutex_t mutex)
970 {
971   return simcall_BODY_mutex_trylock(mutex);  
972 }
973
974 /**
975  * \ingroup simix_synchro_management
976  *
977  */
978 void simcall_mutex_unlock(smx_mutex_t mutex)
979 {
980   simcall_BODY_mutex_unlock(mutex); 
981 }
982
983 /**
984  * \ingroup simix_synchro_management
985  *
986  */
987 smx_cond_t simcall_cond_init(void)
988 {
989   return simcall_BODY_cond_init();
990 }
991
992 /**
993  * \ingroup simix_synchro_management
994  *
995  */
996 void simcall_cond_destroy(smx_cond_t cond)
997 {
998   simcall_BODY_cond_destroy(cond);
999 }
1000
1001 /**
1002  * \ingroup simix_synchro_management
1003  *
1004  */
1005 void simcall_cond_signal(smx_cond_t cond)
1006 {
1007   simcall_BODY_cond_signal(cond);
1008 }
1009
1010 /**
1011  * \ingroup simix_synchro_management
1012  *
1013  */
1014 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1015 {
1016   simcall_BODY_cond_wait(cond, mutex);
1017 }
1018
1019 /**
1020  * \ingroup simix_synchro_management
1021  *
1022  */
1023 void simcall_cond_wait_timeout(smx_cond_t cond,
1024                                  smx_mutex_t mutex,
1025                                  double timeout)
1026 {
1027   xbt_assert(isfinite(timeout), "timeout is not finite!");
1028   simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
1029 }
1030
1031 /**
1032  * \ingroup simix_synchro_management
1033  *
1034  */
1035 void simcall_cond_broadcast(smx_cond_t cond)
1036 {
1037   simcall_BODY_cond_broadcast(cond);
1038 }
1039
1040 /**
1041  * \ingroup simix_synchro_management
1042  *
1043  */
1044 smx_sem_t simcall_sem_init(int capacity)
1045 {
1046   return simcall_BODY_sem_init(capacity);  
1047 }
1048
1049 /**
1050  * \ingroup simix_synchro_management
1051  *
1052  */
1053 void simcall_sem_destroy(smx_sem_t sem)
1054 {
1055   simcall_sem_destroy(sem);
1056 }
1057
1058 /**
1059  * \ingroup simix_synchro_management
1060  *
1061  */
1062 void simcall_sem_release(smx_sem_t sem)
1063 {
1064   simcall_BODY_sem_release(sem);  
1065 }
1066
1067 /**
1068  * \ingroup simix_synchro_management
1069  *
1070  */
1071 int simcall_sem_would_block(smx_sem_t sem)
1072 {
1073   return simcall_BODY_sem_would_block(sem);
1074 }
1075
1076 /**
1077  * \ingroup simix_synchro_management
1078  *
1079  */
1080 void simcall_sem_acquire(smx_sem_t sem)
1081 {
1082   simcall_BODY_sem_acquire(sem);
1083 }
1084
1085 /**
1086  * \ingroup simix_synchro_management
1087  *
1088  */
1089 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1090 {
1091   xbt_assert(isfinite(timeout), "timeout is not finite!");
1092   simcall_BODY_sem_acquire_timeout(sem, timeout);
1093 }
1094
1095 /**
1096  * \ingroup simix_synchro_management
1097  *
1098  */
1099 int simcall_sem_get_capacity(smx_sem_t sem)
1100 {
1101   return simcall_BODY_sem_get_capacity(sem);
1102 }
1103
1104 /**
1105  * \ingroup simix_file_management
1106  *
1107  */
1108 size_t simcall_file_read(void* ptr, size_t size, smx_file_t fd)
1109 {
1110   return simcall_BODY_file_read(ptr, size, fd);
1111 }
1112
1113 /**
1114  * \ingroup simix_file_management
1115  *
1116  */
1117 size_t simcall_file_write(const void* ptr, size_t size,
1118                           smx_file_t fd)
1119 {
1120   return simcall_BODY_file_write(ptr, size, fd);
1121 }
1122
1123 /**
1124  * \ingroup simix_file_management
1125  * \brief
1126  */
1127 smx_file_t simcall_file_open(const char* mount, const char* path)
1128 {
1129   return simcall_BODY_file_open(mount, path);
1130 }
1131
1132 /**
1133  * \ingroup simix_file_management
1134  *
1135  */
1136 int simcall_file_close(smx_file_t fd)
1137 {
1138   return simcall_BODY_file_close(fd);
1139 }
1140
1141 /**
1142  * \ingroup simix_file_management
1143  *
1144  */
1145 int simcall_file_unlink(smx_file_t fd)
1146 {
1147   return simcall_BODY_file_unlink(fd);
1148 }
1149
1150 /**
1151  * \ingroup simix_file_management
1152  *
1153  */
1154 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1155 {
1156   return simcall_BODY_file_ls(mount, path);
1157 }
1158 /**
1159  * \ingroup simix_file_management
1160  *
1161  */
1162 size_t simcall_file_get_size (smx_file_t fd){
1163   return simcall_BODY_file_get_size(fd);
1164 }
1165
1166 #ifdef HAVE_MC
1167
1168 void *simcall_mc_snapshot(void)
1169 {
1170   return simcall_BODY_mc_snapshot();
1171 }
1172
1173 int simcall_mc_compare_snapshots(void *s1, void *s2){ 
1174   return simcall_BODY_mc_compare_snapshots(s1, s2);
1175 }
1176
1177 int simcall_mc_random(void)
1178 {
1179   return simcall_BODY_mc_random();
1180 }
1181
1182
1183 #endif /* HAVE_MC */
1184
1185 /* ****************************************************************************************** */
1186 /* TUTORIAL: New API                                                                          */
1187 /* All functions for simcall                                                                  */
1188 /* ****************************************************************************************** */
1189 int simcall_new_api_fct(const char* param1, double param2){
1190   smx_simcall_t simcall = SIMIX_simcall_mine();
1191   simcall->call = SIMCALL_NEW_API_INIT;
1192   simcall->new_api.param1 = param1;
1193   simcall->new_api.param2 = param2;
1194
1195   SIMIX_simcall_push(simcall->issuer);
1196   return simcall->new_api.result;
1197 }
1198
1199 /* ************************************************************************** */
1200
1201 /** @brief returns a printable string representing a simcall */
1202 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1203   return simcall_names[kind];
1204 }