Logo AND Algorithmique Numérique Distribuée

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