Logo AND Algorithmique Numérique Distribuée

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