Logo AND Algorithmique Numérique Distribuée

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