Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix a compilation error at SIMIX_vm_shutdown
[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_create(const char *name, smx_host_t phys_host)
286 {
287   return simcall_BODY_vm_create(name, phys_host);
288 }
289
290 void simcall_vm_start(smx_host_t vm)
291 {
292   simcall_BODY_set_vm_state(vm, msg_vm_state_running);
293 }
294
295 void simcall_vm_shutdown(smx_host_t vm)
296 {
297   /* will jump to SIMIX_pre_vm_shutdown */
298   simcall_BODY_vm_shutdown(vm);
299 }
300
301 void simcall_vm_destroy(smx_host_t vm)
302 {
303   /* will jump to SIMIX_pre_vm_destroy */
304   simcall_BODY_vm_destroy(vm);
305 }
306
307 /**
308  * \ingroup simix_process_management
309  * \brief Creates and runs a new SIMIX process.
310  *
311  * The structure and the corresponding thread are created and put in the list of ready processes.
312  *
313  * \param process the process created will be stored in this pointer
314  * \param name a name for the process. It is for user-level information and can be NULL.
315  * \param code the main function of the process
316  * \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.
317  * It can be retrieved with the function \ref simcall_process_get_data.
318  * \param hostname name of the host where the new agent is executed.
319  * \param kill_time time when the process is killed
320  * \param argc first argument passed to \a code
321  * \param argv second argument passed to \a code
322  * \param properties the properties of the process
323  * \param auto_restart either it is autorestarting or not.
324  */
325 void simcall_process_create(smx_process_t *process, const char *name,
326                               xbt_main_func_t code,
327                               void *data,
328                               const char *hostname,
329                               double kill_time,
330                               int argc, char **argv,
331                               xbt_dict_t properties,
332                               int auto_restart)
333 {
334   simcall_BODY_process_create(process, name, code, data, hostname,
335                               kill_time, argc, argv, properties,
336                               auto_restart);
337 }
338
339 /**
340  * \ingroup simix_process_management
341  * \brief Kills a SIMIX process.
342  *
343  * This function simply kills a  process.
344  *
345  * \param process poor victim
346  */
347 void simcall_process_kill(smx_process_t process)
348 {
349   simcall_BODY_process_kill(process);
350 }
351
352 /**
353  * \ingroup simix_process_management
354  * \brief Kills all SIMIX processes.
355  */
356 void simcall_process_killall(void)
357 {
358   simcall_BODY_process_killall();
359 }
360
361 /**
362  * \ingroup simix_process_management
363  * \brief Cleans up a SIMIX process.
364  * \param process poor victim (must have already been killed)
365  */
366 void simcall_process_cleanup(smx_process_t process)
367 {
368   simcall_BODY_process_cleanup(process);
369 }
370
371 /**
372  * \ingroup simix_process_management
373  * \brief Migrates an agent to another location.
374  *
375  * This function changes the value of the host on which \a process is running.
376  *
377  * \param process the process to migrate
378  * \param dest name of the new host
379  */
380 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
381 {
382   simcall_BODY_process_change_host(process, dest);
383 }
384
385 /**
386  * \ingroup simix_process_management
387  * \brief Suspends a process.
388  *
389  * This function suspends the process by suspending the action
390  * it was waiting for completion.
391  *
392  * \param process a SIMIX process
393  */
394 void simcall_process_suspend(smx_process_t process)
395 {
396   xbt_assert(process, "Invalid parameters");
397
398   simcall_BODY_process_suspend(process);
399 }
400
401 /**
402  * \ingroup simix_process_management
403  * \brief Resumes a suspended process.
404  *
405  * This function resumes a suspended process by resuming the action
406  * it was waiting for completion.
407  *
408  * \param process a SIMIX process
409  */
410 void simcall_process_resume(smx_process_t process)
411 {
412   simcall_BODY_process_resume(process);
413 }
414
415 /**
416  * \ingroup simix_process_management
417  * \brief Returns the amount of SIMIX processes in the system
418  *
419  * Maestro internal process is not counted, only user code processes are
420  */
421 int simcall_process_count(void)
422 {
423   return simcall_BODY_process_count();
424 }
425
426 /**
427  * \ingroup simix_process_management
428  * \brief Return the user data of a #smx_process_t.
429  * \param process a SIMIX process
430  * \return the user data of this process
431  */
432 void* simcall_process_get_data(smx_process_t process)
433 {
434   if (process == SIMIX_process_self()) {
435     /* avoid a simcall if this function is called by the process itself */
436     return SIMIX_process_get_data(process);
437   }
438
439   return simcall_BODY_process_get_data(process);
440 }
441
442 /**
443  * \ingroup simix_process_management
444  * \brief Set the user data of a #smx_process_t.
445  *
446  * This functions sets the user data associated to \a process.
447  * \param process SIMIX process
448  * \param data User data
449  */
450 void simcall_process_set_data(smx_process_t process, void *data)
451 {
452   if (process == SIMIX_process_self()) {
453     /* avoid a simcall if this function is called by the process itself */
454     SIMIX_process_self_set_data(process, data);
455   }
456   else {
457     simcall_BODY_process_set_data(process, data);
458   }
459 }
460
461 /**
462  * \ingroup simix_process_management
463  * \brief Set the kill time of a process.
464  * \param process a process
465  * \param kill_time a double
466  */
467 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
468 {
469
470   if (kill_time > SIMIX_get_clock()) {
471     if (simix_global->kill_process_function) {
472       XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
473           sg_host_name(process->smx_host));
474       SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
475     }
476   }
477 }
478
479 /**
480  * \ingroup simix_process_management
481  * \brief Return the location on which an agent is running.
482  *
483  * This functions returns the smx_host_t corresponding to the location on which
484  * \a process is running.
485  * \param process SIMIX process
486  * \return SIMIX host
487  */
488 smx_host_t simcall_process_get_host(smx_process_t process)
489 {
490   return simcall_BODY_process_get_host(process);
491 }
492
493 /**
494  * \ingroup simix_process_management
495  * \brief Return the name of an agent.
496  *
497  * This functions checks whether \a process is a valid pointer or not and return its name.
498  * \param process SIMIX process
499  * \return The process name
500  */
501 const char* simcall_process_get_name(smx_process_t process)
502 {
503   if (process == SIMIX_process_self()) {
504     /* avoid a simcall if this function is called by the process itself */
505     return process->name;
506   }
507   return simcall_BODY_process_get_name(process);
508 }
509
510 /**
511  * \ingroup simix_process_management
512  * \brief Returns true if the process is suspended .
513  *
514  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
515  * \param process SIMIX process
516  * \return 1, if the process is suspended, else 0.
517  */
518 int simcall_process_is_suspended(smx_process_t process)
519 {
520   return  simcall_BODY_process_is_suspended(process);
521 }
522
523 /**
524  * \ingroup simix_process_management
525  * \brief Return the properties
526  *
527  * This functions returns the properties associated with this process
528  */
529 xbt_dict_t simcall_process_get_properties(smx_process_t process)
530 {
531   return simcall_BODY_process_get_properties(process);
532 }
533 /**
534  * \ingroup simix_process_management
535  * \brief Add an on_exit function
536  * Add an on_exit function which will be executed when the process exits/is killed.
537  */
538 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
539 {
540   simcall_BODY_process_on_exit(process, fun, data);
541 }
542 /**
543  * \ingroup simix_process_management
544  * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
545  * Will restart the process when the host comes back up if auto_restart is set to 1.
546  */
547
548 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
549 {
550   simcall_BODY_process_auto_restart_set(process, auto_restart);
551 }
552
553 /**
554  * \ingroup simix_process_management
555  * \brief Restarts the process, killing it and starting it again from scratch.
556  */
557 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
558 {
559   return simcall_BODY_process_restart(process);
560 }
561 /**
562  * \ingroup simix_process_management
563  * \brief Creates a new sleep SIMIX action.
564  *
565  * This function creates a SURF action and allocates the data necessary
566  * to create the SIMIX action. It can raise a host_error exception if the
567  * host crashed. The default SIMIX name of the action is "sleep".
568  *
569  *   \param duration Time duration of the sleep.
570  *   \return A result telling whether the sleep was successful
571  */
572 e_smx_state_t simcall_process_sleep(double duration)
573 {
574   /* checking for infinite values */
575   xbt_assert(isfinite(duration), "duration is not finite!");
576   return simcall_BODY_process_sleep(duration);
577 }
578
579 /**
580  *  \ingroup simix_rdv_management
581  *  \brief Creates a new rendez-vous point
582  *  \param name The name of the rendez-vous point
583  *  \return The created rendez-vous point
584  */
585 smx_rdv_t simcall_rdv_create(const char *name)
586 {
587   return simcall_BODY_rdv_create(name);
588 }
589
590
591 /**
592  *  \ingroup simix_rdv_management
593  *  \brief Destroy a rendez-vous point
594  *  \param rdv The rendez-vous point to destroy
595  */
596 void simcall_rdv_destroy(smx_rdv_t rdv)
597 {
598   simcall_BODY_rdv_destroy(rdv);
599 }
600 /**
601  *  \ingroup simix_rdv_management
602  *  \brief Returns a rendez-vous point knowing its name
603  */
604 smx_rdv_t simcall_rdv_get_by_name(const char *name)
605 {
606   xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
607
608   /* FIXME: this is a horrible lost of performance, so we hack it out by
609    * skipping the simcall (for now). It works in parallel, it won't work on
610    * distributed but probably we will change MSG for that. */
611
612   /*
613   smx_simcall_t simcall = simcall_mine();
614   simcall->call = SIMCALL_RDV_GEY_BY_NAME;
615   simcall->rdv_get_by_name.name = name;
616   SIMIX_simcall_push(simcall->issuer);
617   return simcall->rdv_get_by_name.result;*/
618
619   return SIMIX_rdv_get_by_name(name);
620 }
621
622 /**
623  *  \ingroup simix_rdv_management
624  *  \brief Counts the number of communication actions of a given host pending
625  *         on a rendez-vous point.
626  *  \param rdv The rendez-vous point
627  *  \param host The host to be counted
628  *  \return The number of comm actions pending in the rdv
629  */
630 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
631 {
632   return simcall_BODY_rdv_comm_count_by_host(rdv, host);
633 }
634
635 /**
636  *  \ingroup simix_rdv_management
637  *  \brief returns the communication at the head of the rendez-vous
638  *  \param rdv The rendez-vous point
639  *  \return The communication or NULL if empty
640  */
641 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
642 {
643   return simcall_BODY_rdv_get_head(rdv);
644 }
645
646 void simcall_rdv_set_receiver(smx_rdv_t rdv, smx_process_t process)
647 {
648   simcall_BODY_rdv_set_receiver(rdv, process);
649 }
650
651 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
652 {
653   return simcall_BODY_rdv_get_receiver(rdv);
654 }
655
656 /**
657  * \ingroup simix_comm_management
658  */
659 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
660                          void *src_buff, size_t src_buff_size,
661                          int (*match_fun)(void *, void *, smx_action_t), void *data,
662                          double timeout)
663 {
664   /* checking for infinite values */
665   xbt_assert(isfinite(task_size), "task_size is not finite!");
666   xbt_assert(isfinite(rate), "rate is not finite!");
667   xbt_assert(isfinite(timeout), "timeout is not finite!");
668   
669   xbt_assert(rdv, "No rendez-vous point defined for send");
670
671   if (MC_is_active()) {
672     /* the model-checker wants two separate simcalls */
673     smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
674         src_buff, src_buff_size, match_fun, NULL, data, 0);
675     simcall_comm_wait(comm, timeout);
676   }
677   else {
678     simcall_BODY_comm_send(rdv, task_size, rate, src_buff, src_buff_size,
679                          match_fun, data, timeout);
680   }
681 }
682
683 /**
684  * \ingroup simix_comm_management
685  */
686 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
687                               void *src_buff, size_t src_buff_size,
688                               int (*match_fun)(void *, void *, smx_action_t),
689                               void (*clean_fun)(void *),
690                               void *data,
691                               int detached)
692 {
693   /* checking for infinite values */
694   xbt_assert(isfinite(task_size), "task_size is not finite!");
695   xbt_assert(isfinite(rate), "rate is not finite!");
696   
697   xbt_assert(rdv, "No rendez-vous point defined for isend");
698
699   return simcall_BODY_comm_isend(rdv, task_size, rate, src_buff,
700                                  src_buff_size, match_fun,
701                                  clean_fun, data, detached);
702 }
703 /**
704  * \ingroup simix_comm_management
705  */
706 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
707                          int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
708 {
709   xbt_assert(isfinite(timeout), "timeout is not finite!");
710   xbt_assert(rdv, "No rendez-vous point defined for recv");
711
712   if (MC_is_active()) {
713     /* the model-checker wants two separate simcalls */
714     smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
715         match_fun, data);
716     simcall_comm_wait(comm, timeout);
717   }
718   else {
719     simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
720                            match_fun, data, timeout);
721   }
722 }
723 /**
724  * \ingroup simix_comm_management
725  */
726 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
727                                   int (*match_fun)(void *, void *, smx_action_t), void *data)
728 {
729   xbt_assert(rdv, "No rendez-vous point defined for irecv");
730
731   return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size, 
732                                  match_fun, data);
733 }
734
735
736 /**
737  * \ingroup simix_comm_management
738  */
739 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
740                                 int (*match_fun)(void *, void *, smx_action_t), void *data)
741 {
742   xbt_assert(rdv, "No rendez-vous point defined for iprobe");
743
744   return simcall_BODY_comm_iprobe(rdv, src, tag, match_fun, data);
745 }
746
747 void simcall_comm_destroy(smx_action_t comm)
748 {
749   xbt_assert(comm, "Invalid parameter");
750
751   /* FIXME remove this simcall type: comms are auto-destroyed now */
752
753   /*
754   smx_simcall_t simcall = simcall_mine();
755
756   simcall->call = SIMCALL_COMM_DESTROY;
757   simcall->comm_destroy.comm = comm;
758
759   SIMIX_simcall_push(simcall->issuer);
760   */
761 }
762
763 /**
764  * \ingroup simix_comm_management
765  */
766 void simcall_comm_cancel(smx_action_t comm)
767 {
768   simcall_BODY_comm_cancel(comm);
769 }
770
771 /**
772  * \ingroup simix_comm_management
773  */
774 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
775 {
776   return simcall_BODY_comm_waitany(comms);
777 }
778
779 /**
780  * \ingroup simix_comm_management
781  */
782 int simcall_comm_testany(xbt_dynar_t comms)
783 {
784   if (xbt_dynar_is_empty(comms))
785     return -1;
786   return simcall_BODY_comm_testany(comms);
787 }
788
789 /**
790  * \ingroup simix_comm_management
791  */
792 void simcall_comm_wait(smx_action_t comm, double timeout)
793 {
794   xbt_assert(isfinite(timeout), "timeout is not finite!");
795   simcall_BODY_comm_wait(comm, timeout);
796 }
797
798 #ifdef HAVE_TRACING
799 /**
800  * \brief Set the category of an action.
801  *
802  * This functions changes the category only. It calls a surf function.
803  * \param execution The execution action
804  * \param category The tracing category
805  */
806 void simcall_set_category(smx_action_t action, const char *category)
807 {
808   if (category == NULL) {
809     return;
810   }
811   simcall_BODY_set_category(action, category);
812 }
813 #endif
814
815 /**
816  * \ingroup simix_comm_management
817  *
818  */
819 int simcall_comm_test(smx_action_t comm)
820 {
821   return simcall_BODY_comm_test(comm);
822 }
823
824 /**
825  * \ingroup simix_comm_management
826  *
827  */
828 double simcall_comm_get_remains(smx_action_t comm)
829 {
830   return simcall_BODY_comm_get_remains(comm);
831 }
832
833 /**
834  * \ingroup simix_comm_management
835  *
836  */
837 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
838 {
839   return simcall_BODY_comm_get_state(comm);
840 }
841
842 /**
843  * \ingroup simix_comm_management
844  *
845  */
846 void *simcall_comm_get_src_data(smx_action_t comm)
847 {
848   return simcall_BODY_comm_get_src_data(comm);
849 }
850
851 /**
852  * \ingroup simix_comm_management
853  *
854  */
855 void *simcall_comm_get_dst_data(smx_action_t comm)
856 {
857   return simcall_BODY_comm_get_dst_data(comm);
858 }
859
860 /**
861  * \ingroup simix_comm_management
862  *
863  */
864 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
865 {
866   return simcall_BODY_comm_get_src_proc(comm);
867 }
868
869 /**
870  * \ingroup simix_comm_management
871  *
872  */
873 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
874 {
875   return simcall_BODY_comm_get_dst_proc(comm);  
876 }
877
878 #ifdef HAVE_LATENCY_BOUND_TRACKING
879 int simcall_comm_is_latency_bounded(smx_action_t comm)
880 {
881   return simcall_BODY_comm_is_latency_bounded(comm);
882 }
883 #endif
884
885 /**
886  * \ingroup simix_synchro_management
887  *
888  */
889 smx_mutex_t simcall_mutex_init(void)
890 {
891   if(!simix_global) {
892     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
893     xbt_abort();
894   }
895   return simcall_BODY_mutex_init();
896 }
897
898 /**
899  * \ingroup simix_synchro_management
900  *
901  */
902 void simcall_mutex_destroy(smx_mutex_t mutex)
903 {
904   simcall_BODY_mutex_destroy(mutex);
905 }
906
907 /**
908  * \ingroup simix_synchro_management
909  *
910  */
911 void simcall_mutex_lock(smx_mutex_t mutex)
912 {
913   simcall_BODY_mutex_lock(mutex);  
914 }
915
916 /**
917  * \ingroup simix_synchro_management
918  *
919  */
920 int simcall_mutex_trylock(smx_mutex_t mutex)
921 {
922   return simcall_BODY_mutex_trylock(mutex);  
923 }
924
925 /**
926  * \ingroup simix_synchro_management
927  *
928  */
929 void simcall_mutex_unlock(smx_mutex_t mutex)
930 {
931   simcall_BODY_mutex_unlock(mutex); 
932 }
933
934 /**
935  * \ingroup simix_synchro_management
936  *
937  */
938 smx_cond_t simcall_cond_init(void)
939 {
940   return simcall_BODY_cond_init();
941 }
942
943 /**
944  * \ingroup simix_synchro_management
945  *
946  */
947 void simcall_cond_destroy(smx_cond_t cond)
948 {
949   simcall_BODY_cond_destroy(cond);
950 }
951
952 /**
953  * \ingroup simix_synchro_management
954  *
955  */
956 void simcall_cond_signal(smx_cond_t cond)
957 {
958   simcall_BODY_cond_signal(cond);
959 }
960
961 /**
962  * \ingroup simix_synchro_management
963  *
964  */
965 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
966 {
967   simcall_BODY_cond_wait(cond, mutex);
968 }
969
970 /**
971  * \ingroup simix_synchro_management
972  *
973  */
974 void simcall_cond_wait_timeout(smx_cond_t cond,
975                                  smx_mutex_t mutex,
976                                  double timeout)
977 {
978   xbt_assert(isfinite(timeout), "timeout is not finite!");
979   simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
980 }
981
982 /**
983  * \ingroup simix_synchro_management
984  *
985  */
986 void simcall_cond_broadcast(smx_cond_t cond)
987 {
988   simcall_BODY_cond_broadcast(cond);
989 }
990
991 /**
992  * \ingroup simix_synchro_management
993  *
994  */
995 smx_sem_t simcall_sem_init(int capacity)
996 {
997   return simcall_BODY_sem_init(capacity);  
998 }
999
1000 /**
1001  * \ingroup simix_synchro_management
1002  *
1003  */
1004 void simcall_sem_destroy(smx_sem_t sem)
1005 {
1006   simcall_sem_destroy(sem);
1007 }
1008
1009 /**
1010  * \ingroup simix_synchro_management
1011  *
1012  */
1013 void simcall_sem_release(smx_sem_t sem)
1014 {
1015   simcall_BODY_sem_release(sem);  
1016 }
1017
1018 /**
1019  * \ingroup simix_synchro_management
1020  *
1021  */
1022 int simcall_sem_would_block(smx_sem_t sem)
1023 {
1024   return simcall_BODY_sem_would_block(sem);
1025 }
1026
1027 /**
1028  * \ingroup simix_synchro_management
1029  *
1030  */
1031 void simcall_sem_acquire(smx_sem_t sem)
1032 {
1033   simcall_BODY_sem_acquire(sem);
1034 }
1035
1036 /**
1037  * \ingroup simix_synchro_management
1038  *
1039  */
1040 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1041 {
1042   xbt_assert(isfinite(timeout), "timeout is not finite!");
1043   simcall_BODY_sem_acquire_timeout(sem, timeout);
1044 }
1045
1046 /**
1047  * \ingroup simix_synchro_management
1048  *
1049  */
1050 int simcall_sem_get_capacity(smx_sem_t sem)
1051 {
1052   return simcall_BODY_sem_get_capacity(sem);
1053 }
1054
1055 /**
1056  * \ingroup simix_file_management
1057  *
1058  */
1059 double simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1060 {
1061   return simcall_BODY_file_read(ptr, size, nmemb, stream);
1062 }
1063
1064 /**
1065  * \ingroup simix_file_management
1066  *
1067  */
1068 size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1069 {
1070   return simcall_BODY_file_write(ptr, size, nmemb, stream);
1071 }
1072
1073 /**
1074  * \ingroup simix_file_management
1075  * \brief
1076  */
1077 smx_file_t simcall_file_open(const char* mount, const char* path, const char* mode)
1078 {
1079   return simcall_BODY_file_open(mount, path, mode);
1080 }
1081
1082 /**
1083  * \ingroup simix_file_management
1084  *
1085  */
1086 int simcall_file_close(smx_file_t fp)
1087 {
1088   return simcall_BODY_file_close(fp);  
1089 }
1090
1091 /**
1092  * \ingroup simix_file_management
1093  *
1094  */
1095 int simcall_file_stat(smx_file_t fd, s_file_stat_t *buf)
1096 {
1097   return simcall_BODY_file_stat(fd, buf);
1098 }
1099
1100 /**
1101  * \ingroup simix_file_management
1102  *
1103  */
1104 int simcall_file_unlink(smx_file_t fd)
1105 {
1106   return simcall_BODY_file_unlink(fd);
1107 }
1108
1109 /**
1110  * \ingroup simix_file_management
1111  *
1112  */
1113 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1114 {
1115   return simcall_BODY_file_ls(mount, path);
1116 }
1117
1118 #ifdef HAVE_MC
1119
1120 void *simcall_mc_snapshot(void)
1121 {
1122   return simcall_BODY_mc_snapshot();
1123 }
1124
1125 int simcall_mc_compare_snapshots(void *s1, void *s2){ 
1126   return simcall_BODY_mc_compare_snapshots(s1, s2);
1127 }
1128
1129 #endif /* HAVE_MC */
1130
1131 /* ****************************************************************************************** */
1132 /* TUTORIAL: New API                                                                          */
1133 /* All functions for simcall                                                                  */
1134 /* ****************************************************************************************** */
1135 int simcall_new_api_fct(const char* param1, double param2){
1136   smx_simcall_t simcall = SIMIX_simcall_mine();
1137   simcall->call = SIMCALL_NEW_API_INIT;
1138   simcall->new_api.param1 = param1;
1139   simcall->new_api.param2 = param2;
1140
1141   SIMIX_simcall_push(simcall->issuer);
1142   return simcall->new_api.result;
1143 }
1144
1145 /* ************************************************************************** */
1146
1147 /** @brief returns a printable string representing a simcall */
1148 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1149   return simcall_names[kind];
1150 }