Logo AND Algorithmique Numérique Distribuée

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