Logo AND Algorithmique Numérique Distribuée

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