Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8c08f256905a99cc62d1d75cb72123eef7aad831
[simgrid.git] / src / simix / smx_user.c
1 /* smx_user.c - public interface to simix                                   */
2
3 /* Copyright (c) 2010, 2011. 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 #ifndef _SVID_SOURCE
8 #  define _SVID_SOURCE    /* strdup() */
9 #endif
10 #ifndef _ISOC99_SOURCE
11 #  define _ISOC99_SOURCE  /* isfinite() */
12 #endif
13 #ifndef _ISO_C99_SOURCE
14 #  define _ISO_C99_SOURCE /* isfinite() */
15 #endif
16 #include <math.h>         /* isfinite() */
17
18 #include "smx_private.h"
19 #include "mc/mc.h"
20 #include "xbt/ex.h"
21
22 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
23
24 static const char* simcall_names[] = {
25 #undef SIMCALL_ENUM_ELEMENT
26 #define SIMCALL_ENUM_ELEMENT(x) #x /* generate strings from the enumeration values */
27 SIMCALL_LIST
28 #undef SIMCALL_ENUM_ELEMENT
29 };
30
31 /**
32  * \brief Returns a host given its name.
33  *
34  * \param name The name of the host to get
35  * \return The corresponding host
36  */
37 smx_host_t simcall_host_get_by_name(const char *name)
38 {
39   smx_simcall_t simcall = SIMIX_simcall_mine();
40
41   simcall->call = SIMCALL_HOST_GET_BY_NAME;
42   simcall->host_get_by_name.name = name;
43   SIMIX_simcall_push(simcall->issuer);
44   return simcall->host_get_by_name.result;
45 }
46
47 /**
48  * \brief Returns the name of a host.
49  *
50  * \param host A SIMIX host
51  * \return The name of this host
52  */
53 const char* simcall_host_get_name(smx_host_t host)
54 {
55   smx_simcall_t simcall = SIMIX_simcall_mine();
56
57   simcall->call = SIMCALL_HOST_GET_NAME;
58   simcall->host_get_name.host = host;
59   SIMIX_simcall_push(simcall->issuer);
60   return simcall->host_get_name.result;
61 }
62
63 /**
64  * \brief Returns a dict of the properties assigned to a host.
65  *
66  * \param host A host
67  * \return The properties of this host
68  */
69 xbt_dict_t simcall_host_get_properties(smx_host_t host)
70 {
71   smx_simcall_t simcall = SIMIX_simcall_mine();
72
73   simcall->call = SIMCALL_HOST_GET_PROPERTIES;
74   simcall->host_get_properties.host = host;
75   SIMIX_simcall_push(simcall->issuer);
76   return simcall->host_get_properties.result;
77 }
78
79 /**
80  * \brief Returns the speed of the processor.
81  *
82  * The speed returned does not take into account the current load on the machine.
83  * \param host A SIMIX host
84  * \return The speed of this host (in Mflop/s)
85  */
86 double simcall_host_get_speed(smx_host_t host)
87 {
88   smx_simcall_t simcall = SIMIX_simcall_mine();
89
90   simcall->call = SIMCALL_HOST_GET_SPEED;
91   simcall->host_get_speed.host = host;
92   SIMIX_simcall_push(simcall->issuer);
93   return simcall->host_get_speed.result;
94 }
95
96 /**
97  * \brief Returns the available speed of the processor.
98  *
99  * \return Speed currently available (in Mflop/s)
100  */
101 double simcall_host_get_available_speed(smx_host_t host)
102 {
103   smx_simcall_t simcall = SIMIX_simcall_mine();
104
105   simcall->call = SIMCALL_HOST_GET_AVAILABLE_SPEED;
106   simcall->host_get_available_speed.host = host;
107   SIMIX_simcall_push(simcall->issuer);
108   return simcall->host_get_available_speed.result;
109 }
110
111 /**
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   smx_simcall_t simcall = SIMIX_simcall_mine();
121
122   simcall->call = SIMCALL_HOST_GET_STATE;
123   simcall->host_get_state.host = host;
124   SIMIX_simcall_push(simcall->issuer);
125   return simcall->host_get_state.result;
126 }
127
128 /**
129  * \brief Returns the user data associated to a host.
130  *
131  * \param host SIMIX host
132  * \return the user data of this host
133  */
134 void* simcall_host_get_data(smx_host_t host)
135 {
136   smx_simcall_t simcall = SIMIX_simcall_mine();
137
138   simcall->call = SIMCALL_HOST_GET_DATA;
139   simcall->host_get_data.host = host;
140   SIMIX_simcall_push(simcall->issuer);
141   return simcall->host_get_data.result;
142 }
143
144 /**
145  * \brief Sets the user data associated to a host.
146  *
147  * The host must not have previous user data associated to it.
148  * \param A host SIMIX host
149  * \param data The user data to set
150  */
151 void simcall_host_set_data(smx_host_t host, void *data)
152 {
153   smx_simcall_t simcall = SIMIX_simcall_mine();
154
155   simcall->call = SIMCALL_HOST_SET_DATA;
156   simcall->host_set_data.host = host;
157   simcall->host_set_data.data = data;
158   SIMIX_simcall_push(simcall->issuer);
159 }
160
161 /** \brief Creates an action that executes some computation of an host.
162  *
163  * This function creates a SURF action and allocates the data necessary
164  * to create the SIMIX action. It can raise a host_error exception if the host crashed.
165  *
166  * \param name Name of the execution action to create
167  * \param host SIMIX host where the action will be executed
168  * \param amount Computation amount (in bytes)
169  * \return A new SIMIX execution action
170  */
171 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
172                                     double computation_amount,
173                                     double priority)
174 {
175   /* checking for infinite values */
176   xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
177   xbt_assert(isfinite(priority), "priority is not finite!");
178   
179   smx_simcall_t simcall = SIMIX_simcall_mine();
180
181   simcall->call = SIMCALL_HOST_EXECUTE;
182   simcall->host_execute.name = name;
183   simcall->host_execute.host = host;
184   simcall->host_execute.computation_amount = computation_amount;
185   simcall->host_execute.priority = priority;
186   SIMIX_simcall_push(simcall->issuer);
187   return simcall->host_execute.result;
188 }
189
190 /** \brief Creates an action that may involve parallel computation on
191  * several hosts and communication between them.
192  *
193  * \param name Name of the execution action to create
194  * \param host_nb Number of hosts where the action will be executed
195  * \param host_list Array (of size host_nb) of hosts where the action will be executed
196  * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
197  * \param communication_amount Array (of size host_nb * host_nb) representing the communication
198  * amount between each pair of hosts
199  * \param amount the SURF action amount
200  * \param rate the SURF action rate
201  * \return A new SIMIX execution action
202  */
203 smx_action_t simcall_host_parallel_execute(const char *name,
204                                          int host_nb,
205                                          smx_host_t *host_list,
206                                          double *computation_amount,
207                                          double *communication_amount,
208                                          double amount,
209                                          double rate)
210 {
211   int i,j;
212   /* checking for infinite values */
213   for (i = 0 ; i < host_nb ; ++i) {
214      xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
215      for (j = 0 ; j < host_nb ; ++j) {
216         xbt_assert(isfinite(communication_amount[i + host_nb * j]), 
217                    "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
218      }   
219   }   
220  
221   xbt_assert(isfinite(amount), "amount is not finite!");
222   xbt_assert(isfinite(rate), "rate is not finite!");
223   
224   smx_simcall_t simcall = SIMIX_simcall_mine();
225
226   simcall->call = SIMCALL_HOST_PARALLEL_EXECUTE;
227   simcall->host_parallel_execute.name = name;
228   simcall->host_parallel_execute.host_nb = host_nb;
229   simcall->host_parallel_execute.host_list = host_list;
230   simcall->host_parallel_execute.computation_amount = computation_amount;
231   simcall->host_parallel_execute.communication_amount = communication_amount;
232   simcall->host_parallel_execute.amount = amount;
233   simcall->host_parallel_execute.rate = rate;
234   SIMIX_simcall_push(simcall->issuer);
235   return simcall->host_parallel_execute.result;
236 }
237
238 /**
239  * \brief Destroys an execution action.
240  *
241  * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
242  * \param action The execution action to destroy
243  */
244 void simcall_host_execution_destroy(smx_action_t execution)
245 {
246   smx_simcall_t simcall = SIMIX_simcall_mine();
247
248   simcall->call = SIMCALL_HOST_EXECUTION_DESTROY;
249   simcall->host_execution_destroy.execution = execution;
250   SIMIX_simcall_push(simcall->issuer);
251 }
252
253 /**
254  * \brief Cancels an execution action.
255  *
256  * This functions stops the execution. It calls a surf function.
257  * \param action The execution action to cancel
258  */
259 void simcall_host_execution_cancel(smx_action_t execution)
260 {
261   smx_simcall_t simcall = SIMIX_simcall_mine();
262
263   simcall->call = SIMCALL_HOST_EXECUTION_CANCEL;
264   simcall->host_execution_cancel.execution = execution;
265   SIMIX_simcall_push(simcall->issuer);
266 }
267
268 /**
269  * \brief Returns how much of an execution action remains to be done.
270  *
271  * \param Action The execution action
272  * \return The remaining amount
273  */
274 double simcall_host_execution_get_remains(smx_action_t execution)
275 {
276   smx_simcall_t simcall = SIMIX_simcall_mine();
277
278   simcall->call = SIMCALL_HOST_EXECUTION_GET_REMAINS;
279   simcall->host_execution_get_remains.execution = execution;
280   SIMIX_simcall_push(simcall->issuer);
281   return simcall->host_execution_get_remains.result;
282 }
283
284 /**
285  * \brief Returns the state of an execution action.
286  *
287  * \param execution The execution action
288  * \return The state
289  */
290 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
291 {
292   smx_simcall_t simcall = SIMIX_simcall_mine();
293
294   simcall->call = SIMCALL_HOST_EXECUTION_GET_STATE;
295   simcall->host_execution_get_state.execution = execution;
296   SIMIX_simcall_push(simcall->issuer);
297   return simcall->host_execution_get_state.result;
298 }
299
300 /**
301  * \brief Changes the priority of an execution action.
302  *
303  * This functions changes the priority only. It calls a surf function.
304  * \param execution The execution action
305  * \param priority The new priority
306  */
307 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
308 {
309   /* checking for infinite values */
310   xbt_assert(isfinite(priority), "priority is not finite!");
311   
312   smx_simcall_t simcall = SIMIX_simcall_mine();
313
314   simcall->call = SIMCALL_HOST_EXECUTION_SET_PRIORITY;
315   simcall->host_execution_set_priority.execution = execution;
316   simcall->host_execution_set_priority.priority = priority;
317   SIMIX_simcall_push(simcall->issuer);
318 }
319
320 /**
321  * \brief Waits for the completion of an execution action and destroy it.
322  *
323  * \param execution The execution action
324  */
325 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
326 {
327   smx_simcall_t simcall = SIMIX_simcall_mine();
328
329   simcall->call = SIMCALL_HOST_EXECUTION_WAIT;
330   simcall->host_execution_wait.execution = execution;
331   SIMIX_simcall_push(simcall->issuer);
332   return simcall->host_execution_wait.result;
333 }
334
335 /**
336  * \brief Creates and runs a new SIMIX process.
337  *
338  * The structure and the corresponding thread are created and put in the list of ready processes.
339  *
340  * \param process the process created will be stored in this pointer
341  * \param name a name for the process. It is for user-level information and can be NULL.
342  * \param code the main function of the process
343  * \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.
344  * It can be retrieved with the function \ref simcall_process_get_data.
345  * \param hostname name of the host where the new agent is executed.
346  * \param argc first argument passed to \a code
347  * \param argv second argument passed to \a code
348  * \param properties the properties of the process
349  */
350 void simcall_process_create(smx_process_t *process, const char *name,
351                               xbt_main_func_t code,
352                               void *data,
353                               const char *hostname,
354                               int argc, char **argv,
355                               xbt_dict_t properties)
356 {
357   smx_simcall_t simcall = SIMIX_simcall_mine();
358
359   simcall->call = SIMCALL_PROCESS_CREATE;
360   simcall->process_create.process = process;
361   simcall->process_create.name = name;
362   simcall->process_create.code = code;
363   simcall->process_create.data = data;
364   simcall->process_create.hostname = hostname;
365   simcall->process_create.argc = argc;
366   simcall->process_create.argv = argv;
367   simcall->process_create.properties = properties;
368   SIMIX_simcall_push(simcall->issuer);
369 }
370
371 /** \brief Kills a SIMIX process.
372  *
373  * This function simply kills a  process.
374  *
375  * \param process poor victim
376  */
377 void simcall_process_kill(smx_process_t process)
378 {
379   smx_simcall_t simcall = SIMIX_simcall_mine();
380
381   simcall->call = SIMCALL_PROCESS_KILL;
382   simcall->process_kill.process = process;
383   SIMIX_simcall_push(simcall->issuer);
384 }
385
386 /** \brief Kills all SIMIX processes.
387  */
388 void simcall_process_killall(void)
389 {
390   smx_simcall_t simcall = SIMIX_simcall_mine();
391
392   simcall->call = SIMCALL_PROCESS_KILLALL;
393   SIMIX_simcall_push(simcall->issuer);
394 }
395
396 /** \brief Cleans up a SIMIX process.
397  * \param process poor victim (must have already been killed)
398  */
399 void simcall_process_cleanup(smx_process_t process)
400 {
401   smx_simcall_t simcall = SIMIX_simcall_mine();
402
403   simcall->call = SIMCALL_PROCESS_CLEANUP;
404   simcall->process_cleanup.process = process;
405   SIMIX_simcall_push(simcall->issuer);
406 }
407
408 /**
409  * \brief Migrates an agent to another location.
410  *
411  * This function changes the value of the host on which \a process is running.
412  *
413  * \param process the process to migrate
414  * \param source name of the previous host
415  * \param dest name of the new host
416  */
417 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
418 {
419   smx_simcall_t simcall = SIMIX_simcall_mine();
420
421   simcall->call = SIMCALL_PROCESS_CHANGE_HOST;
422   simcall->process_change_host.process = process;
423   simcall->process_change_host.dest = dest;
424   SIMIX_simcall_push(simcall->issuer);
425 }
426
427 /**
428  * \brief Suspends a process.
429  *
430  * This function suspends the process by suspending the action
431  * it was waiting for completion.
432  *
433  * \param process a SIMIX process
434  */
435 void simcall_process_suspend(smx_process_t process)
436 {
437   xbt_assert(process, "Invalid parameters");
438
439   smx_simcall_t simcall = SIMIX_simcall_mine();
440
441   simcall->call = SIMCALL_PROCESS_SUSPEND;
442   simcall->process_suspend.process = process;
443   SIMIX_simcall_push(simcall->issuer);
444 }
445
446 /**
447  * \brief Resumes a suspended process.
448  *
449  * This function resumes a suspended process by resuming the action
450  * it was waiting for completion.
451  *
452  * \param process a SIMIX process
453  */
454 void simcall_process_resume(smx_process_t process)
455 {
456   smx_simcall_t simcall = SIMIX_simcall_mine();
457
458   simcall->call = SIMCALL_PROCESS_RESUME;
459   simcall->process_resume.process = process;
460   SIMIX_simcall_push(simcall->issuer);
461 }
462
463 /**
464  * \brief Returns the amount of SIMIX processes in the system
465  *
466  * Maestro internal process is not counted, only user code processes are
467  */
468 int simcall_process_count(void)
469 {
470   smx_simcall_t simcall = SIMIX_simcall_mine();
471
472   simcall->call = SIMCALL_PROCESS_COUNT;
473   SIMIX_simcall_push(simcall->issuer);
474   return simcall->process_count.result;
475 }
476
477 /**
478  * \brief Return the user data of a #smx_process_t.
479  * \param process a SIMIX process
480  * \return the user data of this process
481  */
482 void* simcall_process_get_data(smx_process_t process)
483 {
484   if (process == SIMIX_process_self()) {
485     /* avoid a simcall if this function is called by the process itself */
486     return SIMIX_process_get_data(process);
487   }
488
489   smx_simcall_t simcall = SIMIX_simcall_mine();
490
491   simcall->call = SIMCALL_PROCESS_GET_DATA;
492   simcall->process_get_data.process = process;
493   SIMIX_simcall_push(simcall->issuer);
494   return simcall->process_get_data.result;
495 }
496
497 /**
498  * \brief Set the user data of a #m_process_t.
499  *
500  * This functions checks whether \a process is a valid pointer or not and set the user data associated to \a process if it is possible.
501  * \param process SIMIX process
502  * \param data User data
503  */
504 void simcall_process_set_data(smx_process_t process, void *data)
505 {
506   if (process == SIMIX_process_self()) {
507     /* avoid a simcall if this function is called by the process itself */
508     SIMIX_process_self_set_data(process, data);
509   }
510   else {
511
512     smx_simcall_t simcall = SIMIX_simcall_mine();
513
514     simcall->call = SIMCALL_PROCESS_SET_DATA;
515     simcall->process_set_data.process = process;
516     simcall->process_set_data.data = data;
517     SIMIX_simcall_push(simcall->issuer);
518   }
519 }
520
521 /**
522  * \brief Return the location on which an agent is running.
523  *
524  * This functions checks whether \a process is a valid pointer or not and return the m_host_t corresponding to the location on which \a process is running.
525  * \param process SIMIX process
526  * \return SIMIX host
527  */
528 smx_host_t simcall_process_get_host(smx_process_t process)
529 {
530   smx_simcall_t simcall = SIMIX_simcall_mine();
531
532   simcall->call = SIMCALL_PROCESS_GET_HOST;
533   simcall->process_get_host.process = process;
534   SIMIX_simcall_push(simcall->issuer);
535   return simcall->process_get_host.result;
536 }
537
538 /**
539  * \brief Return the name of an agent.
540  *
541  * This functions checks whether \a process is a valid pointer or not and return its name.
542  * \param process SIMIX process
543  * \return The process name
544  */
545 const char* simcall_process_get_name(smx_process_t process)
546 {
547   if (process == SIMIX_process_self()) {
548     /* avoid a simcall if this function is called by the process itself */
549     return process->name;
550   }
551
552   smx_simcall_t simcall = SIMIX_simcall_mine();
553
554   simcall->call = SIMCALL_PROCESS_GET_NAME;
555   simcall->process_get_name.process = process;
556   SIMIX_simcall_push(simcall->issuer);
557   return simcall->process_get_name.result;
558 }
559
560 /**
561  * \brief Returns true if the process is suspended .
562  *
563  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
564  * \param process SIMIX process
565  * \return 1, if the process is suspended, else 0.
566  */
567 int simcall_process_is_suspended(smx_process_t process)
568 {
569   smx_simcall_t simcall = SIMIX_simcall_mine();
570
571   simcall->call = SIMCALL_PROCESS_IS_SUSPENDED;
572   simcall->process_is_suspended.process = process;
573   SIMIX_simcall_push(simcall->issuer);
574   return simcall->process_is_suspended.result;
575 }
576
577 /** \ingroup m_process_management
578  * \brief Return the properties
579  *
580  * This functions returns the properties associated with this process
581  */
582 xbt_dict_t simcall_process_get_properties(smx_process_t process)
583 {
584   smx_simcall_t simcall = SIMIX_simcall_mine();
585
586   simcall->call = SIMCALL_PROCESS_GET_PROPERTIES;
587   simcall->process_get_properties.process = process;
588   SIMIX_simcall_push(simcall->issuer);
589   return simcall->process_get_properties.result;
590 }
591
592 /** \brief Creates a new sleep SIMIX action.
593  *
594  * This function creates a SURF action and allocates the data necessary
595  * to create the SIMIX action. It can raise a host_error exception if the
596  * host crashed. The default SIMIX name of the action is "sleep".
597  *
598  *      \param duration Time duration of the sleep.
599  *      \return A result telling whether the sleep was successful
600  */
601 e_smx_state_t simcall_process_sleep(double duration)
602 {
603   /* checking for infinite values */
604   xbt_assert(isfinite(duration), "duration is not finite!");
605   
606   smx_simcall_t simcall = SIMIX_simcall_mine();
607
608   simcall->call = SIMCALL_PROCESS_SLEEP;
609   simcall->process_sleep.duration = duration;
610   SIMIX_simcall_push(simcall->issuer);
611   return simcall->process_sleep.result;
612 }
613
614 /**
615  *  \brief Creates a new rendez-vous point
616  *  \param name The name of the rendez-vous point
617  *  \return The created rendez-vous point
618  */
619 smx_rdv_t simcall_rdv_create(const char *name)
620 {
621   smx_simcall_t simcall = SIMIX_simcall_mine();
622
623   simcall->call = SIMCALL_RDV_CREATE;
624   simcall->rdv_create.name = name;
625
626   SIMIX_simcall_push(simcall->issuer);
627   return simcall->rdv_create.result;
628 }
629
630
631 /**
632  *  \brief Destroy a rendez-vous point
633  *  \param name The rendez-vous point to destroy
634  */
635 void simcall_rdv_destroy(smx_rdv_t rdv)
636 {
637   smx_simcall_t simcall = SIMIX_simcall_mine();
638
639   simcall->call = SIMCALL_RDV_DESTROY;
640   simcall->rdv_destroy.rdv = rdv;
641
642   SIMIX_simcall_push(simcall->issuer);
643 }
644
645 smx_rdv_t simcall_rdv_get_by_name(const char *name)
646 {
647   xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
648
649   /* FIXME: this is a horrible lost of performance, so we hack it out by
650    * skipping the simcall (for now). It works in parallel, it won't work on
651    * distributed but probably we will change MSG for that. */
652
653   /*
654   smx_simcall_t simcall = simcall_mine();
655   simcall->call = SIMCALL_RDV_GEY_BY_NAME;
656   simcall->rdv_get_by_name.name = name;
657   SIMIX_simcall_push(simcall->issuer);
658   return simcall->rdv_get_by_name.result;*/
659
660   return SIMIX_rdv_get_by_name(name);
661 }
662
663 /**
664  *  \brief Counts the number of communication actions of a given host pending
665  *         on a rendez-vous point.
666  *  \param rdv The rendez-vous point
667  *  \param host The host to be counted
668  *  \return The number of comm actions pending in the rdv
669  */
670 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
671 {
672   smx_simcall_t simcall = SIMIX_simcall_mine();
673
674   simcall->call = SIMCALL_RDV_COMM_COUNT_BY_HOST;
675   simcall->rdv_comm_count_by_host.rdv = rdv;
676   simcall->rdv_comm_count_by_host.host = host;
677
678   SIMIX_simcall_push(simcall->issuer);
679   return simcall->rdv_comm_count_by_host.result;
680 }
681
682 /**
683  *  \brief returns the communication at the head of the rendez-vous
684  *  \param rdv The rendez-vous point
685  *  \return The communication or NULL if empty
686  */
687 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
688 {
689   smx_simcall_t simcall = SIMIX_simcall_mine();
690
691   simcall->call = SIMCALL_RDV_GET_HEAD;
692   simcall->rdv_get_head.rdv = rdv;
693
694   SIMIX_simcall_push(simcall->issuer);
695   return simcall->rdv_get_head.result;
696 }
697
698 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
699                          void *src_buff, size_t src_buff_size,
700                          int (*match_fun)(void *, void *), void *data,
701                          double timeout)
702 {
703   /* checking for infinite values */
704   xbt_assert(isfinite(task_size), "task_size is not finite!");
705   xbt_assert(isfinite(rate), "rate is not finite!");
706   xbt_assert(isfinite(timeout), "timeout is not finite!");
707   
708   xbt_assert(rdv, "No rendez-vous point defined for send");
709
710   if (MC_IS_ENABLED) {
711     /* the model-checker wants two separate simcalls */
712     smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
713         src_buff, src_buff_size, match_fun, NULL, data, 0);
714     simcall_comm_wait(comm, timeout);
715   }
716   else {
717     smx_simcall_t simcall = SIMIX_simcall_mine();
718
719     simcall->call = SIMCALL_COMM_SEND;
720     simcall->comm_send.rdv = rdv;
721     simcall->comm_send.task_size = task_size;
722     simcall->comm_send.rate = rate;
723     simcall->comm_send.src_buff = src_buff;
724     simcall->comm_send.src_buff_size = src_buff_size;
725     simcall->comm_send.match_fun = match_fun;
726     simcall->comm_send.data = data;
727     simcall->comm_send.timeout = timeout;
728
729     SIMIX_simcall_push(simcall->issuer);
730   }
731 }
732
733 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
734                               void *src_buff, size_t src_buff_size,
735                               int (*match_fun)(void *, void *),
736                               void (*clean_fun)(void *),
737                               void *data,
738                               int detached)
739 {
740   /* checking for infinite values */
741   xbt_assert(isfinite(task_size), "task_size is not finite!");
742   xbt_assert(isfinite(rate), "rate is not finite!");
743   
744   xbt_assert(rdv, "No rendez-vous point defined for isend");
745
746   smx_simcall_t simcall = SIMIX_simcall_mine();
747
748   simcall->call = SIMCALL_COMM_ISEND;
749   simcall->comm_isend.rdv = rdv;
750   simcall->comm_isend.task_size = task_size;
751   simcall->comm_isend.rate = rate;
752   simcall->comm_isend.src_buff = src_buff;
753   simcall->comm_isend.src_buff_size = src_buff_size;
754   simcall->comm_isend.match_fun = match_fun;
755   simcall->comm_isend.clean_fun = clean_fun;
756   simcall->comm_isend.data = data;
757   simcall->comm_isend.detached = detached;
758
759   SIMIX_simcall_push(simcall->issuer);
760   return simcall->comm_isend.result;
761 }
762
763 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
764                          int (*match_fun)(void *, void *), void *data, double timeout)
765 {
766   xbt_assert(isfinite(timeout), "timeout is not finite!");
767   xbt_assert(rdv, "No rendez-vous point defined for recv");
768
769   if (MC_IS_ENABLED) {
770     /* the model-checker wants two separate simcalls */
771     smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
772         match_fun, data);
773     simcall_comm_wait(comm, timeout);
774   }
775   else {
776     smx_simcall_t simcall = SIMIX_simcall_mine();
777
778     simcall->call = SIMCALL_COMM_RECV;
779     simcall->comm_recv.rdv = rdv;
780     simcall->comm_recv.dst_buff = dst_buff;
781     simcall->comm_recv.dst_buff_size = dst_buff_size;
782     simcall->comm_recv.match_fun = match_fun;
783     simcall->comm_recv.data = data;
784     simcall->comm_recv.timeout = timeout;
785
786     SIMIX_simcall_push(simcall->issuer);
787   }
788 }
789
790 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
791                                   int (*match_fun)(void *, void *), void *data)
792 {
793   xbt_assert(rdv, "No rendez-vous point defined for irecv");
794
795   smx_simcall_t simcall = SIMIX_simcall_mine();
796
797   simcall->call = SIMCALL_COMM_IRECV;
798   simcall->comm_irecv.rdv = rdv;
799   simcall->comm_irecv.dst_buff = dst_buff;
800   simcall->comm_irecv.dst_buff_size = dst_buff_size;
801   simcall->comm_irecv.match_fun = match_fun;
802   simcall->comm_irecv.data = data;
803
804   SIMIX_simcall_push(simcall->issuer);
805   return simcall->comm_irecv.result;
806 }
807
808 void simcall_comm_destroy(smx_action_t comm)
809 {
810   xbt_assert(comm, "Invalid parameter");
811
812   /* FIXME remove this simcall type: comms are auto-destroyed now */
813
814   /*
815   smx_simcall_t simcall = simcall_mine();
816
817   simcall->call = SIMCALL_COMM_DESTROY;
818   simcall->comm_destroy.comm = comm;
819
820   SIMIX_simcall_push(simcall->issuer);
821   */
822 }
823
824 void simcall_comm_cancel(smx_action_t comm)
825 {
826   smx_simcall_t simcall = SIMIX_simcall_mine();
827
828   simcall->call = SIMCALL_COMM_CANCEL;
829   simcall->comm_cancel.comm = comm;
830
831   SIMIX_simcall_push(simcall->issuer);
832 }
833
834 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
835 {
836   smx_simcall_t simcall = SIMIX_simcall_mine();
837
838   simcall->call = SIMCALL_COMM_WAITANY;
839   simcall->comm_waitany.comms = comms;
840
841   SIMIX_simcall_push(simcall->issuer);
842   return simcall->comm_waitany.result;
843 }
844
845 int simcall_comm_testany(xbt_dynar_t comms)
846 {
847   smx_simcall_t simcall = SIMIX_simcall_mine();
848   if (xbt_dynar_is_empty(comms))
849     return -1;
850
851   simcall->call = SIMCALL_COMM_TESTANY;
852   simcall->comm_testany.comms = comms;
853
854   SIMIX_simcall_push(simcall->issuer);
855   return simcall->comm_testany.result;
856 }
857
858 void simcall_comm_wait(smx_action_t comm, double timeout)
859 {
860   xbt_assert(isfinite(timeout), "timeout is not finite!");
861   
862   smx_simcall_t simcall = SIMIX_simcall_mine();
863
864   simcall->call = SIMCALL_COMM_WAIT;
865   simcall->comm_wait.comm = comm;
866   simcall->comm_wait.timeout = timeout;
867
868   SIMIX_simcall_push(simcall->issuer);
869 }
870
871 #ifdef HAVE_TRACING
872 /**
873  * \brief Set the category of an action.
874  *
875  * This functions changes the category only. It calls a surf function.
876  * \param execution The execution action
877  * \param category The tracing category
878  */
879 void simcall_set_category(smx_action_t action, const char *category)
880 {
881   if (category == NULL) {
882     return;
883   }
884
885   smx_simcall_t simcall = SIMIX_simcall_mine();
886
887   simcall->call = SIMCALL_SET_CATEGORY;
888   simcall->set_category.action = action;
889   simcall->set_category.category = category;
890
891   SIMIX_simcall_push(simcall->issuer);
892 }
893 #endif
894
895 int simcall_comm_test(smx_action_t comm)
896 {
897   smx_simcall_t simcall = SIMIX_simcall_mine();
898
899   simcall->call = SIMCALL_COMM_TEST;
900   simcall->comm_test.comm = comm;
901
902   SIMIX_simcall_push(simcall->issuer);
903   return simcall->comm_test.result;
904 }
905
906 double simcall_comm_get_remains(smx_action_t comm)
907 {
908   smx_simcall_t simcall = SIMIX_simcall_mine();
909
910   simcall->call = SIMCALL_COMM_GET_REMAINS;
911   simcall->comm_get_remains.comm = comm;
912
913   SIMIX_simcall_push(simcall->issuer);
914   return simcall->comm_get_remains.result;
915 }
916
917 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
918 {
919   smx_simcall_t simcall = SIMIX_simcall_mine();
920
921   simcall->call = SIMCALL_COMM_GET_STATE;
922   simcall->comm_get_state.comm = comm;
923
924   SIMIX_simcall_push(simcall->issuer);
925   return simcall->comm_get_state.result;
926 }
927
928 void *simcall_comm_get_src_data(smx_action_t comm)
929 {
930   smx_simcall_t simcall = SIMIX_simcall_mine();
931
932   simcall->call = SIMCALL_COMM_GET_SRC_DATA;
933   simcall->comm_get_src_data.comm = comm;
934
935   SIMIX_simcall_push(simcall->issuer);
936   return simcall->comm_get_src_data.result;
937 }
938
939 void *simcall_comm_get_dst_data(smx_action_t comm)
940 {
941   smx_simcall_t simcall = SIMIX_simcall_mine();
942
943   simcall->call = SIMCALL_COMM_GET_DST_DATA;
944   simcall->comm_get_dst_data.comm = comm;
945
946   SIMIX_simcall_push(simcall->issuer);
947   return simcall->comm_get_dst_data.result;
948 }
949
950 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
951 {
952   smx_simcall_t simcall = SIMIX_simcall_mine();
953
954   simcall->call = SIMCALL_COMM_GET_SRC_PROC;
955   simcall->comm_get_src_proc.comm = comm;
956
957   SIMIX_simcall_push(simcall->issuer);
958   return simcall->comm_get_src_proc.result;
959 }
960
961 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
962 {
963   smx_simcall_t simcall = SIMIX_simcall_mine();
964
965   simcall->call = SIMCALL_COMM_GET_DST_PROC;
966   simcall->comm_get_dst_proc.comm = comm;
967
968   SIMIX_simcall_push(simcall->issuer);
969   return simcall->comm_get_dst_proc.result;
970 }
971
972 #ifdef HAVE_LATENCY_BOUND_TRACKING
973 int simcall_comm_is_latency_bounded(smx_action_t comm)
974 {
975   smx_simcall_t simcall = SIMIX_simcall_mine();
976
977   simcall->call = SIMCALL_COMM_IS_LATENCY_BOUNDED;
978   simcall->comm_is_latency_bounded.comm = comm;
979
980   SIMIX_simcall_push(simcall->issuer);
981   return simcall->comm_is_latency_bounded.result;
982 }
983 #endif
984
985 smx_mutex_t simcall_mutex_init(void)
986 {
987   smx_simcall_t simcall = SIMIX_simcall_mine();
988
989   simcall->call = SIMCALL_MUTEX_INIT;
990
991   SIMIX_simcall_push(simcall->issuer);
992   return simcall->mutex_init.result;
993 }
994
995 void simcall_mutex_destroy(smx_mutex_t mutex)
996 {
997   smx_simcall_t simcall = SIMIX_simcall_mine();
998
999   simcall->call = SIMCALL_MUTEX_DESTROY;
1000   simcall->mutex_destroy.mutex = mutex;
1001
1002   SIMIX_simcall_push(simcall->issuer);
1003 }
1004
1005 void simcall_mutex_lock(smx_mutex_t mutex)
1006 {
1007   smx_simcall_t simcall = SIMIX_simcall_mine();
1008
1009   simcall->call = SIMCALL_MUTEX_LOCK;
1010   simcall->mutex_lock.mutex = mutex;
1011
1012   SIMIX_simcall_push(simcall->issuer);
1013 }
1014
1015 int simcall_mutex_trylock(smx_mutex_t mutex)
1016 {
1017   smx_simcall_t simcall = SIMIX_simcall_mine();
1018
1019   simcall->call = SIMCALL_MUTEX_TRYLOCK;
1020   simcall->mutex_trylock.mutex = mutex;
1021
1022   SIMIX_simcall_push(simcall->issuer);
1023   return simcall->mutex_trylock.result;
1024 }
1025
1026 void simcall_mutex_unlock(smx_mutex_t mutex)
1027 {
1028   smx_simcall_t simcall = SIMIX_simcall_mine();
1029
1030   simcall->call = SIMCALL_MUTEX_UNLOCK;
1031   simcall->mutex_unlock.mutex = mutex;
1032
1033   SIMIX_simcall_push(simcall->issuer);
1034 }
1035
1036
1037 smx_cond_t simcall_cond_init(void)
1038 {
1039   smx_simcall_t simcall = SIMIX_simcall_mine();
1040
1041   simcall->call = SIMCALL_COND_INIT;
1042
1043   SIMIX_simcall_push(simcall->issuer);
1044   return simcall->cond_init.result;
1045 }
1046
1047 void simcall_cond_destroy(smx_cond_t cond)
1048 {
1049   smx_simcall_t simcall = SIMIX_simcall_mine();
1050
1051   simcall->call = SIMCALL_COND_DESTROY;
1052   simcall->cond_destroy.cond = cond;
1053
1054   SIMIX_simcall_push(simcall->issuer);
1055 }
1056
1057 void simcall_cond_signal(smx_cond_t cond)
1058 {
1059   smx_simcall_t simcall = SIMIX_simcall_mine();
1060
1061   simcall->call = SIMCALL_COND_SIGNAL;
1062   simcall->cond_signal.cond = cond;
1063
1064   SIMIX_simcall_push(simcall->issuer);
1065 }
1066
1067 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1068 {
1069   smx_simcall_t simcall = SIMIX_simcall_mine();
1070
1071   simcall->call = SIMCALL_COND_WAIT;
1072   simcall->cond_wait.cond = cond;
1073   simcall->cond_wait.mutex = mutex;
1074
1075   SIMIX_simcall_push(simcall->issuer);
1076 }
1077
1078 void simcall_cond_wait_timeout(smx_cond_t cond,
1079                                  smx_mutex_t mutex,
1080                                  double timeout)
1081 {
1082   xbt_assert(isfinite(timeout), "timeout is not finite!");
1083   
1084   smx_simcall_t simcall = SIMIX_simcall_mine();
1085
1086   simcall->call = SIMCALL_COND_WAIT_TIMEOUT;
1087   simcall->cond_wait_timeout.cond = cond;
1088   simcall->cond_wait_timeout.mutex = mutex;
1089   simcall->cond_wait_timeout.timeout = timeout;
1090
1091   SIMIX_simcall_push(simcall->issuer);
1092 }
1093
1094 void simcall_cond_broadcast(smx_cond_t cond)
1095 {
1096   smx_simcall_t simcall = SIMIX_simcall_mine();
1097
1098   simcall->call = SIMCALL_COND_BROADCAST;
1099   simcall->cond_broadcast.cond = cond;
1100
1101   SIMIX_simcall_push(simcall->issuer);
1102 }
1103
1104
1105 smx_sem_t simcall_sem_init(int capacity)
1106 {
1107   smx_simcall_t simcall = SIMIX_simcall_mine();
1108
1109   simcall->call = SIMCALL_SEM_INIT;
1110   simcall->sem_init.capacity = capacity;
1111
1112   SIMIX_simcall_push(simcall->issuer);
1113   return simcall->sem_init.result;
1114 }
1115
1116 void simcall_sem_destroy(smx_sem_t sem)
1117 {
1118   smx_simcall_t simcall = SIMIX_simcall_mine();
1119
1120   simcall->call = SIMCALL_SEM_DESTROY;
1121   simcall->sem_destroy.sem = sem;
1122
1123   SIMIX_simcall_push(simcall->issuer);
1124 }
1125
1126 void simcall_sem_release(smx_sem_t sem)
1127 {
1128   smx_simcall_t simcall = SIMIX_simcall_mine();
1129
1130   simcall->call = SIMCALL_SEM_RELEASE;
1131   simcall->sem_release.sem = sem;
1132
1133   SIMIX_simcall_push(simcall->issuer);
1134 }
1135
1136 int simcall_sem_would_block(smx_sem_t sem)
1137 {
1138   smx_simcall_t simcall = SIMIX_simcall_mine();
1139
1140   simcall->call = SIMCALL_SEM_WOULD_BLOCK;
1141   simcall->sem_would_block.sem = sem;
1142
1143   SIMIX_simcall_push(simcall->issuer);
1144   return simcall->sem_would_block.result;
1145 }
1146
1147 void simcall_sem_acquire(smx_sem_t sem)
1148 {
1149   smx_simcall_t simcall = SIMIX_simcall_mine();
1150
1151   simcall->call = SIMCALL_SEM_ACQUIRE;
1152   simcall->sem_acquire.sem = sem;
1153
1154   SIMIX_simcall_push(simcall->issuer);
1155 }
1156
1157 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1158 {
1159   xbt_assert(isfinite(timeout), "timeout is not finite!");
1160   
1161   smx_simcall_t simcall = SIMIX_simcall_mine();
1162
1163   simcall->call = SIMCALL_SEM_ACQUIRE_TIMEOUT;
1164   simcall->sem_acquire_timeout.sem = sem;
1165   simcall->sem_acquire_timeout.timeout = timeout;
1166
1167   SIMIX_simcall_push(simcall->issuer);
1168 }
1169
1170 int simcall_sem_get_capacity(smx_sem_t sem)
1171 {
1172   smx_simcall_t simcall = SIMIX_simcall_mine();
1173
1174   simcall->call = SIMCALL_SEM_GET_CAPACITY;
1175   simcall->sem_get_capacity.sem = sem;
1176
1177   SIMIX_simcall_push(simcall->issuer);
1178   return simcall->sem_get_capacity.result;
1179 }
1180
1181 size_t simcall_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1182 {
1183   smx_simcall_t simcall = SIMIX_simcall_mine();
1184
1185   simcall->call = SIMCALL_FILE_READ;
1186   simcall->file_read.storage = storage;
1187   simcall->file_read.ptr = ptr;
1188   simcall->file_read.size = size;
1189   simcall->file_read.nmemb = nmemb;
1190   simcall->file_read.stream = stream;
1191   SIMIX_simcall_push(simcall->issuer);
1192
1193   return simcall->file_read.result;
1194 }
1195
1196 size_t simcall_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1197 {
1198   smx_simcall_t simcall = SIMIX_simcall_mine();
1199
1200   simcall->call = SIMCALL_FILE_WRITE;
1201   simcall->file_write.storage = storage;
1202   simcall->file_write.ptr = ptr;
1203   simcall->file_write.size = size;
1204   simcall->file_write.nmemb = nmemb;
1205   simcall->file_write.stream = stream;
1206   SIMIX_simcall_push(simcall->issuer);
1207
1208   return simcall->file_write.result;
1209 }
1210
1211 smx_file_t simcall_file_open(const char* storage, const char* path, const char* mode)
1212 {
1213   smx_simcall_t simcall = SIMIX_simcall_mine();
1214
1215   simcall->call = SIMCALL_FILE_OPEN;
1216   simcall->file_open.storage = storage;
1217   simcall->file_open.path = path;
1218   simcall->file_open.mode = mode;
1219   SIMIX_simcall_push(simcall->issuer);
1220
1221   return simcall->file_open.result;
1222 }
1223
1224 int simcall_file_close(const char* storage, smx_file_t fp)
1225 {
1226   smx_simcall_t simcall = SIMIX_simcall_mine();
1227
1228   simcall->call = SIMCALL_FILE_CLOSE;
1229   simcall->file_close.storage = storage;
1230   simcall->file_close.fp = fp;
1231   SIMIX_simcall_push(simcall->issuer);
1232
1233   return simcall->file_close.result;
1234 }
1235
1236 int simcall_file_stat(const char* storage, smx_file_t fd, s_file_stat_t *buf)
1237 {
1238   smx_simcall_t simcall = SIMIX_simcall_mine();
1239   simcall->call = SIMCALL_FILE_STAT;
1240   simcall->file_stat.storage = storage;
1241   simcall->file_stat.fd = fd;
1242
1243   SIMIX_simcall_push(simcall->issuer);
1244
1245   *buf = simcall->file_stat.buf;
1246
1247   return simcall->file_stat.result;
1248 }
1249
1250 /* ************************************************************************** */
1251
1252 /** @brief returns a printable string representing a simcall */
1253 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1254   return simcall_names[kind];
1255 }