Logo AND Algorithmique Numérique Distribuée

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