Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
615d7aa554eec38758f4d6e094e29ca5a2ea703b
[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
8 #define _ISOC99_SOURCE /* isfinite() */
9 #include <math.h> /* isfinite() */
10
11 #include "private.h"
12 #include "mc/mc.h"
13
14
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
16
17 static const char* request_names[] = {
18 #undef SIMIX_REQ_ENUM_ELEMENT
19 #define SIMIX_REQ_ENUM_ELEMENT(x) #x /* generate strings from the enumeration values */
20 SIMIX_REQ_LIST
21 #undef SIMIX_REQ_ENUM_ELEMENT
22 };
23
24 /**
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 SIMIX_req_host_get_by_name(const char *name)
31 {
32   smx_req_t req = SIMIX_req_mine();
33
34   req->call = REQ_HOST_GET_BY_NAME;
35   req->host_get_by_name.name = name;
36   SIMIX_request_push();
37   return req->host_get_by_name.result;
38 }
39
40 /**
41  * \brief Returns the name of a host.
42  *
43  * \param host A SIMIX host
44  * \return The name of this host
45  */
46 const char* SIMIX_req_host_get_name(smx_host_t host)
47 {
48   smx_req_t req = SIMIX_req_mine();
49
50   req->call = REQ_HOST_GET_NAME;
51   req->host_get_name.host = host;
52   SIMIX_request_push();
53   return req->host_get_name.result;
54 }
55
56 /**
57  * \brief Returns a dict of the properties assigned to a host.
58  *
59  * \param host A host
60  * \return The properties of this host
61  */
62 xbt_dict_t SIMIX_req_host_get_properties(smx_host_t host)
63 {
64   smx_req_t req = SIMIX_req_mine();
65
66   req->call = REQ_HOST_GET_PROPERTIES;
67   req->host_get_properties.host = host;
68   SIMIX_request_push();
69   return req->host_get_properties.result;
70 }
71
72 /**
73  * \brief Returns the speed of the processor.
74  *
75  * The speed returned does not take into account the current load on the machine.
76  * \param host A SIMIX host
77  * \return The speed of this host (in Mflop/s)
78  */
79 double SIMIX_req_host_get_speed(smx_host_t host)
80 {
81   smx_req_t req = SIMIX_req_mine();
82
83   req->call = REQ_HOST_GET_SPEED;
84   req->host_get_speed.host = host;
85   SIMIX_request_push();
86   return req->host_get_speed.result;
87 }
88
89 /**
90  * \brief Returns the available speed of the processor.
91  *
92  * \return Speed currently available (in Mflop/s)
93  */
94 double SIMIX_req_host_get_available_speed(smx_host_t host)
95 {
96   smx_req_t req = SIMIX_req_mine();
97
98   req->call = REQ_HOST_GET_AVAILABLE_SPEED;
99   req->host_get_available_speed.host = host;
100   SIMIX_request_push();
101   return req->host_get_available_speed.result;
102 }
103
104 /**
105  * \brief Returns the state of a host.
106  *
107  * Two states are possible: 1 if the host is active or 0 if it has crashed.
108  * \param host A SIMIX host
109  * \return 1 if the host is available, 0 otherwise
110  */
111 int SIMIX_req_host_get_state(smx_host_t host)
112 {
113   smx_req_t req = SIMIX_req_mine();
114
115   req->call = REQ_HOST_GET_STATE;
116   req->host_get_state.host = host;
117   SIMIX_request_push();
118   return req->host_get_state.result;
119 }
120
121 /**
122  * \brief Returns the user data associated to a host.
123  *
124  * \param host SIMIX host
125  * \return the user data of this host
126  */
127 void* SIMIX_req_host_get_data(smx_host_t host)
128 {
129   smx_req_t req = SIMIX_req_mine();
130
131   req->call = REQ_HOST_GET_DATA;
132   req->host_get_data.host = host;
133   SIMIX_request_push();
134   return req->host_get_data.result;
135 }
136
137 /**
138  * \brief Sets the user data associated to a host.
139  *
140  * The host must not have previous user data associated to it.
141  * \param A host SIMIX host
142  * \param data The user data to set
143  */
144 void SIMIX_req_host_set_data(smx_host_t host, void *data)
145 {
146   smx_req_t req = SIMIX_req_mine();
147
148   req->call = REQ_HOST_SET_DATA;
149   req->host_set_data.host = host;
150   req->host_set_data.data = data;
151   SIMIX_request_push();
152 }
153
154 /** \brief Creates an action that executes some computation of an host.
155  *
156  * This function creates a SURF action and allocates the data necessary
157  * to create the SIMIX action. It can raise a host_error exception if the host crashed.
158  *
159  * \param name Name of the execution action to create
160  * \param host SIMIX host where the action will be executed
161  * \param amount Computation amount (in bytes)
162  * \return A new SIMIX execution action
163  */
164 smx_action_t SIMIX_req_host_execute(const char *name, smx_host_t host,
165                                     double computation_amount,
166                                     double priority)
167 {
168   /* checking for infinite values */
169   xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
170   xbt_assert(isfinite(priority), "priority is not finite!");
171   
172   smx_req_t req = SIMIX_req_mine();
173
174   req->call = REQ_HOST_EXECUTE;
175   req->host_execute.name = name;
176   req->host_execute.host = host;
177   req->host_execute.computation_amount = computation_amount;
178   req->host_execute.priority = priority;
179   SIMIX_request_push();
180   return req->host_execute.result;
181 }
182
183 /** \brief Creates an action that may involve parallel computation on
184  * several hosts and communication between them.
185  *
186  * \param name Name of the execution action to create
187  * \param host_nb Number of hosts where the action will be executed
188  * \param host_list Array (of size host_nb) of hosts where the action will be executed
189  * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
190  * \param communication_amount Array (of size host_nb * host_nb) representing the communication
191  * amount between each pair of hosts
192  * \param amount the SURF action amount
193  * \param rate the SURF action rate
194  * \return A new SIMIX execution action
195  */
196 smx_action_t SIMIX_req_host_parallel_execute(const char *name,
197                                          int host_nb,
198                                          smx_host_t *host_list,
199                                          double *computation_amount,
200                                          double *communication_amount,
201                                          double amount,
202                                          double rate)
203 {
204   int i,j;
205   /* checking for infinite values */
206   for (i = 0 ; i < host_nb ; ++i) {
207      xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
208      for (j = 0 ; j < host_nb ; ++j) {
209         xbt_assert(isfinite(communication_amount[i + host_nb * j]), 
210                    "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
211      }   
212   }   
213  
214   xbt_assert(isfinite(amount), "amount is not finite!");
215   xbt_assert(isfinite(rate), "rate is not finite!");
216   
217   smx_req_t req = SIMIX_req_mine();
218
219   req->call = REQ_HOST_PARALLEL_EXECUTE;
220   req->host_parallel_execute.name = name;
221   req->host_parallel_execute.host_nb = host_nb;
222   req->host_parallel_execute.host_list = host_list;
223   req->host_parallel_execute.computation_amount = computation_amount;
224   req->host_parallel_execute.communication_amount = communication_amount;
225   req->host_parallel_execute.amount = amount;
226   req->host_parallel_execute.rate = rate;
227   SIMIX_request_push();
228   return req->host_parallel_execute.result;
229 }
230
231 /**
232  * \brief Destroys an execution action.
233  *
234  * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
235  * \param action The execution action to destroy
236  */
237 void SIMIX_req_host_execution_destroy(smx_action_t execution)
238 {
239   smx_req_t req = SIMIX_req_mine();
240
241   req->call = REQ_HOST_EXECUTION_DESTROY;
242   req->host_execution_destroy.execution = execution;
243   SIMIX_request_push();
244 }
245
246 /**
247  * \brief Cancels an execution action.
248  *
249  * This functions stops the execution. It calls a surf function.
250  * \param action The execution action to cancel
251  */
252 void SIMIX_req_host_execution_cancel(smx_action_t execution)
253 {
254   smx_req_t req = SIMIX_req_mine();
255
256   req->call = REQ_HOST_EXECUTION_CANCEL;
257   req->host_execution_cancel.execution = execution;
258   SIMIX_request_push();
259 }
260
261 /**
262  * \brief Returns how much of an execution action remains to be done.
263  *
264  * \param Action The execution action
265  * \return The remaining amount
266  */
267 double SIMIX_req_host_execution_get_remains(smx_action_t execution)
268 {
269   smx_req_t req = SIMIX_req_mine();
270
271   req->call = REQ_HOST_EXECUTION_GET_REMAINS;
272   req->host_execution_get_remains.execution = execution;
273   SIMIX_request_push();
274   return req->host_execution_get_remains.result;
275 }
276
277 /**
278  * \brief Returns the state of an execution action.
279  *
280  * \param execution The execution action
281  * \return The state
282  */
283 e_smx_state_t SIMIX_req_host_execution_get_state(smx_action_t execution)
284 {
285   smx_req_t req = SIMIX_req_mine();
286
287   req->call = REQ_HOST_EXECUTION_GET_STATE;
288   req->host_execution_get_state.execution = execution;
289   SIMIX_request_push();
290   return req->host_execution_get_state.result;
291 }
292
293 /**
294  * \brief Changes the priority of an execution action.
295  *
296  * This functions changes the priority only. It calls a surf function.
297  * \param execution The execution action
298  * \param priority The new priority
299  */
300 void SIMIX_req_host_execution_set_priority(smx_action_t execution, double priority)
301 {
302   /* checking for infinite values */
303   xbt_assert(isfinite(priority), "priority is not finite!");
304   
305   smx_req_t req = SIMIX_req_mine();
306
307   req->call = REQ_HOST_EXECUTION_SET_PRIORITY;
308   req->host_execution_set_priority.execution = execution;
309   req->host_execution_set_priority.priority = priority;
310   SIMIX_request_push();
311 }
312
313 /**
314  * \brief Waits for the completion of an execution action and destroy it.
315  *
316  * \param execution The execution action
317  */
318 e_smx_state_t SIMIX_req_host_execution_wait(smx_action_t execution)
319 {
320   smx_req_t req = SIMIX_req_mine();
321
322   req->call = REQ_HOST_EXECUTION_WAIT;
323   req->host_execution_wait.execution = execution;
324   SIMIX_request_push();
325   return req->host_execution_wait.result;
326 }
327
328 /**
329  * \brief Creates and runs a new SIMIX process.
330  *
331  * The structure and the corresponding thread are created and put in the list of ready processes.
332  *
333  * \param process the process created will be stored in this pointer
334  * \param name a name for the process. It is for user-level information and can be NULL.
335  * \param code the main function of the process
336  * \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.
337  * It can be retrieved with the function \ref SIMIX_req_process_get_data.
338  * \param hostname name of the host where the new agent is executed.
339  * \param argc first argument passed to \a code
340  * \param argv second argument passed to \a code
341  * \param properties the properties of the process
342  */
343 void SIMIX_req_process_create(smx_process_t *process, const char *name,
344                               xbt_main_func_t code,
345                               void *data,
346                               const char *hostname,
347                               int argc, char **argv,
348                               xbt_dict_t properties)
349 {
350   smx_req_t req = SIMIX_req_mine();
351
352   req->call = REQ_PROCESS_CREATE;
353   req->process_create.process = process;
354   req->process_create.name = name;
355   req->process_create.code = code;
356   req->process_create.data = data;
357   req->process_create.hostname = hostname;
358   req->process_create.argc = argc;
359   req->process_create.argv = argv;
360   req->process_create.properties = properties;
361   SIMIX_request_push();
362 }
363
364 /** \brief Kills a SIMIX process.
365  *
366  * This function simply kills a  process.
367  *
368  * \param process poor victim
369  */
370 void SIMIX_req_process_kill(smx_process_t process)
371 {
372   smx_req_t req = SIMIX_req_mine();
373
374   req->call = REQ_PROCESS_KILL;
375   req->process_kill.process = process;
376   SIMIX_request_push();
377 }
378
379 /** \brief Kills all SIMIX processes.
380  */
381 void SIMIX_req_process_killall(void)
382 {
383   smx_req_t req = SIMIX_req_mine();
384
385   req->call = REQ_PROCESS_KILLALL;
386   SIMIX_request_push();
387 }
388
389 /** \brief Cleans up a SIMIX process.
390  * \param process poor victim (must have already been killed)
391  */
392 void SIMIX_req_process_cleanup(smx_process_t process)
393 {
394   smx_req_t req = SIMIX_req_mine();
395
396   req->call = REQ_PROCESS_CLEANUP;
397   req->process_cleanup.process = process;
398   SIMIX_request_push();
399 }
400
401 /**
402  * \brief Migrates an agent to another location.
403  *
404  * This function changes the value of the host on which \a process is running.
405  *
406  * \param process the process to migrate
407  * \param source name of the previous host
408  * \param dest name of the new host
409  */
410 void SIMIX_req_process_change_host(smx_process_t process, smx_host_t dest)
411 {
412   smx_req_t req = SIMIX_req_mine();
413
414   req->call = REQ_PROCESS_CHANGE_HOST;
415   req->process_change_host.process = process;
416   req->process_change_host.dest = dest;
417   SIMIX_request_push();
418 }
419
420 /**
421  * \brief Suspends a process.
422  *
423  * This function suspends the process by suspending the action
424  * it was waiting for completion.
425  *
426  * \param process a SIMIX process
427  */
428 void SIMIX_req_process_suspend(smx_process_t process)
429 {
430   xbt_assert(process, "Invalid parameters");
431
432   smx_req_t req = SIMIX_req_mine();
433
434   req->call = REQ_PROCESS_SUSPEND;
435   req->process_suspend.process = process;
436   SIMIX_request_push();
437 }
438
439 /**
440  * \brief Resumes a suspended process.
441  *
442  * This function resumes a suspended process by resuming the action
443  * it was waiting for completion.
444  *
445  * \param process a SIMIX process
446  */
447 void SIMIX_req_process_resume(smx_process_t process)
448 {
449   smx_req_t req = SIMIX_req_mine();
450
451   req->call = REQ_PROCESS_RESUME;
452   req->process_resume.process = process;
453   SIMIX_request_push();
454 }
455
456 /**
457  * \brief Returns the amount of SIMIX processes in the system
458  *
459  * Maestro internal process is not counted, only user code processes are
460  */
461 int SIMIX_req_process_count(void)
462 {
463   smx_req_t req = SIMIX_req_mine();
464
465   req->call = REQ_PROCESS_COUNT;
466   SIMIX_request_push();
467   return req->process_count.result;
468 }
469
470 /**
471  * \brief Return the user data of a #smx_process_t.
472  *
473  * This functions checks whether \a process is a valid pointer or not and return the user data associated to \a process if it is possible.
474  * \param process SIMIX process
475  * \return A void pointer to the user data
476  */
477 void* SIMIX_req_process_get_data(smx_process_t process)
478 {
479   if (process == SIMIX_process_self()) {
480     /* avoid a request if this function is called by the process itself */
481     return SIMIX_process_self_get_data();
482   }
483
484   smx_req_t req = SIMIX_req_mine();
485
486   req->call = REQ_PROCESS_GET_DATA;
487   req->process_get_data.process = process;
488   SIMIX_request_push();
489   return req->process_get_data.result;
490 }
491
492 /**
493  * \brief Set the user data of a #m_process_t.
494  *
495  * 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.
496  * \param process SIMIX process
497  * \param data User data
498  */
499 void SIMIX_req_process_set_data(smx_process_t process, void *data)
500 {
501   if (process == SIMIX_process_self()) {
502     /* avoid a request if this function is called by the process itself */
503     SIMIX_process_self_set_data(data);
504   }
505   else {
506
507     smx_req_t req = SIMIX_req_mine();
508
509     req->call = REQ_PROCESS_SET_DATA;
510     req->process_set_data.process = process;
511     req->process_set_data.data = data;
512     SIMIX_request_push();
513   }
514 }
515
516 /**
517  * \brief Return the location on which an agent is running.
518  *
519  * 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.
520  * \param process SIMIX process
521  * \return SIMIX host
522  */
523 smx_host_t SIMIX_req_process_get_host(smx_process_t process)
524 {
525   smx_req_t req = SIMIX_req_mine();
526
527   req->call = REQ_PROCESS_GET_HOST;
528   req->process_get_host.process = process;
529   SIMIX_request_push();
530   return req->process_get_host.result;
531 }
532
533 /**
534  * \brief Return the name of an agent.
535  *
536  * This functions checks whether \a process is a valid pointer or not and return its name.
537  * \param process SIMIX process
538  * \return The process name
539  */
540 const char* SIMIX_req_process_get_name(smx_process_t process)
541 {
542   if (process == SIMIX_process_self()) {
543     /* avoid a request if this function is called by the process itself */
544     return process->name;
545   }
546
547   smx_req_t req = SIMIX_req_mine();
548
549   req->call = REQ_PROCESS_GET_NAME;
550   req->process_get_name.process = process;
551   SIMIX_request_push();
552   return req->process_get_name.result;
553 }
554
555 /**
556  * \brief Returns true if the process is suspended .
557  *
558  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
559  * \param process SIMIX process
560  * \return 1, if the process is suspended, else 0.
561  */
562 int SIMIX_req_process_is_suspended(smx_process_t process)
563 {
564   smx_req_t req = SIMIX_req_mine();
565
566   req->call = REQ_PROCESS_IS_SUSPENDED;
567   req->process_is_suspended.process = process;
568   SIMIX_request_push();
569   return req->process_is_suspended.result;
570 }
571
572 /** \ingroup m_process_management
573  * \brief Return the properties
574  *
575  * This functions returns the properties associated with this process
576  */
577 xbt_dict_t SIMIX_req_process_get_properties(smx_process_t process)
578 {
579   smx_req_t req = SIMIX_req_mine();
580
581   req->call = REQ_PROCESS_GET_PROPERTIES;
582   req->process_get_properties.process = process;
583   SIMIX_request_push();
584   return req->process_get_properties.result;
585 }
586
587 /** \brief Creates a new sleep SIMIX action.
588  *
589  * This function creates a SURF action and allocates the data necessary
590  * to create the SIMIX action. It can raise a host_error exception if the
591  * host crashed. The default SIMIX name of the action is "sleep".
592  *
593  *      \param duration Time duration of the sleep.
594  *      \return A result telling whether the sleep was successful
595  */
596 e_smx_state_t SIMIX_req_process_sleep(double duration)
597 {
598   /* checking for infinite values */
599   xbt_assert(isfinite(duration), "duration is not finite!");
600   
601   smx_req_t req = SIMIX_req_mine();
602
603   req->call = REQ_PROCESS_SLEEP;
604   req->process_sleep.duration = duration;
605   SIMIX_request_push();
606   return req->process_sleep.result;
607 }
608
609 /**
610  *  \brief Creates a new rendez-vous point
611  *  \param name The name of the rendez-vous point
612  *  \return The created rendez-vous point
613  */
614 smx_rdv_t SIMIX_req_rdv_create(const char *name)
615 {
616   smx_req_t req = SIMIX_req_mine();
617
618   req->call = REQ_RDV_CREATE;
619   req->rdv_create.name = name;
620
621   SIMIX_request_push();
622   return req->rdv_create.result;
623 }
624
625
626 /**
627  *  \brief Destroy a rendez-vous point
628  *  \param name The rendez-vous point to destroy
629  */
630 void SIMIX_req_rdv_destroy(smx_rdv_t rdv)
631 {
632   smx_req_t req = SIMIX_req_mine();
633
634   req->call = REQ_RDV_DESTROY;
635   req->rdv_destroy.rdv = rdv;
636
637   SIMIX_request_push();
638 }
639
640 smx_rdv_t SIMIX_req_rdv_get_by_name(const char *name)
641 {
642   xbt_assert(name != NULL, "Invalid parameter for SIMIX_req_rdv_get_by_name (name is NULL)");
643
644   /* FIXME: this is a horrible lost of performance, so we hack it out by
645    * skipping the request (for now). It won't work on distributed but
646    * probably we will change MSG for that. */
647 /*
648   smx_req_t req = SIMIX_req_mine();
649   req->call = REQ_RDV_GEY_BY_NAME;
650   req->rdv_get_by_name.name = name;
651   SIMIX_request_push();
652   return req->rdv_get_by_name.result;*/
653
654   return SIMIX_rdv_get_by_name(name);
655 }
656
657 /**
658  *  \brief counts the number of communication requests of a given host pending
659  *         on a rendez-vous point
660  *  \param rdv The rendez-vous point
661  *  \param host The host to be counted
662  *  \return The number of comm request pending in the rdv
663  */
664 int SIMIX_req_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
665 {
666   smx_req_t req = SIMIX_req_mine();
667
668   req->call = REQ_RDV_COMM_COUNT_BY_HOST;
669   req->rdv_comm_count_by_host.rdv = rdv;
670   req->rdv_comm_count_by_host.host = host;
671
672   SIMIX_request_push();
673   return req->rdv_comm_count_by_host.result;
674 }
675
676 /**
677  *  \brief returns the communication at the head of the rendez-vous
678  *  \param rdv The rendez-vous point
679  *  \return The communication or NULL if empty
680  */
681 smx_action_t SIMIX_req_rdv_get_head(smx_rdv_t rdv)
682 {
683   smx_req_t req = SIMIX_req_mine();
684
685   req->call = REQ_RDV_GET_HEAD;
686   req->rdv_get_head.rdv = rdv;
687
688   SIMIX_request_push();
689   return req->rdv_get_head.result;
690 }
691
692 void SIMIX_req_comm_send(smx_rdv_t rdv, double task_size, double rate,
693                          void *src_buff, size_t src_buff_size,
694                          int (*match_fun)(void *, void *), void *data,
695                          double timeout)
696 {
697   /* checking for infinite values */
698   xbt_assert(isfinite(task_size), "task_size is not finite!");
699   xbt_assert(isfinite(rate), "rate is not finite!");
700   xbt_assert(isfinite(timeout), "timeout is not finite!");
701   
702   xbt_assert(rdv, "No rendez-vous point defined for send");
703
704   if (MC_IS_ENABLED) {
705     /* the model-checker wants two separate requests */
706     smx_action_t comm = SIMIX_req_comm_isend(rdv, task_size, rate,
707         src_buff, src_buff_size, match_fun, data, 0);
708     SIMIX_req_comm_wait(comm, timeout);
709   }
710   else {
711     smx_req_t req = SIMIX_req_mine();
712
713     req->call = REQ_COMM_SEND;
714     req->comm_send.rdv = rdv;
715     req->comm_send.task_size = task_size;
716     req->comm_send.rate = rate;
717     req->comm_send.src_buff = src_buff;
718     req->comm_send.src_buff_size = src_buff_size;
719     req->comm_send.match_fun = match_fun;
720     req->comm_send.data = data;
721     req->comm_send.timeout = timeout;
722
723     SIMIX_request_push();
724   }
725 }
726
727 smx_action_t SIMIX_req_comm_isend(smx_rdv_t rdv, double task_size, double rate,
728                               void *src_buff, size_t src_buff_size,
729                               int (*match_fun)(void *, void *), void *data,
730                               int detached)
731 {
732   /* checking for infinite values */
733   xbt_assert(isfinite(task_size), "task_size is not finite!");
734   xbt_assert(isfinite(rate), "rate is not finite!");
735   
736   xbt_assert(rdv, "No rendez-vous point defined for isend");
737
738   smx_req_t req = SIMIX_req_mine();
739
740   req->call = REQ_COMM_ISEND;
741   req->comm_isend.rdv = rdv;
742   req->comm_isend.task_size = task_size;
743   req->comm_isend.rate = rate;
744   req->comm_isend.src_buff = src_buff;
745   req->comm_isend.src_buff_size = src_buff_size;
746   req->comm_isend.match_fun = match_fun;
747   req->comm_isend.data = data;
748   req->comm_isend.detached = detached;
749
750   SIMIX_request_push();
751   return req->comm_isend.result;
752 }
753
754 void SIMIX_req_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
755                          int (*match_fun)(void *, void *), void *data, double timeout)
756 {
757   xbt_assert(isfinite(timeout), "timeout is not finite!");
758   xbt_assert(rdv, "No rendez-vous point defined for recv");
759
760   if (MC_IS_ENABLED) {
761     /* the model-checker wants two separate requests */
762     smx_action_t comm = SIMIX_req_comm_irecv(rdv, dst_buff, dst_buff_size,
763         match_fun, data);
764     SIMIX_req_comm_wait(comm, timeout);
765   }
766   else {
767     smx_req_t req = SIMIX_req_mine();
768
769     req->call = REQ_COMM_RECV;
770     req->comm_recv.rdv = rdv;
771     req->comm_recv.dst_buff = dst_buff;
772     req->comm_recv.dst_buff_size = dst_buff_size;
773     req->comm_recv.match_fun = match_fun;
774     req->comm_recv.data = data;
775     req->comm_recv.timeout = timeout;
776
777     SIMIX_request_push();
778   }
779 }
780
781 smx_action_t SIMIX_req_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
782                                   int (*match_fun)(void *, void *), void *data)
783 {
784   xbt_assert(rdv, "No rendez-vous point defined for irecv");
785
786   smx_req_t req = SIMIX_req_mine();
787
788   req->call = REQ_COMM_IRECV;
789   req->comm_irecv.rdv = rdv;
790   req->comm_irecv.dst_buff = dst_buff;
791   req->comm_irecv.dst_buff_size = dst_buff_size;
792   req->comm_irecv.match_fun = match_fun;
793   req->comm_irecv.data = data;
794
795   SIMIX_request_push();
796   return req->comm_irecv.result;
797 }
798
799 void SIMIX_req_comm_destroy(smx_action_t comm)
800 {
801   xbt_assert(comm, "Invalid parameter");
802
803   /* FIXME remove this request type: comms are auto-destroyed now,
804    * but what happens with unfinished comms? */
805
806   /*
807   smx_req_t req = SIMIX_req_mine();
808
809   req->call = REQ_COMM_DESTROY;
810   req->comm_destroy.comm = comm;
811
812   SIMIX_request_push();
813   */
814 }
815
816 void SIMIX_req_comm_cancel(smx_action_t comm)
817 {
818   smx_req_t req = SIMIX_req_mine();
819
820   req->call = REQ_COMM_CANCEL;
821   req->comm_cancel.comm = comm;
822
823   SIMIX_request_push();
824 }
825
826 unsigned int SIMIX_req_comm_waitany(xbt_dynar_t comms)
827 {
828   smx_req_t req = SIMIX_req_mine();
829
830   req->call = REQ_COMM_WAITANY;
831   req->comm_waitany.comms = comms;
832
833   SIMIX_request_push();
834   return req->comm_waitany.result;
835 }
836
837 int SIMIX_req_comm_testany(xbt_dynar_t comms)
838 {
839   smx_req_t req = SIMIX_req_mine();
840   if (xbt_dynar_length(comms)==0)
841     return -1;
842
843   req->call = REQ_COMM_TESTANY;
844   req->comm_testany.comms = comms;
845
846   SIMIX_request_push();
847   return req->comm_testany.result;
848 }
849
850 void SIMIX_req_comm_wait(smx_action_t comm, double timeout)
851 {
852   xbt_assert(isfinite(timeout), "timeout is not finite!");
853   
854   smx_req_t req = SIMIX_req_mine();
855
856   req->call = REQ_COMM_WAIT;
857   req->comm_wait.comm = comm;
858   req->comm_wait.timeout = timeout;
859
860   SIMIX_request_push();
861 }
862
863 #ifdef HAVE_TRACING
864 /**
865  * \brief Set the category of an action.
866  *
867  * This functions changes the category only. It calls a surf function.
868  * \param execution The execution action
869  * \param category The tracing category
870  */
871 void SIMIX_req_set_category(smx_action_t action, const char *category)
872 {
873   if (category == NULL) {
874     return;
875   }
876
877   smx_req_t req = SIMIX_req_mine();
878
879   req->call = REQ_SET_CATEGORY;
880   req->set_category.action = action;
881   req->set_category.category = category;
882
883   SIMIX_request_push();
884 }
885 #endif
886
887 int SIMIX_req_comm_test(smx_action_t comm)
888 {
889   smx_req_t req = SIMIX_req_mine();
890
891   req->call = REQ_COMM_TEST;
892   req->comm_test.comm = comm;
893
894   SIMIX_request_push();
895   return req->comm_test.result;
896 }
897
898 double SIMIX_req_comm_get_remains(smx_action_t comm)
899 {
900   smx_req_t req = SIMIX_req_mine();
901
902   req->call = REQ_COMM_GET_REMAINS;
903   req->comm_get_remains.comm = comm;
904
905   SIMIX_request_push();
906   return req->comm_get_remains.result;
907 }
908
909 e_smx_state_t SIMIX_req_comm_get_state(smx_action_t comm)
910 {
911   smx_req_t req = SIMIX_req_mine();
912
913   req->call = REQ_COMM_GET_STATE;
914   req->comm_get_state.comm = comm;
915
916   SIMIX_request_push();
917   return req->comm_get_state.result;
918 }
919
920 void *SIMIX_req_comm_get_src_data(smx_action_t comm)
921 {
922   smx_req_t req = SIMIX_req_mine();
923
924   req->call = REQ_COMM_GET_SRC_DATA;
925   req->comm_get_src_data.comm = comm;
926
927   SIMIX_request_push();
928   return req->comm_get_src_data.result;
929 }
930
931 void *SIMIX_req_comm_get_dst_data(smx_action_t comm)
932 {
933   smx_req_t req = SIMIX_req_mine();
934
935   req->call = REQ_COMM_GET_DST_DATA;
936   req->comm_get_dst_data.comm = comm;
937
938   SIMIX_request_push();
939   return req->comm_get_dst_data.result;
940 }
941
942 smx_process_t SIMIX_req_comm_get_src_proc(smx_action_t comm)
943 {
944   smx_req_t req = SIMIX_req_mine();
945
946   req->call = REQ_COMM_GET_SRC_PROC;
947   req->comm_get_src_proc.comm = comm;
948
949   SIMIX_request_push();
950   return req->comm_get_src_proc.result;
951 }
952
953 smx_process_t SIMIX_req_comm_get_dst_proc(smx_action_t comm)
954 {
955   smx_req_t req = SIMIX_req_mine();
956
957   req->call = REQ_COMM_GET_DST_PROC;
958   req->comm_get_dst_proc.comm = comm;
959
960   SIMIX_request_push();
961   return req->comm_get_dst_proc.result;
962 }
963
964 #ifdef HAVE_LATENCY_BOUND_TRACKING
965 int SIMIX_req_comm_is_latency_bounded(smx_action_t comm)
966 {
967   smx_req_t req = SIMIX_req_mine();
968
969   req->call = REQ_COMM_IS_LATENCY_BOUNDED;
970   req->comm_is_latency_bounded.comm = comm;
971
972   SIMIX_request_push();
973   return req->comm_is_latency_bounded.result;
974 }
975 #endif
976
977 smx_mutex_t SIMIX_req_mutex_init(void)
978 {
979   smx_req_t req = SIMIX_req_mine();
980
981   req->call = REQ_MUTEX_INIT;
982
983   SIMIX_request_push();
984   return req->mutex_init.result;
985 }
986
987 void SIMIX_req_mutex_destroy(smx_mutex_t mutex)
988 {
989   smx_req_t req = SIMIX_req_mine();
990
991   req->call = REQ_MUTEX_DESTROY;
992   req->mutex_destroy.mutex = mutex;
993
994   SIMIX_request_push();
995 }
996
997 void SIMIX_req_mutex_lock(smx_mutex_t mutex)
998 {
999   smx_req_t req = SIMIX_req_mine();
1000
1001   req->call = REQ_MUTEX_LOCK;
1002   req->mutex_lock.mutex = mutex;
1003
1004   SIMIX_request_push();
1005 }
1006
1007 int SIMIX_req_mutex_trylock(smx_mutex_t mutex)
1008 {
1009   smx_req_t req = SIMIX_req_mine();
1010
1011   req->call = REQ_MUTEX_TRYLOCK;
1012   req->mutex_trylock.mutex = mutex;
1013
1014   SIMIX_request_push();
1015   return req->mutex_trylock.result;
1016 }
1017
1018 void SIMIX_req_mutex_unlock(smx_mutex_t mutex)
1019 {
1020   smx_req_t req = SIMIX_req_mine();
1021
1022   req->call = REQ_MUTEX_UNLOCK;
1023   req->mutex_unlock.mutex = mutex;
1024
1025   SIMIX_request_push();
1026 }
1027
1028
1029 smx_cond_t SIMIX_req_cond_init(void)
1030 {
1031   smx_req_t req = SIMIX_req_mine();
1032
1033   req->call = REQ_COND_INIT;
1034
1035   SIMIX_request_push();
1036   return req->cond_init.result;
1037 }
1038
1039 void SIMIX_req_cond_destroy(smx_cond_t cond)
1040 {
1041   smx_req_t req = SIMIX_req_mine();
1042
1043   req->call = REQ_COND_DESTROY;
1044   req->cond_destroy.cond = cond;
1045
1046   SIMIX_request_push();
1047 }
1048
1049 void SIMIX_req_cond_signal(smx_cond_t cond)
1050 {
1051   smx_req_t req = SIMIX_req_mine();
1052
1053   req->call = REQ_COND_SIGNAL;
1054   req->cond_signal.cond = cond;
1055
1056   SIMIX_request_push();
1057 }
1058
1059 void SIMIX_req_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1060 {
1061   smx_req_t req = SIMIX_req_mine();
1062
1063   req->call = REQ_COND_WAIT;
1064   req->cond_wait.cond = cond;
1065   req->cond_wait.mutex = mutex;
1066
1067   SIMIX_request_push();
1068 }
1069
1070 void SIMIX_req_cond_wait_timeout(smx_cond_t cond,
1071                                  smx_mutex_t mutex,
1072                                  double timeout)
1073 {
1074   xbt_assert(isfinite(timeout), "timeout is not finite!");
1075   
1076   smx_req_t req = SIMIX_req_mine();
1077
1078   req->call = REQ_COND_WAIT_TIMEOUT;
1079   req->cond_wait_timeout.cond = cond;
1080   req->cond_wait_timeout.mutex = mutex;
1081   req->cond_wait_timeout.timeout = timeout;
1082
1083   SIMIX_request_push();
1084 }
1085
1086 void SIMIX_req_cond_broadcast(smx_cond_t cond)
1087 {
1088   smx_req_t req = SIMIX_req_mine();
1089
1090   req->call = REQ_COND_BROADCAST;
1091   req->cond_broadcast.cond = cond;
1092
1093   SIMIX_request_push();
1094 }
1095
1096
1097 smx_sem_t SIMIX_req_sem_init(int capacity)
1098 {
1099   smx_req_t req = SIMIX_req_mine();
1100
1101   req->call = REQ_SEM_INIT;
1102   req->sem_init.capacity = capacity;
1103
1104   SIMIX_request_push();
1105   return req->sem_init.result;
1106 }
1107
1108 void SIMIX_req_sem_destroy(smx_sem_t sem)
1109 {
1110   smx_req_t req = SIMIX_req_mine();
1111
1112   req->call = REQ_SEM_DESTROY;
1113   req->sem_destroy.sem = sem;
1114
1115   SIMIX_request_push();
1116 }
1117
1118 void SIMIX_req_sem_release(smx_sem_t sem)
1119 {
1120   smx_req_t req = SIMIX_req_mine();
1121
1122   req->call = REQ_SEM_RELEASE;
1123   req->sem_release.sem = sem;
1124
1125   SIMIX_request_push();
1126 }
1127
1128 int SIMIX_req_sem_would_block(smx_sem_t sem)
1129 {
1130   smx_req_t req = SIMIX_req_mine();
1131
1132   req->call = REQ_SEM_WOULD_BLOCK;
1133   req->sem_would_block.sem = sem;
1134
1135   SIMIX_request_push();
1136   return req->sem_would_block.result;
1137 }
1138
1139 void SIMIX_req_sem_acquire(smx_sem_t sem)
1140 {
1141   smx_req_t req = SIMIX_req_mine();
1142
1143   req->call = REQ_SEM_ACQUIRE;
1144   req->sem_acquire.sem = sem;
1145
1146   SIMIX_request_push();
1147 }
1148
1149 void SIMIX_req_sem_acquire_timeout(smx_sem_t sem, double timeout)
1150 {
1151   xbt_assert(isfinite(timeout), "timeout is not finite!");
1152   
1153   smx_req_t req = SIMIX_req_mine();
1154
1155   req->call = REQ_SEM_ACQUIRE_TIMEOUT;
1156   req->sem_acquire_timeout.sem = sem;
1157   req->sem_acquire_timeout.timeout = timeout;
1158
1159   SIMIX_request_push();
1160 }
1161
1162 int SIMIX_req_sem_get_capacity(smx_sem_t sem)
1163 {
1164   smx_req_t req = SIMIX_req_mine();
1165
1166   req->call = REQ_SEM_GET_CAPACITY;
1167   req->sem_get_capacity.sem = sem;
1168
1169   SIMIX_request_push();
1170   return req->sem_get_capacity.result;
1171 }
1172 /* ************************************************************************** */
1173
1174 /** @brief returns a printable string representing the request kind */
1175 const char *SIMIX_request_name(int kind) {
1176   return request_names[kind];
1177 }