Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement a dynamic parallel execution mode.
[simgrid.git] / src / simix / smurf_private.h
1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef _SIMIX_SMURF_PRIVATE_H
8 #define _SIMIX_SMURF_PRIVATE_H
9
10 /********************************* Requests ***********************************/
11
12 /* we want to build the e_smx_t enumeration and the table of the corresponding
13  * strings automatically, using macros */
14
15 #define SIMIX_REQ_LIST1 \
16 SIMIX_REQ_ENUM_ELEMENT(REQ_NO_REQ),\
17 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_BY_NAME),\
18 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_NAME),\
19 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_PROPERTIES),\
20 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_SPEED),\
21 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_AVAILABLE_SPEED),\
22 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_STATE),\
23 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_DATA),\
24 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_SET_DATA),\
25 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTE),\
26 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_PARALLEL_EXECUTE),\
27 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_DESTROY),\
28 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_CANCEL),\
29 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_GET_REMAINS),\
30 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_GET_STATE),\
31 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_SET_PRIORITY),\
32 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_WAIT),\
33 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_CREATE),\
34 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_KILL),\
35 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_CHANGE_HOST),\
36 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SUSPEND),\
37 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_RESUME),\
38 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_COUNT),\
39 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_DATA),\
40 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SET_DATA),\
41 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_HOST),\
42 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_NAME),\
43 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_IS_SUSPENDED),\
44 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_PROPERTIES),\
45 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SLEEP),\
46 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_CREATE),\
47 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_DESTROY),\
48 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_GEY_BY_NAME),\
49 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_COMM_COUNT_BY_HOST),\
50 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_GET_HEAD),\
51 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_ISEND),\
52 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_IRECV),\
53 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_DESTROY),\
54 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_CANCEL),\
55 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_WAITANY),\
56 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_WAIT),\
57 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_TEST),\
58 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_TESTANY),\
59 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_REMAINS),\
60 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_STATE),\
61 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_DATA),\
62 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_DATA),\
63 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_BUFF),\
64 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_BUFF),\
65 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_BUFF_SIZE),\
66 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_BUFF_SIZE),\
67 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_PROC),\
68 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_PROC),\
69 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_INIT),\
70 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_DESTROY),\
71 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_LOCK),\
72 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_TRYLOCK),\
73 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_UNLOCK),\
74 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_INIT),\
75 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_DESTROY),\
76 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_SIGNAL),\
77 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_WAIT),\
78 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_WAIT_TIMEOUT),\
79 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_BROADCAST),\
80 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_INIT),\
81 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_DESTROY),\
82 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_RELEASE),\
83 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_WOULD_BLOCK),\
84 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE),\
85 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE_TIMEOUT),\
86 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_GET_CAPACITY)
87
88 /* REQ_COMM_IS_LATENCY_BOUNDED and REQ_SET_CATEGORY make things complicated
89  * because they are not always present */
90 #ifdef HAVE_LATENCY_BOUND_TRACKING
91 #define SIMIX_REQ_LIST2 \
92 ,SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_IS_LATENCY_BOUNDED)
93 #else
94 #define SIMIX_REQ_LIST2
95 #endif
96
97 #ifdef HAVE_TRACING
98 #define SIMIX_REQ_LIST3 \
99 ,SIMIX_REQ_ENUM_ELEMENT(REQ_SET_CATEGORY)
100 #else
101 #define SIMIX_REQ_LIST3
102 #endif
103
104 /* SIMIX_REQ_LIST is the final macro to use */
105 #define SIMIX_REQ_LIST SIMIX_REQ_LIST1 SIMIX_REQ_LIST2 SIMIX_REQ_LIST3
106
107 /* you can redefine the following macro differently to generate something else
108  * with the list of enumeration values (e.g. a table of strings or a table of function pointers) */
109 #define SIMIX_REQ_ENUM_ELEMENT(x) x
110
111 /**
112  * \brief All possible SIMIX requests.
113  */
114 typedef enum {
115 SIMIX_REQ_LIST
116 } e_smx_req_t;
117
118 /**
119  * \brief Represents a SIMIX request.
120  */
121 typedef struct s_smx_req {
122   s_xbt_swag_hookup_t reqtable_hookup;
123   e_smx_req_t call;
124   smx_process_t issuer;
125
126   union {
127
128     struct {
129       const char *name;
130       smx_host_t result;
131     } host_get_by_name;
132
133     struct {
134       smx_host_t host;
135       const char* result;
136     } host_get_name;
137
138     struct {
139       smx_host_t host;
140       xbt_dict_t result;
141     } host_get_properties;
142
143     struct {
144       smx_host_t host;
145       double result;
146     } host_get_speed;
147
148     struct {
149       smx_host_t host;
150       double result;
151     } host_get_available_speed;
152
153     struct {
154       smx_host_t host;
155       int result;
156     } host_get_state;
157
158     struct {
159       smx_host_t host;
160       void* result;
161     } host_get_data;
162
163     struct {
164       smx_host_t host;
165       void* data;
166     } host_set_data;
167
168     struct {
169       const char* name;
170       smx_host_t host;
171       double computation_amount;
172       double priority;
173       smx_action_t result;
174     } host_execute;
175
176     struct {
177       const char *name;
178       int host_nb;
179       smx_host_t *host_list;
180       double *computation_amount;
181       double *communication_amount;
182       double amount;
183       double rate;
184       smx_action_t result;
185     } host_parallel_execute;
186
187     struct {
188       smx_action_t execution;
189     } host_execution_destroy;
190
191     struct {
192       smx_action_t execution;
193     } host_execution_cancel;
194
195     struct {
196       smx_action_t execution;
197       double result;
198     } host_execution_get_remains;
199
200     struct {
201       smx_action_t execution;
202       e_smx_state_t result;
203     } host_execution_get_state;
204
205     struct {
206       smx_action_t execution;
207       double priority;
208     } host_execution_set_priority;
209
210     struct {
211       smx_action_t execution;
212       e_smx_state_t result;
213     } host_execution_wait;
214
215     struct {
216       smx_process_t *process;
217       const char *name;
218       xbt_main_func_t code;
219       void *data;
220       const char *hostname;
221       int argc;
222       char **argv;
223       xbt_dict_t properties;
224     } process_create;
225
226     struct {
227       smx_process_t process;
228     } process_kill;
229
230     struct {
231       smx_process_t process;
232       const char *source;
233       const char *dest;
234     } process_change_host;
235
236     struct {
237       smx_process_t process;
238     } process_suspend;
239
240     struct {
241       smx_process_t process;
242     } process_resume;
243
244     struct {
245       int result;
246     } process_count;
247
248     struct {
249       smx_process_t process;
250       void* result;
251     } process_get_data;
252
253     struct {
254       smx_process_t process;
255       void* data;
256     } process_set_data;
257
258     struct {
259       smx_process_t process;
260       smx_host_t result;
261     } process_get_host;
262
263     struct {
264       smx_process_t process;
265       const char *result;
266     } process_get_name;
267
268     struct {
269       smx_process_t process;
270       int result;
271     } process_is_suspended;
272
273     struct {
274       smx_process_t process;
275       xbt_dict_t result;
276     } process_get_properties;
277
278     struct {
279       double duration;
280       e_smx_state_t result;
281     } process_sleep;
282
283     struct {
284       const char *name;
285       smx_rdv_t result;
286     } rdv_create;
287
288     struct {
289       smx_rdv_t rdv;
290     } rdv_destroy;
291
292     struct {
293       const char* name;
294       smx_rdv_t result;
295     } rdv_get_by_name;
296
297     struct {
298       smx_rdv_t rdv;
299       smx_host_t host;
300       unsigned int result; 
301     } rdv_comm_count_by_host;
302
303     struct {
304       smx_rdv_t rdv;
305       smx_action_t result;
306     } rdv_get_head;
307
308     struct {
309       smx_rdv_t rdv;
310       double task_size;
311       double rate;
312       void *src_buff;
313       size_t src_buff_size;
314       int (*match_fun)(void *, void *);
315       void *data;
316       int detached;
317       smx_action_t result;
318     } comm_isend;
319
320     struct {
321       smx_rdv_t rdv;
322       void *dst_buff;
323       size_t *dst_buff_size;
324       int (*match_fun)(void *, void *);
325           void *data;
326       smx_action_t result;
327     } comm_irecv;
328
329     struct {
330       smx_action_t comm;
331     } comm_destroy;
332
333     struct {
334       smx_action_t comm;
335     } comm_cancel;
336
337     struct {
338       xbt_dynar_t comms;
339       unsigned int result;
340     } comm_waitany;
341
342     struct {
343       smx_action_t comm;
344       double timeout;
345     } comm_wait;
346
347     struct {
348       smx_action_t comm;
349       int result;
350     } comm_test;
351
352     struct {
353       xbt_dynar_t comms;
354       int result;
355     } comm_testany;
356
357     struct {
358       smx_action_t comm;
359       double result;
360     } comm_get_remains;
361
362     struct {
363       smx_action_t comm;
364       e_smx_state_t result;
365     } comm_get_state;
366
367     struct {
368       smx_action_t comm;
369       void *result;
370     } comm_get_src_data;
371
372     struct {
373       smx_action_t comm;
374       void *result;
375     } comm_get_dst_data;
376
377     struct {
378       smx_action_t comm;
379       void *result;
380     } comm_get_src_buff;
381
382     struct {
383       smx_action_t comm;
384       void *result;
385     } comm_get_dst_buff;
386
387     struct {
388       smx_action_t comm;
389       size_t result;
390     } comm_get_src_buff_size;
391
392     struct {
393       smx_action_t comm;
394       size_t result;
395     } comm_get_dst_buff_size;
396
397     struct {
398       smx_action_t comm;
399       smx_process_t result;
400     } comm_get_src_proc;
401
402     struct {
403       smx_action_t comm;
404       smx_process_t result;
405     } comm_get_dst_proc;
406
407 #ifdef HAVE_LATENCY_BOUND_TRACKING
408     struct {
409       smx_action_t comm;
410       int result;
411     } comm_is_latency_bounded;
412 #endif
413
414 #ifdef HAVE_TRACING
415     struct {
416       smx_action_t action;
417       const char *category;
418     } set_category;
419 #endif
420
421     struct {
422       smx_mutex_t result;
423     } mutex_init;
424
425     struct {
426       smx_mutex_t mutex;
427     } mutex_lock;
428
429     struct {
430       smx_mutex_t mutex;
431       int result;
432     } mutex_trylock;
433
434     struct {
435       smx_mutex_t mutex;
436     } mutex_unlock;
437
438     struct {
439       smx_mutex_t mutex;
440     } mutex_destroy;
441
442     struct {
443       smx_cond_t result;
444     } cond_init;
445
446     struct {
447       smx_cond_t cond;
448     } cond_destroy;
449
450     struct {
451       smx_cond_t cond;
452     } cond_signal;
453
454     struct {
455       smx_cond_t cond;
456       smx_mutex_t mutex;
457     } cond_wait;
458
459     struct {
460       smx_cond_t cond;
461       smx_mutex_t mutex;
462       double timeout;
463     } cond_wait_timeout;
464
465     struct {
466       smx_cond_t cond;
467     } cond_broadcast;
468
469     struct {
470       int capacity;
471       smx_sem_t result;
472     } sem_init;
473
474     struct {
475       smx_sem_t sem;
476     } sem_destroy;
477
478     struct {
479       smx_sem_t sem;
480     } sem_release;
481
482     struct {
483       smx_sem_t sem;
484       int result;
485     } sem_would_block;
486
487     struct {
488       smx_sem_t sem;
489     } sem_acquire;
490
491     struct {
492       smx_sem_t sem;
493       double timeout;
494     } sem_acquire_timeout;
495
496     struct {
497       smx_sem_t sem;
498       int result;
499     } sem_get_capacity;
500   };
501 } s_smx_req_t, *smx_req_t;
502
503 /******************************** General *************************************/
504
505 void SIMIX_request_init(void);
506 void SIMIX_request_destroy(void);
507 xbt_swag_t SIMIX_request_get_reqlist(int thread_pid);
508 void SIMIX_request_push(void);
509 smx_req_t SIMIX_request_pop(void);
510 void SIMIX_request_answer(smx_req_t);
511 void SIMIX_request_pre(smx_req_t, int);
512 void SIMIX_request_post(smx_action_t);
513 XBT_INLINE smx_req_t SIMIX_req_mine(void);
514
515 #endif
516