Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
For win64 it is cast unsigned long long.
[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 "private.h"
19 #include "mc/mc.h"
20
21
22 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
23
24 static const char* request_names[] = {
25 #undef SIMIX_REQ_ENUM_ELEMENT
26 #define SIMIX_REQ_ENUM_ELEMENT(x) #x /* generate strings from the enumeration values */
27 SIMIX_REQ_LIST
28 #undef SIMIX_REQ_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 SIMIX_req_host_get_by_name(const char *name)
38 {
39   smx_req_t req = SIMIX_req_mine();
40
41   req->call = REQ_HOST_GET_BY_NAME;
42   req->host_get_by_name.name = name;
43   SIMIX_request_push();
44   return req->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* SIMIX_req_host_get_name(smx_host_t host)
54 {
55   smx_req_t req = SIMIX_req_mine();
56
57   req->call = REQ_HOST_GET_NAME;
58   req->host_get_name.host = host;
59   SIMIX_request_push();
60   return req->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 SIMIX_req_host_get_properties(smx_host_t host)
70 {
71   smx_req_t req = SIMIX_req_mine();
72
73   req->call = REQ_HOST_GET_PROPERTIES;
74   req->host_get_properties.host = host;
75   SIMIX_request_push();
76   return req->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 SIMIX_req_host_get_speed(smx_host_t host)
87 {
88   smx_req_t req = SIMIX_req_mine();
89
90   req->call = REQ_HOST_GET_SPEED;
91   req->host_get_speed.host = host;
92   SIMIX_request_push();
93   return req->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 SIMIX_req_host_get_available_speed(smx_host_t host)
102 {
103   smx_req_t req = SIMIX_req_mine();
104
105   req->call = REQ_HOST_GET_AVAILABLE_SPEED;
106   req->host_get_available_speed.host = host;
107   SIMIX_request_push();
108   return req->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 SIMIX_req_host_get_state(smx_host_t host)
119 {
120   smx_req_t req = SIMIX_req_mine();
121
122   req->call = REQ_HOST_GET_STATE;
123   req->host_get_state.host = host;
124   SIMIX_request_push();
125   return req->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* SIMIX_req_host_get_data(smx_host_t host)
135 {
136   smx_req_t req = SIMIX_req_mine();
137
138   req->call = REQ_HOST_GET_DATA;
139   req->host_get_data.host = host;
140   SIMIX_request_push();
141   return req->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 SIMIX_req_host_set_data(smx_host_t host, void *data)
152 {
153   smx_req_t req = SIMIX_req_mine();
154
155   req->call = REQ_HOST_SET_DATA;
156   req->host_set_data.host = host;
157   req->host_set_data.data = data;
158   SIMIX_request_push();
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 SIMIX_req_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_req_t req = SIMIX_req_mine();
180
181   req->call = REQ_HOST_EXECUTE;
182   req->host_execute.name = name;
183   req->host_execute.host = host;
184   req->host_execute.computation_amount = computation_amount;
185   req->host_execute.priority = priority;
186   SIMIX_request_push();
187   return req->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 SIMIX_req_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_req_t req = SIMIX_req_mine();
225
226   req->call = REQ_HOST_PARALLEL_EXECUTE;
227   req->host_parallel_execute.name = name;
228   req->host_parallel_execute.host_nb = host_nb;
229   req->host_parallel_execute.host_list = host_list;
230   req->host_parallel_execute.computation_amount = computation_amount;
231   req->host_parallel_execute.communication_amount = communication_amount;
232   req->host_parallel_execute.amount = amount;
233   req->host_parallel_execute.rate = rate;
234   SIMIX_request_push();
235   return req->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 SIMIX_req_host_execution_destroy(smx_action_t execution)
245 {
246   smx_req_t req = SIMIX_req_mine();
247
248   req->call = REQ_HOST_EXECUTION_DESTROY;
249   req->host_execution_destroy.execution = execution;
250   SIMIX_request_push();
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 SIMIX_req_host_execution_cancel(smx_action_t execution)
260 {
261   smx_req_t req = SIMIX_req_mine();
262
263   req->call = REQ_HOST_EXECUTION_CANCEL;
264   req->host_execution_cancel.execution = execution;
265   SIMIX_request_push();
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 SIMIX_req_host_execution_get_remains(smx_action_t execution)
275 {
276   smx_req_t req = SIMIX_req_mine();
277
278   req->call = REQ_HOST_EXECUTION_GET_REMAINS;
279   req->host_execution_get_remains.execution = execution;
280   SIMIX_request_push();
281   return req->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 SIMIX_req_host_execution_get_state(smx_action_t execution)
291 {
292   smx_req_t req = SIMIX_req_mine();
293
294   req->call = REQ_HOST_EXECUTION_GET_STATE;
295   req->host_execution_get_state.execution = execution;
296   SIMIX_request_push();
297   return req->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 SIMIX_req_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_req_t req = SIMIX_req_mine();
313
314   req->call = REQ_HOST_EXECUTION_SET_PRIORITY;
315   req->host_execution_set_priority.execution = execution;
316   req->host_execution_set_priority.priority = priority;
317   SIMIX_request_push();
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 SIMIX_req_host_execution_wait(smx_action_t execution)
326 {
327   smx_req_t req = SIMIX_req_mine();
328
329   req->call = REQ_HOST_EXECUTION_WAIT;
330   req->host_execution_wait.execution = execution;
331   SIMIX_request_push();
332   return req->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 SIMIX_req_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 SIMIX_req_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_req_t req = SIMIX_req_mine();
358
359   req->call = REQ_PROCESS_CREATE;
360   req->process_create.process = process;
361   req->process_create.name = name;
362   req->process_create.code = code;
363   req->process_create.data = data;
364   req->process_create.hostname = hostname;
365   req->process_create.argc = argc;
366   req->process_create.argv = argv;
367   req->process_create.properties = properties;
368   SIMIX_request_push();
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 SIMIX_req_process_kill(smx_process_t process)
378 {
379   smx_req_t req = SIMIX_req_mine();
380
381   req->call = REQ_PROCESS_KILL;
382   req->process_kill.process = process;
383   SIMIX_request_push();
384 }
385
386 /** \brief Kills all SIMIX processes.
387  */
388 void SIMIX_req_process_killall(void)
389 {
390   smx_req_t req = SIMIX_req_mine();
391
392   req->call = REQ_PROCESS_KILLALL;
393   SIMIX_request_push();
394 }
395
396 /** \brief Cleans up a SIMIX process.
397  * \param process poor victim (must have already been killed)
398  */
399 void SIMIX_req_process_cleanup(smx_process_t process)
400 {
401   smx_req_t req = SIMIX_req_mine();
402
403   req->call = REQ_PROCESS_CLEANUP;
404   req->process_cleanup.process = process;
405   SIMIX_request_push();
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 SIMIX_req_process_change_host(smx_process_t process, smx_host_t dest)
418 {
419   smx_req_t req = SIMIX_req_mine();
420
421   req->call = REQ_PROCESS_CHANGE_HOST;
422   req->process_change_host.process = process;
423   req->process_change_host.dest = dest;
424   SIMIX_request_push();
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 SIMIX_req_process_suspend(smx_process_t process)
436 {
437   xbt_assert(process, "Invalid parameters");
438
439   smx_req_t req = SIMIX_req_mine();
440
441   req->call = REQ_PROCESS_SUSPEND;
442   req->process_suspend.process = process;
443   SIMIX_request_push();
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 SIMIX_req_process_resume(smx_process_t process)
455 {
456   smx_req_t req = SIMIX_req_mine();
457
458   req->call = REQ_PROCESS_RESUME;
459   req->process_resume.process = process;
460   SIMIX_request_push();
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 SIMIX_req_process_count(void)
469 {
470   smx_req_t req = SIMIX_req_mine();
471
472   req->call = REQ_PROCESS_COUNT;
473   SIMIX_request_push();
474   return req->process_count.result;
475 }
476
477 /**
478  * \brief Return the user data of a #smx_process_t.
479  *
480  * 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.
481  * \param process SIMIX process
482  * \return A void pointer to the user data
483  */
484 void* SIMIX_req_process_get_data(smx_process_t process)
485 {
486   if (process == SIMIX_process_self()) {
487     /* avoid a request if this function is called by the process itself */
488     return SIMIX_process_self_get_data();
489   }
490
491   smx_req_t req = SIMIX_req_mine();
492
493   req->call = REQ_PROCESS_GET_DATA;
494   req->process_get_data.process = process;
495   SIMIX_request_push();
496   return req->process_get_data.result;
497 }
498
499 /**
500  * \brief Set the user data of a #m_process_t.
501  *
502  * 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.
503  * \param process SIMIX process
504  * \param data User data
505  */
506 void SIMIX_req_process_set_data(smx_process_t process, void *data)
507 {
508   if (process == SIMIX_process_self()) {
509     /* avoid a request if this function is called by the process itself */
510     SIMIX_process_self_set_data(data);
511   }
512   else {
513
514     smx_req_t req = SIMIX_req_mine();
515
516     req->call = REQ_PROCESS_SET_DATA;
517     req->process_set_data.process = process;
518     req->process_set_data.data = data;
519     SIMIX_request_push();
520   }
521 }
522
523 /**
524  * \brief Return the location on which an agent is running.
525  *
526  * 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.
527  * \param process SIMIX process
528  * \return SIMIX host
529  */
530 smx_host_t SIMIX_req_process_get_host(smx_process_t process)
531 {
532   smx_req_t req = SIMIX_req_mine();
533
534   req->call = REQ_PROCESS_GET_HOST;
535   req->process_get_host.process = process;
536   SIMIX_request_push();
537   return req->process_get_host.result;
538 }
539
540 /**
541  * \brief Return the name of an agent.
542  *
543  * This functions checks whether \a process is a valid pointer or not and return its name.
544  * \param process SIMIX process
545  * \return The process name
546  */
547 const char* SIMIX_req_process_get_name(smx_process_t process)
548 {
549   if (process == SIMIX_process_self()) {
550     /* avoid a request if this function is called by the process itself */
551     return process->name;
552   }
553
554   smx_req_t req = SIMIX_req_mine();
555
556   req->call = REQ_PROCESS_GET_NAME;
557   req->process_get_name.process = process;
558   SIMIX_request_push();
559   return req->process_get_name.result;
560 }
561
562 /**
563  * \brief Returns true if the process is suspended .
564  *
565  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
566  * \param process SIMIX process
567  * \return 1, if the process is suspended, else 0.
568  */
569 int SIMIX_req_process_is_suspended(smx_process_t process)
570 {
571   smx_req_t req = SIMIX_req_mine();
572
573   req->call = REQ_PROCESS_IS_SUSPENDED;
574   req->process_is_suspended.process = process;
575   SIMIX_request_push();
576   return req->process_is_suspended.result;
577 }
578
579 /** \ingroup m_process_management
580  * \brief Return the properties
581  *
582  * This functions returns the properties associated with this process
583  */
584 xbt_dict_t SIMIX_req_process_get_properties(smx_process_t process)
585 {
586   smx_req_t req = SIMIX_req_mine();
587
588   req->call = REQ_PROCESS_GET_PROPERTIES;
589   req->process_get_properties.process = process;
590   SIMIX_request_push();
591   return req->process_get_properties.result;
592 }
593
594 /** \brief Creates a new sleep SIMIX action.
595  *
596  * This function creates a SURF action and allocates the data necessary
597  * to create the SIMIX action. It can raise a host_error exception if the
598  * host crashed. The default SIMIX name of the action is "sleep".
599  *
600  *      \param duration Time duration of the sleep.
601  *      \return A result telling whether the sleep was successful
602  */
603 e_smx_state_t SIMIX_req_process_sleep(double duration)
604 {
605   /* checking for infinite values */
606   xbt_assert(isfinite(duration), "duration is not finite!");
607   
608   smx_req_t req = SIMIX_req_mine();
609
610   req->call = REQ_PROCESS_SLEEP;
611   req->process_sleep.duration = duration;
612   SIMIX_request_push();
613   return req->process_sleep.result;
614 }
615
616 /**
617  *  \brief Creates a new rendez-vous point
618  *  \param name The name of the rendez-vous point
619  *  \return The created rendez-vous point
620  */
621 smx_rdv_t SIMIX_req_rdv_create(const char *name)
622 {
623   smx_req_t req = SIMIX_req_mine();
624
625   req->call = REQ_RDV_CREATE;
626   req->rdv_create.name = name;
627
628   SIMIX_request_push();
629   return req->rdv_create.result;
630 }
631
632
633 /**
634  *  \brief Destroy a rendez-vous point
635  *  \param name The rendez-vous point to destroy
636  */
637 void SIMIX_req_rdv_destroy(smx_rdv_t rdv)
638 {
639   smx_req_t req = SIMIX_req_mine();
640
641   req->call = REQ_RDV_DESTROY;
642   req->rdv_destroy.rdv = rdv;
643
644   SIMIX_request_push();
645 }
646
647 smx_rdv_t SIMIX_req_rdv_get_by_name(const char *name)
648 {
649   xbt_assert(name != NULL, "Invalid parameter for SIMIX_req_rdv_get_by_name (name is NULL)");
650
651   /* FIXME: this is a horrible lost of performance, so we hack it out by
652    * skipping the request (for now). It won't work on distributed but
653    * probably we will change MSG for that. */
654 /*
655   smx_req_t req = SIMIX_req_mine();
656   req->call = REQ_RDV_GEY_BY_NAME;
657   req->rdv_get_by_name.name = name;
658   SIMIX_request_push();
659   return req->rdv_get_by_name.result;*/
660
661   return SIMIX_rdv_get_by_name(name);
662 }
663
664 /**
665  *  \brief counts the number of communication requests of a given host pending
666  *         on a rendez-vous point
667  *  \param rdv The rendez-vous point
668  *  \param host The host to be counted
669  *  \return The number of comm request pending in the rdv
670  */
671 int SIMIX_req_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
672 {
673   smx_req_t req = SIMIX_req_mine();
674
675   req->call = REQ_RDV_COMM_COUNT_BY_HOST;
676   req->rdv_comm_count_by_host.rdv = rdv;
677   req->rdv_comm_count_by_host.host = host;
678
679   SIMIX_request_push();
680   return req->rdv_comm_count_by_host.result;
681 }
682
683 /**
684  *  \brief returns the communication at the head of the rendez-vous
685  *  \param rdv The rendez-vous point
686  *  \return The communication or NULL if empty
687  */
688 smx_action_t SIMIX_req_rdv_get_head(smx_rdv_t rdv)
689 {
690   smx_req_t req = SIMIX_req_mine();
691
692   req->call = REQ_RDV_GET_HEAD;
693   req->rdv_get_head.rdv = rdv;
694
695   SIMIX_request_push();
696   return req->rdv_get_head.result;
697 }
698
699 void SIMIX_req_comm_send(smx_rdv_t rdv, double task_size, double rate,
700                          void *src_buff, size_t src_buff_size,
701                          int (*match_fun)(void *, void *), void *data,
702                          double timeout)
703 {
704   /* checking for infinite values */
705   xbt_assert(isfinite(task_size), "task_size is not finite!");
706   xbt_assert(isfinite(rate), "rate is not finite!");
707   xbt_assert(isfinite(timeout), "timeout is not finite!");
708   
709   xbt_assert(rdv, "No rendez-vous point defined for send");
710
711   if (MC_IS_ENABLED) {
712     /* the model-checker wants two separate requests */
713     smx_action_t comm = SIMIX_req_comm_isend(rdv, task_size, rate,
714         src_buff, src_buff_size, match_fun, data, 0);
715     SIMIX_req_comm_wait(comm, timeout);
716   }
717   else {
718     smx_req_t req = SIMIX_req_mine();
719
720     req->call = REQ_COMM_SEND;
721     req->comm_send.rdv = rdv;
722     req->comm_send.task_size = task_size;
723     req->comm_send.rate = rate;
724     req->comm_send.src_buff = src_buff;
725     req->comm_send.src_buff_size = src_buff_size;
726     req->comm_send.match_fun = match_fun;
727     req->comm_send.data = data;
728     req->comm_send.timeout = timeout;
729
730     SIMIX_request_push();
731   }
732 }
733
734 smx_action_t SIMIX_req_comm_isend(smx_rdv_t rdv, double task_size, double rate,
735                               void *src_buff, size_t src_buff_size,
736                               int (*match_fun)(void *, void *), void *data,
737                               int detached)
738 {
739   /* checking for infinite values */
740   xbt_assert(isfinite(task_size), "task_size is not finite!");
741   xbt_assert(isfinite(rate), "rate is not finite!");
742   
743   xbt_assert(rdv, "No rendez-vous point defined for isend");
744
745   smx_req_t req = SIMIX_req_mine();
746
747   req->call = REQ_COMM_ISEND;
748   req->comm_isend.rdv = rdv;
749   req->comm_isend.task_size = task_size;
750   req->comm_isend.rate = rate;
751   req->comm_isend.src_buff = src_buff;
752   req->comm_isend.src_buff_size = src_buff_size;
753   req->comm_isend.match_fun = match_fun;
754   req->comm_isend.data = data;
755   req->comm_isend.detached = detached;
756
757   SIMIX_request_push();
758   return req->comm_isend.result;
759 }
760
761 void SIMIX_req_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
762                          int (*match_fun)(void *, void *), void *data, double timeout)
763 {
764   xbt_assert(isfinite(timeout), "timeout is not finite!");
765   xbt_assert(rdv, "No rendez-vous point defined for recv");
766
767   if (MC_IS_ENABLED) {
768     /* the model-checker wants two separate requests */
769     smx_action_t comm = SIMIX_req_comm_irecv(rdv, dst_buff, dst_buff_size,
770         match_fun, data);
771     SIMIX_req_comm_wait(comm, timeout);
772   }
773   else {
774     smx_req_t req = SIMIX_req_mine();
775
776     req->call = REQ_COMM_RECV;
777     req->comm_recv.rdv = rdv;
778     req->comm_recv.dst_buff = dst_buff;
779     req->comm_recv.dst_buff_size = dst_buff_size;
780     req->comm_recv.match_fun = match_fun;
781     req->comm_recv.data = data;
782     req->comm_recv.timeout = timeout;
783
784     SIMIX_request_push();
785   }
786 }
787
788 smx_action_t SIMIX_req_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
789                                   int (*match_fun)(void *, void *), void *data)
790 {
791   xbt_assert(rdv, "No rendez-vous point defined for irecv");
792
793   smx_req_t req = SIMIX_req_mine();
794
795   req->call = REQ_COMM_IRECV;
796   req->comm_irecv.rdv = rdv;
797   req->comm_irecv.dst_buff = dst_buff;
798   req->comm_irecv.dst_buff_size = dst_buff_size;
799   req->comm_irecv.match_fun = match_fun;
800   req->comm_irecv.data = data;
801
802   SIMIX_request_push();
803   return req->comm_irecv.result;
804 }
805
806 void SIMIX_req_comm_destroy(smx_action_t comm)
807 {
808   xbt_assert(comm, "Invalid parameter");
809
810   /* FIXME remove this request type: comms are auto-destroyed now,
811    * but what happens with unfinished comms? */
812
813   /*
814   smx_req_t req = SIMIX_req_mine();
815
816   req->call = REQ_COMM_DESTROY;
817   req->comm_destroy.comm = comm;
818
819   SIMIX_request_push();
820   */
821 }
822
823 void SIMIX_req_comm_cancel(smx_action_t comm)
824 {
825   smx_req_t req = SIMIX_req_mine();
826
827   req->call = REQ_COMM_CANCEL;
828   req->comm_cancel.comm = comm;
829
830   SIMIX_request_push();
831 }
832
833 unsigned int SIMIX_req_comm_waitany(xbt_dynar_t comms)
834 {
835   smx_req_t req = SIMIX_req_mine();
836
837   req->call = REQ_COMM_WAITANY;
838   req->comm_waitany.comms = comms;
839
840   SIMIX_request_push();
841   return req->comm_waitany.result;
842 }
843
844 int SIMIX_req_comm_testany(xbt_dynar_t comms)
845 {
846   smx_req_t req = SIMIX_req_mine();
847   if (xbt_dynar_length(comms)==0)
848     return -1;
849
850   req->call = REQ_COMM_TESTANY;
851   req->comm_testany.comms = comms;
852
853   SIMIX_request_push();
854   return req->comm_testany.result;
855 }
856
857 void SIMIX_req_comm_wait(smx_action_t comm, double timeout)
858 {
859   xbt_assert(isfinite(timeout), "timeout is not finite!");
860   
861   smx_req_t req = SIMIX_req_mine();
862
863   req->call = REQ_COMM_WAIT;
864   req->comm_wait.comm = comm;
865   req->comm_wait.timeout = timeout;
866
867   SIMIX_request_push();
868 }
869
870 #ifdef HAVE_TRACING
871 /**
872  * \brief Set the category of an action.
873  *
874  * This functions changes the category only. It calls a surf function.
875  * \param execution The execution action
876  * \param category The tracing category
877  */
878 void SIMIX_req_set_category(smx_action_t action, const char *category)
879 {
880   if (category == NULL) {
881     return;
882   }
883
884   smx_req_t req = SIMIX_req_mine();
885
886   req->call = REQ_SET_CATEGORY;
887   req->set_category.action = action;
888   req->set_category.category = category;
889
890   SIMIX_request_push();
891 }
892 #endif
893
894 int SIMIX_req_comm_test(smx_action_t comm)
895 {
896   smx_req_t req = SIMIX_req_mine();
897
898   req->call = REQ_COMM_TEST;
899   req->comm_test.comm = comm;
900
901   SIMIX_request_push();
902   return req->comm_test.result;
903 }
904
905 double SIMIX_req_comm_get_remains(smx_action_t comm)
906 {
907   smx_req_t req = SIMIX_req_mine();
908
909   req->call = REQ_COMM_GET_REMAINS;
910   req->comm_get_remains.comm = comm;
911
912   SIMIX_request_push();
913   return req->comm_get_remains.result;
914 }
915
916 e_smx_state_t SIMIX_req_comm_get_state(smx_action_t comm)
917 {
918   smx_req_t req = SIMIX_req_mine();
919
920   req->call = REQ_COMM_GET_STATE;
921   req->comm_get_state.comm = comm;
922
923   SIMIX_request_push();
924   return req->comm_get_state.result;
925 }
926
927 void *SIMIX_req_comm_get_src_data(smx_action_t comm)
928 {
929   smx_req_t req = SIMIX_req_mine();
930
931   req->call = REQ_COMM_GET_SRC_DATA;
932   req->comm_get_src_data.comm = comm;
933
934   SIMIX_request_push();
935   return req->comm_get_src_data.result;
936 }
937
938 void *SIMIX_req_comm_get_dst_data(smx_action_t comm)
939 {
940   smx_req_t req = SIMIX_req_mine();
941
942   req->call = REQ_COMM_GET_DST_DATA;
943   req->comm_get_dst_data.comm = comm;
944
945   SIMIX_request_push();
946   return req->comm_get_dst_data.result;
947 }
948
949 smx_process_t SIMIX_req_comm_get_src_proc(smx_action_t comm)
950 {
951   smx_req_t req = SIMIX_req_mine();
952
953   req->call = REQ_COMM_GET_SRC_PROC;
954   req->comm_get_src_proc.comm = comm;
955
956   SIMIX_request_push();
957   return req->comm_get_src_proc.result;
958 }
959
960 smx_process_t SIMIX_req_comm_get_dst_proc(smx_action_t comm)
961 {
962   smx_req_t req = SIMIX_req_mine();
963
964   req->call = REQ_COMM_GET_DST_PROC;
965   req->comm_get_dst_proc.comm = comm;
966
967   SIMIX_request_push();
968   return req->comm_get_dst_proc.result;
969 }
970
971 #ifdef HAVE_LATENCY_BOUND_TRACKING
972 int SIMIX_req_comm_is_latency_bounded(smx_action_t comm)
973 {
974   smx_req_t req = SIMIX_req_mine();
975
976   req->call = REQ_COMM_IS_LATENCY_BOUNDED;
977   req->comm_is_latency_bounded.comm = comm;
978
979   SIMIX_request_push();
980   return req->comm_is_latency_bounded.result;
981 }
982 #endif
983
984 smx_mutex_t SIMIX_req_mutex_init(void)
985 {
986   smx_req_t req = SIMIX_req_mine();
987
988   req->call = REQ_MUTEX_INIT;
989
990   SIMIX_request_push();
991   return req->mutex_init.result;
992 }
993
994 void SIMIX_req_mutex_destroy(smx_mutex_t mutex)
995 {
996   smx_req_t req = SIMIX_req_mine();
997
998   req->call = REQ_MUTEX_DESTROY;
999   req->mutex_destroy.mutex = mutex;
1000
1001   SIMIX_request_push();
1002 }
1003
1004 void SIMIX_req_mutex_lock(smx_mutex_t mutex)
1005 {
1006   smx_req_t req = SIMIX_req_mine();
1007
1008   req->call = REQ_MUTEX_LOCK;
1009   req->mutex_lock.mutex = mutex;
1010
1011   SIMIX_request_push();
1012 }
1013
1014 int SIMIX_req_mutex_trylock(smx_mutex_t mutex)
1015 {
1016   smx_req_t req = SIMIX_req_mine();
1017
1018   req->call = REQ_MUTEX_TRYLOCK;
1019   req->mutex_trylock.mutex = mutex;
1020
1021   SIMIX_request_push();
1022   return req->mutex_trylock.result;
1023 }
1024
1025 void SIMIX_req_mutex_unlock(smx_mutex_t mutex)
1026 {
1027   smx_req_t req = SIMIX_req_mine();
1028
1029   req->call = REQ_MUTEX_UNLOCK;
1030   req->mutex_unlock.mutex = mutex;
1031
1032   SIMIX_request_push();
1033 }
1034
1035
1036 smx_cond_t SIMIX_req_cond_init(void)
1037 {
1038   smx_req_t req = SIMIX_req_mine();
1039
1040   req->call = REQ_COND_INIT;
1041
1042   SIMIX_request_push();
1043   return req->cond_init.result;
1044 }
1045
1046 void SIMIX_req_cond_destroy(smx_cond_t cond)
1047 {
1048   smx_req_t req = SIMIX_req_mine();
1049
1050   req->call = REQ_COND_DESTROY;
1051   req->cond_destroy.cond = cond;
1052
1053   SIMIX_request_push();
1054 }
1055
1056 void SIMIX_req_cond_signal(smx_cond_t cond)
1057 {
1058   smx_req_t req = SIMIX_req_mine();
1059
1060   req->call = REQ_COND_SIGNAL;
1061   req->cond_signal.cond = cond;
1062
1063   SIMIX_request_push();
1064 }
1065
1066 void SIMIX_req_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1067 {
1068   smx_req_t req = SIMIX_req_mine();
1069
1070   req->call = REQ_COND_WAIT;
1071   req->cond_wait.cond = cond;
1072   req->cond_wait.mutex = mutex;
1073
1074   SIMIX_request_push();
1075 }
1076
1077 void SIMIX_req_cond_wait_timeout(smx_cond_t cond,
1078                                  smx_mutex_t mutex,
1079                                  double timeout)
1080 {
1081   xbt_assert(isfinite(timeout), "timeout is not finite!");
1082   
1083   smx_req_t req = SIMIX_req_mine();
1084
1085   req->call = REQ_COND_WAIT_TIMEOUT;
1086   req->cond_wait_timeout.cond = cond;
1087   req->cond_wait_timeout.mutex = mutex;
1088   req->cond_wait_timeout.timeout = timeout;
1089
1090   SIMIX_request_push();
1091 }
1092
1093 void SIMIX_req_cond_broadcast(smx_cond_t cond)
1094 {
1095   smx_req_t req = SIMIX_req_mine();
1096
1097   req->call = REQ_COND_BROADCAST;
1098   req->cond_broadcast.cond = cond;
1099
1100   SIMIX_request_push();
1101 }
1102
1103
1104 smx_sem_t SIMIX_req_sem_init(int capacity)
1105 {
1106   smx_req_t req = SIMIX_req_mine();
1107
1108   req->call = REQ_SEM_INIT;
1109   req->sem_init.capacity = capacity;
1110
1111   SIMIX_request_push();
1112   return req->sem_init.result;
1113 }
1114
1115 void SIMIX_req_sem_destroy(smx_sem_t sem)
1116 {
1117   smx_req_t req = SIMIX_req_mine();
1118
1119   req->call = REQ_SEM_DESTROY;
1120   req->sem_destroy.sem = sem;
1121
1122   SIMIX_request_push();
1123 }
1124
1125 void SIMIX_req_sem_release(smx_sem_t sem)
1126 {
1127   smx_req_t req = SIMIX_req_mine();
1128
1129   req->call = REQ_SEM_RELEASE;
1130   req->sem_release.sem = sem;
1131
1132   SIMIX_request_push();
1133 }
1134
1135 int SIMIX_req_sem_would_block(smx_sem_t sem)
1136 {
1137   smx_req_t req = SIMIX_req_mine();
1138
1139   req->call = REQ_SEM_WOULD_BLOCK;
1140   req->sem_would_block.sem = sem;
1141
1142   SIMIX_request_push();
1143   return req->sem_would_block.result;
1144 }
1145
1146 void SIMIX_req_sem_acquire(smx_sem_t sem)
1147 {
1148   smx_req_t req = SIMIX_req_mine();
1149
1150   req->call = REQ_SEM_ACQUIRE;
1151   req->sem_acquire.sem = sem;
1152
1153   SIMIX_request_push();
1154 }
1155
1156 void SIMIX_req_sem_acquire_timeout(smx_sem_t sem, double timeout)
1157 {
1158   xbt_assert(isfinite(timeout), "timeout is not finite!");
1159   
1160   smx_req_t req = SIMIX_req_mine();
1161
1162   req->call = REQ_SEM_ACQUIRE_TIMEOUT;
1163   req->sem_acquire_timeout.sem = sem;
1164   req->sem_acquire_timeout.timeout = timeout;
1165
1166   SIMIX_request_push();
1167 }
1168
1169 int SIMIX_req_sem_get_capacity(smx_sem_t sem)
1170 {
1171   smx_req_t req = SIMIX_req_mine();
1172
1173   req->call = REQ_SEM_GET_CAPACITY;
1174   req->sem_get_capacity.sem = sem;
1175
1176   SIMIX_request_push();
1177   return req->sem_get_capacity.result;
1178 }
1179 /* ************************************************************************** */
1180
1181 /** @brief returns a printable string representing the request kind */
1182 const char *SIMIX_request_name(int kind) {
1183   return request_names[kind];
1184 }