Logo AND Algorithmique Numérique Distribuée

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