Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enough is enough. Add semaphores as SIMIX synchronization mechanism.
[simgrid.git] / src / include / simix / simix.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
4    All rights reserved.                                          */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #ifndef _SIMIX_SIMIX_H
10 #define _SIMIX_SIMIX_H
11
12 #include "xbt/misc.h"
13 #include "xbt/fifo.h"
14 #include "xbt/dict.h"
15 #include "xbt/function_types.h"
16 #include "simix/datatypes.h"
17 #include "surf/surf.h"
18
19 SG_BEGIN_DECL()
20
21
22 /************************** Global ******************************************/
23 XBT_PUBLIC(void) SIMIX_global_init(int *argc, char **argv);
24 XBT_PUBLIC(void) SIMIX_clean(void);
25 XBT_PUBLIC(void) SIMIX_function_register(const char *name,
26                                          xbt_main_func_t code);
27 XBT_PUBLIC(void) SIMIX_function_register_default(xbt_main_func_t code);
28 XBT_PUBLIC(xbt_main_func_t) SIMIX_get_registered_function(const char *name);
29
30 XBT_PUBLIC(void) SIMIX_launch_application(const char *file);
31
32 XBT_PUBLIC(double) SIMIX_get_clock(void);
33 XBT_PUBLIC(void) SIMIX_init(void);
34 XBT_PUBLIC(double) SIMIX_solve(xbt_fifo_t actions_done,
35                                xbt_fifo_t actions_failed);
36
37 /* Timer functions */
38 XBT_PUBLIC(void) SIMIX_timer_set(double date, void *function, void *arg);
39 XBT_PUBLIC(int) SIMIX_timer_get(void **function, void **arg);
40
41 /* only for tests */
42 XBT_PUBLIC(void) __SIMIX_main(void);
43
44 /* User create and kill process, the function must accept the folling parameters:
45  * const char *name: a name for the object. It is for user-level information and can be NULL
46  * xbt_main_func_t code: is a function describing the behavior of the agent
47  * void *data: data a pointer to any data one may want to attach to the new object.
48  * smx_host_t host: the location where the new agent is executed
49  * int argc, char **argv: parameters passed to code
50  *
51  * */
52      typedef void *(*smx_creation_func_t) ( /*name */ const char *,
53                                            /*code */ xbt_main_func_t,
54                                            /*userdata */ void *,
55                                            /*hostname */ char *,
56                                            /* argc */ int,
57                                            /* argv */ char **,
58                                            /* props */ xbt_dict_t);
59 XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t
60                                                         function);
61 XBT_PUBLIC(void) SIMIX_function_register_process_kill(void_f_pvoid_t
62                                                       function);
63 XBT_PUBLIC(void) SIMIX_function_register_process_cleanup(void_f_pvoid_t
64                                                          function);
65
66 /************************** Host handling ***********************************/
67
68 XBT_PUBLIC(void) SIMIX_host_set_data(smx_host_t host, void *data);
69 XBT_PUBLIC(void *) SIMIX_host_get_data(smx_host_t host);
70
71 XBT_PUBLIC(const char *) SIMIX_host_get_name(smx_host_t host);
72 XBT_PUBLIC(void) SIMIX_process_set_name(smx_process_t process, char *name);
73 XBT_PUBLIC(smx_host_t) SIMIX_host_self(void);
74 XBT_PUBLIC(double) SIMIX_host_get_speed(smx_host_t host);
75 XBT_PUBLIC(double) SIMIX_host_get_available_speed(smx_host_t host);
76
77 XBT_PUBLIC(int) SIMIX_host_get_number(void);
78 XBT_PUBLIC(smx_host_t *) SIMIX_host_get_table(void);
79 XBT_PUBLIC(xbt_dict_t) SIMIX_host_get_dict(void);
80
81 XBT_PUBLIC(void) SIMIX_create_environment(const char *file);
82 XBT_PUBLIC(smx_host_t) SIMIX_host_get_by_name(const char *name);
83
84 XBT_PUBLIC(xbt_dict_t) SIMIX_host_get_properties(smx_host_t host);
85
86 /* Two possible states, 1 - CPU ON and 0 CPU OFF */
87 XBT_PUBLIC(int) SIMIX_host_get_state(smx_host_t host);
88
89 /************************** Process handling *********************************/
90 XBT_PUBLIC(smx_process_t) SIMIX_process_create(const char *name,
91                                                xbt_main_func_t code,
92                                                void *data,
93                                                const char *hostname, int argc,
94                                                char **argv,
95                                                xbt_dict_t properties);
96
97 XBT_PUBLIC(void) SIMIX_process_kill(smx_process_t process);
98 XBT_PUBLIC(void) SIMIX_process_cleanup(void *arg);
99 XBT_PUBLIC(void) SIMIX_process_killall(void);
100 XBT_PUBLIC(void) SIMIX_process_change_host(smx_process_t process,
101                                            char *source, char *dest);
102
103 //above layer
104 XBT_PUBLIC(void *) SIMIX_process_get_data(smx_process_t process);
105 XBT_PUBLIC(void) SIMIX_process_set_data(smx_process_t process, void *data);
106
107 XBT_PUBLIC(smx_host_t) SIMIX_process_get_host(smx_process_t process);
108 XBT_PUBLIC(const char *) SIMIX_process_get_name(smx_process_t process);
109 XBT_PUBLIC(smx_process_t) SIMIX_process_self(void);
110
111 XBT_PUBLIC(void) SIMIX_process_yield(void);
112 XBT_PUBLIC(void) SIMIX_process_suspend(smx_process_t process);
113 XBT_PUBLIC(void) SIMIX_process_resume(smx_process_t process);
114 XBT_PUBLIC(int) SIMIX_process_is_suspended(smx_process_t process);
115 XBT_PUBLIC(int) SIMIX_process_is_blocked(smx_process_t process);
116
117 /*property handlers*/
118 XBT_PUBLIC(xbt_dict_t) SIMIX_process_get_properties(smx_process_t host);
119 XBT_PUBLIC(int) SIMIX_process_count(void);
120
121 /************************** Synchro handling **********************************/
122
123 /******Mutex******/
124 XBT_PUBLIC(smx_mutex_t) SIMIX_mutex_init(void);
125 XBT_PUBLIC(void) SIMIX_mutex_lock(smx_mutex_t mutex);
126 XBT_PUBLIC(int) SIMIX_mutex_trylock(smx_mutex_t mutex);
127 XBT_PUBLIC(void) SIMIX_mutex_unlock(smx_mutex_t mutex);
128 XBT_PUBLIC(void) SIMIX_mutex_destroy(smx_mutex_t mutex);
129
130 /*****Conditional*****/
131 XBT_PUBLIC(smx_cond_t) SIMIX_cond_init(void);
132 XBT_PUBLIC(void) SIMIX_cond_signal(smx_cond_t cond);
133 XBT_PUBLIC(void) SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex);
134 XBT_PUBLIC(void) SIMIX_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex,
135                                          double max_duration);
136 XBT_PUBLIC(void) SIMIX_cond_broadcast(smx_cond_t cond);
137 XBT_PUBLIC(void) SIMIX_cond_destroy(smx_cond_t cond);
138 XBT_PUBLIC(xbt_fifo_t) SIMIX_cond_get_actions(smx_cond_t cond);
139 XBT_PUBLIC(void) SIMIX_cond_display_info(smx_cond_t cond);
140
141 /*****Semaphores*******/
142
143
144 XBT_PUBLIC(smx_sem_t) SIMIX_sem_init(int capacity);
145 XBT_PUBLIC(void) SIMIX_sem_destroy(smx_sem_t sem);
146 XBT_PUBLIC(void) SIMIX_sem_release(smx_sem_t sem);
147 XBT_PUBLIC(void) SIMIX_sem_release_forever(smx_sem_t sem);
148 XBT_PUBLIC(int) SIMIX_sem_would_block(smx_sem_t sem);
149 XBT_PUBLIC(void) SIMIX_sem_acquire(smx_sem_t sem);
150 XBT_PUBLIC(void) SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration);
151
152
153 /************************** Action handling ************************************/
154 XBT_PUBLIC(smx_action_t) SIMIX_action_communicate(smx_host_t sender,
155                                                   smx_host_t receiver,
156                                                   const char *name,
157                                                   double size, double rate);
158 XBT_PUBLIC(smx_action_t) SIMIX_action_execute(smx_host_t host,
159                                               const char *name,
160                                               double amount);
161 XBT_PUBLIC(smx_action_t) SIMIX_action_sleep(smx_host_t host, double amount);
162 XBT_PUBLIC(void) SIMIX_action_cancel(smx_action_t action);
163 XBT_PUBLIC(void) SIMIX_action_set_priority(smx_action_t action,
164                                            double priority);
165 XBT_PUBLIC(int) SIMIX_action_destroy(smx_action_t action);
166 XBT_PUBLIC(void) SIMIX_action_use(smx_action_t action);
167 XBT_PUBLIC(void) SIMIX_action_release(smx_action_t action);
168
169 XBT_PUBLIC(void) SIMIX_register_action_to_condition(smx_action_t action,
170                                                     smx_cond_t cond);
171 XBT_PUBLIC(void) SIMIX_unregister_action_to_condition(smx_action_t action,
172                                                       smx_cond_t cond);
173 XBT_PUBLIC(void) SIMIX_register_action_to_semaphore(smx_action_t action, smx_sem_t sem);
174 XBT_PUBLIC(void) SIMIX_unregister_action_to_semaphore(smx_action_t action, smx_sem_t sem);
175
176
177 XBT_PUBLIC(double) SIMIX_action_get_remains(smx_action_t action);
178
179 XBT_PUBLIC(e_surf_action_state_t) SIMIX_action_get_state(smx_action_t action);
180
181 XBT_PUBLIC(smx_action_t) SIMIX_action_parallel_execute(char *name,
182                                                        int host_nb,
183                                                        smx_host_t * host_list,
184                                                        double
185                                                        *computation_amount, double
186                                                        *communication_amount,
187                                                        double amount,
188                                                        double rate);
189
190 XBT_PUBLIC(char *) SIMIX_action_get_name(smx_action_t action);
191 XBT_PUBLIC(void) SIMIX_action_set_name(smx_action_t action,char *name);
192 XBT_PUBLIC(void) SIMIX_action_signal_all(smx_action_t action);
193 XBT_PUBLIC(void) SIMIX_display_process_status(void);
194 /************************** Comunication Handling *****************************/
195
196 /* Public */
197 /*****Rendez-vous points*****/
198 XBT_PUBLIC(smx_rdv_t) SIMIX_rdv_create(const char *name);
199 XBT_PUBLIC(void) SIMIX_rdv_destroy(smx_rdv_t rvp);
200 XBT_PUBLIC(int) SIMIX_rdv_get_count_waiting_comm(smx_rdv_t rdv, smx_host_t host);
201 XBT_PUBLIC(smx_comm_t) SIMIX_rdv_get_head(smx_rdv_t rdv);
202 XBT_PUBLIC(smx_comm_t) SIMIX_rdv_get_request(smx_rdv_t rdv, smx_comm_type_t type);
203 XBT_PUBLIC(void) SIMIX_rdv_set_data(smx_rdv_t rdv,void *data);
204 XBT_PUBLIC(void*) SIMIX_rdv_get_data(smx_rdv_t rdv);
205
206 /*****Communication Requests*****/
207 XBT_PUBLIC(void) SIMIX_communication_cancel(smx_comm_t comm);
208 XBT_PUBLIC(double) SIMIX_communication_get_remains(smx_comm_t comm);
209 XBT_PUBLIC(void *) SIMIX_communication_get_data(smx_comm_t comm);
210
211 /*****Networking*****/
212 XBT_PUBLIC(void) SIMIX_network_send(smx_rdv_t rdv, double task_size, double rate,
213                                     double timeout, void *src_buff,
214                                     size_t src_buff_size, smx_comm_t *comm, void *data);
215 XBT_PUBLIC(void) SIMIX_network_recv(smx_rdv_t rdv, double timeout, void *dst_buff,
216                                     size_t *dst_buff_size, smx_comm_t *comm);
217 XBT_PUBLIC(smx_comm_t) SIMIX_network_isend(smx_rdv_t rdv, double task_size, double rate,
218                                            void *src_buff, size_t src_buff_size, void *data);
219 XBT_PUBLIC(smx_comm_t) SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size);
220
221 XBT_PUBLIC(void) SIMIX_network_wait(smx_comm_t comm, double timeout);
222 XBT_PUBLIC(int) SIMIX_network_test(smx_comm_t comm);
223
224 SG_END_DECL()
225 #endif /* _SIMIX_SIMIX_H */