Logo AND Algorithmique Numérique Distribuée

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