Logo AND Algorithmique Numérique Distribuée

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