Logo AND Algorithmique Numérique Distribuée

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