Logo AND Algorithmique Numérique Distribuée

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