Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rewrite the kill_time mecanism.
[simgrid.git] / include / simix / simix.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_SIMIX_H
8 #define _SIMIX_SIMIX_H
9
10 #include "xbt/misc.h"
11 #include "xbt/fifo.h"
12 #include "xbt/dict.h"
13 #include "xbt/file_stat.h"
14 #include "xbt/function_types.h"
15 #include "simix/datatypes.h"
16 #include "simix/context.h"
17
18 SG_BEGIN_DECL()
19
20 /********************************** Global ************************************/
21 /* Initialization and exit */
22 XBT_PUBLIC(void) SIMIX_global_init(int *argc, char **argv);
23 XBT_PUBLIC(void) SIMIX_clean(void);
24
25
26 XBT_PUBLIC(void) SIMIX_function_register_process_cleanup(void_pfn_smxprocess_t function);
27 XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function);
28 XBT_PUBLIC(void) SIMIX_function_register_process_kill(void_pfn_smxprocess_t function);
29
30 /* Simulation execution */
31 XBT_PUBLIC(void) SIMIX_run(void);    
32 XBT_PUBLIC(double) SIMIX_get_clock(void);
33
34 /* Timer functions FIXME: should these be public? */
35 XBT_PUBLIC(void) SIMIX_timer_set(double date, void *function, void *arg);
36 XBT_PUBLIC(double) SIMIX_timer_next(void);
37
38 XBT_PUBLIC(void) SIMIX_display_process_status(void);
39
40 /******************************* Environment **********************************/
41 XBT_PUBLIC(void) SIMIX_create_environment(const char *file);
42
43 /******************************** Deployment **********************************/
44
45 XBT_PUBLIC(void) SIMIX_function_register(const char *name, xbt_main_func_t code);
46 XBT_PUBLIC(void) SIMIX_function_register_default(xbt_main_func_t code);
47 XBT_PUBLIC(xbt_main_func_t) SIMIX_get_registered_function(const char *name);
48 XBT_PUBLIC(void) SIMIX_launch_application(const char *file);
49 XBT_PUBLIC(void) SIMIX_process_set_function(const char* process_host,
50                                             const char *process_function,
51                                             xbt_dynar_t arguments,
52                                             double process_start_time,
53                                             double process_kill_time);
54
55 /*********************************** Host *************************************/
56 XBT_PUBLIC(xbt_dict_t) SIMIX_host_get_dict(void);
57 XBT_PUBLIC(smx_host_t) SIMIX_host_get_by_name(const char *name);
58 XBT_PUBLIC(smx_host_t) SIMIX_host_self(void);
59 XBT_PUBLIC(const char*) SIMIX_host_self_get_name(void);
60 XBT_PUBLIC(const char*) SIMIX_host_get_name(smx_host_t host); /* FIXME: make private: only the name of SIMIX_host_self() should be public without request */
61 XBT_PUBLIC(void) SIMIX_host_self_set_data(void *data);
62 XBT_PUBLIC(void*) SIMIX_host_self_get_data(void);
63
64 /********************************* Process ************************************/
65 XBT_PUBLIC(int) SIMIX_process_count(void);
66 XBT_PUBLIC(smx_process_t) SIMIX_process_self(void);
67 XBT_PUBLIC(const char*) SIMIX_process_self_get_name(void);
68 XBT_PUBLIC(void) SIMIX_process_self_set_data(smx_process_t self, void *data);
69 XBT_PUBLIC(void*) SIMIX_process_self_get_data(smx_process_t self);
70 XBT_PUBLIC(smx_context_t) SIMIX_process_get_context(smx_process_t);
71 XBT_PUBLIC(void) SIMIX_process_set_context(smx_process_t p,smx_context_t c);
72 XBT_PUBLIC(int) SIMIX_process_has_pending_comms(smx_process_t process);
73
74 /****************************** Communication *********************************/
75 XBT_PUBLIC(void) SIMIX_comm_set_copy_data_callback(void (*callback) (smx_action_t, void*, size_t));
76 XBT_PUBLIC(void) SIMIX_comm_copy_pointer_callback(smx_action_t comm, void* buff, size_t buff_size);
77 XBT_PUBLIC(void) SIMIX_comm_copy_buffer_callback(smx_action_t comm, void* buff, size_t buff_size);
78 XBT_PUBLIC(void) smpi_comm_copy_data_callback(smx_action_t comm, void* buff, size_t buff_size);
79
80 XBT_PUBLIC(smx_action_t) SIMIX_comm_get_send_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data);
81 XBT_PUBLIC(int) SIMIX_comm_has_send_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data);
82 XBT_PUBLIC(int) SIMIX_comm_has_recv_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data);
83 XBT_PUBLIC(void) SIMIX_comm_finish(smx_action_t action);
84
85 /******************************************************************************/
86 /*                            SIMIX simcalls                                  */
87 /******************************************************************************/
88 /* These functions are a system call-like interface to the simulation kernel. */
89 /* They can also be called from maestro's context, and they are thread safe.  */
90 /******************************************************************************/
91
92 /******************************* Host simcalls ********************************/
93 /* TODO use handlers and keep smx_host_t hidden from higher levels */
94 XBT_PUBLIC(xbt_dict_t) simcall_host_get_dict(void);
95 XBT_PUBLIC(smx_host_t) simcall_host_get_by_name(const char *name);
96 XBT_PUBLIC(const char *) simcall_host_get_name(smx_host_t host);
97 XBT_PUBLIC(xbt_dict_t) simcall_host_get_properties(smx_host_t host);
98 XBT_PUBLIC(double) simcall_host_get_speed(smx_host_t host);
99 XBT_PUBLIC(double) simcall_host_get_available_speed(smx_host_t host);
100 /* Two possible states, 1 - CPU ON and 0 CPU OFF */
101 XBT_PUBLIC(int) simcall_host_get_state(smx_host_t host);
102 XBT_PUBLIC(void *) simcall_host_get_data(smx_host_t host);
103
104 XBT_PUBLIC(void) simcall_host_set_data(smx_host_t host, void *data);
105
106 XBT_PUBLIC(smx_action_t) simcall_host_execute(const char *name, smx_host_t host,
107                                                 double computation_amount,
108                                                 double priority);
109 XBT_PUBLIC(smx_action_t) simcall_host_parallel_execute(const char *name,
110                                                      int host_nb,
111                                                      smx_host_t *host_list,
112                                                      double *computation_amount,
113                                                      double *communication_amount,
114                                                      double amount,
115                                                      double rate);
116 XBT_PUBLIC(void) simcall_host_execution_destroy(smx_action_t execution);
117 XBT_PUBLIC(void) simcall_host_execution_cancel(smx_action_t execution);
118 XBT_PUBLIC(double) simcall_host_execution_get_remains(smx_action_t execution);
119 XBT_PUBLIC(e_smx_state_t) simcall_host_execution_get_state(smx_action_t execution);
120 XBT_PUBLIC(void) simcall_host_execution_set_priority(smx_action_t execution, double priority);
121 XBT_PUBLIC(e_smx_state_t) simcall_host_execution_wait(smx_action_t execution);
122
123
124 /**************************** Process simcalls ********************************/
125 /* Constructor and Destructor */
126 XBT_PUBLIC(void) simcall_process_create(smx_process_t *process,
127                                           const char *name,
128                                           xbt_main_func_t code,
129                                           void *data,
130                                           const char *hostname,
131                                           double kill_time,
132                                           int argc, char **argv,
133                                           xbt_dict_t properties);
134
135 XBT_PUBLIC(void) simcall_process_kill(smx_process_t process);
136 XBT_PUBLIC(void) simcall_process_killall(void);
137
138 /* Process handling */
139 XBT_PUBLIC(void) simcall_process_cleanup(smx_process_t process);
140 XBT_PUBLIC(void) simcall_process_change_host(smx_process_t process,
141                                                smx_host_t dest);
142 XBT_PUBLIC(void) simcall_process_suspend(smx_process_t process);
143 XBT_PUBLIC(void) simcall_process_resume(smx_process_t process);
144
145 /* Getters and Setters */
146 XBT_PUBLIC(int) simcall_process_count(void);
147 XBT_PUBLIC(void *) simcall_process_get_data(smx_process_t process);
148 XBT_PUBLIC(void) simcall_process_set_data(smx_process_t process, void *data);
149 XBT_PUBLIC(smx_host_t) simcall_process_get_host(smx_process_t process);
150 XBT_PUBLIC(const char *) simcall_process_get_name(smx_process_t process);
151 XBT_PUBLIC(int) simcall_process_is_suspended(smx_process_t process);
152 XBT_PUBLIC(xbt_dict_t) simcall_process_get_properties(smx_process_t host);
153
154 /* Sleep control */
155 XBT_PUBLIC(e_smx_state_t) simcall_process_sleep(double duration);
156
157 /************************** Comunication simcalls *****************************/
158 /***** Rendez-vous points *****/
159
160 XBT_PUBLIC(smx_rdv_t) simcall_rdv_create(const char *name);
161 XBT_PUBLIC(void) simcall_rdv_destroy(smx_rdv_t rvp);
162 XBT_PUBLIC(smx_rdv_t) simcall_rdv_get_by_name(const char *name);
163 XBT_PUBLIC(int) simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host);
164 XBT_PUBLIC(smx_action_t) simcall_rdv_get_head(smx_rdv_t rdv);
165
166 XBT_PUBLIC(xbt_dict_t) SIMIX_get_rdv_points(void);
167
168 /***** Communication simcalls *****/
169
170 XBT_PUBLIC(void) simcall_comm_send(smx_rdv_t rdv, double task_size,
171                                      double rate, void *src_buff,
172                                      size_t src_buff_size,
173                                      int (*match_fun)(void *, void *),
174                                      void *data, double timeout);
175
176 XBT_PUBLIC(smx_action_t) simcall_comm_isend(smx_rdv_t rdv, double task_size,
177                                               double rate, void *src_buff,
178                                               size_t src_buff_size,
179                                               int (*match_fun)(void *, void *),
180                                               void (*clean_fun)(void *),
181                                               void *data, int detached);
182
183 XBT_PUBLIC(void) simcall_comm_recv(smx_rdv_t rdv, void *dst_buff,
184                                      size_t * dst_buff_size,
185                                      int (*match_fun)(void *, void *),
186                                      void *data, double timeout);
187
188 XBT_PUBLIC(smx_action_t) simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff,
189                                               size_t * dst_buff_size,
190                                               int (*match_fun)(void *, void *),
191                                               void *data);
192
193 XBT_PUBLIC(void) simcall_comm_destroy(smx_action_t comm);
194
195 XBT_PUBLIC(void) simcall_comm_cancel(smx_action_t comm);
196
197 /* FIXME: waitany is going to be a vararg function, and should take a timeout */
198 XBT_PUBLIC(unsigned int) simcall_comm_waitany(xbt_dynar_t comms);
199 XBT_PUBLIC(void) simcall_comm_wait(smx_action_t comm, double timeout);
200 XBT_PUBLIC(int) simcall_comm_test(smx_action_t comm);
201 XBT_PUBLIC(int) simcall_comm_testany(xbt_dynar_t comms);
202
203 /* Getters and setters */
204 XBT_PUBLIC(double) simcall_comm_get_remains(smx_action_t comm);
205 XBT_PUBLIC(e_smx_state_t) simcall_comm_get_state(smx_action_t comm);
206 XBT_PUBLIC(void *) simcall_comm_get_src_data(smx_action_t comm);
207 XBT_PUBLIC(void *) simcall_comm_get_dst_data(smx_action_t comm);
208 XBT_PUBLIC(smx_process_t) simcall_comm_get_src_proc(smx_action_t comm);
209 XBT_PUBLIC(smx_process_t) simcall_comm_get_dst_proc(smx_action_t comm);
210
211 #ifdef HAVE_LATENCY_BOUND_TRACKING
212 XBT_PUBLIC(int) simcall_comm_is_latency_bounded(smx_action_t comm);
213 #endif
214
215 #ifdef HAVE_TRACING
216 /************************** Tracing handling **********************************/
217 XBT_PUBLIC(void) simcall_set_category(smx_action_t action, const char *category);
218 #endif
219
220 /************************** Synchro simcalls **********************************/
221
222 XBT_PUBLIC(smx_mutex_t) simcall_mutex_init(void);
223 XBT_PUBLIC(void) simcall_mutex_destroy(smx_mutex_t mutex);
224 XBT_PUBLIC(void) simcall_mutex_lock(smx_mutex_t mutex);
225 XBT_PUBLIC(int) simcall_mutex_trylock(smx_mutex_t mutex);
226 XBT_PUBLIC(void) simcall_mutex_unlock(smx_mutex_t mutex);
227
228 XBT_PUBLIC(smx_cond_t) simcall_cond_init(void);
229 XBT_PUBLIC(void) simcall_cond_destroy(smx_cond_t cond);
230 XBT_PUBLIC(void) simcall_cond_signal(smx_cond_t cond);
231 XBT_PUBLIC(void) simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex);
232 XBT_PUBLIC(void) simcall_cond_wait_timeout(smx_cond_t cond,
233                                          smx_mutex_t mutex,
234                                          double max_duration);
235 XBT_PUBLIC(void) simcall_cond_broadcast(smx_cond_t cond);
236
237 XBT_PUBLIC(smx_sem_t) simcall_sem_init(int capacity);
238 XBT_PUBLIC(void) simcall_sem_destroy(smx_sem_t sem);
239 XBT_PUBLIC(void) simcall_sem_release(smx_sem_t sem);
240 XBT_PUBLIC(void) simcall_sem_release_forever(smx_sem_t sem);
241 XBT_PUBLIC(int) simcall_sem_would_block(smx_sem_t sem);
242 XBT_PUBLIC(void) simcall_sem_block_onto(smx_sem_t sem);
243 XBT_PUBLIC(void) simcall_sem_acquire(smx_sem_t sem);
244 XBT_PUBLIC(void) simcall_sem_acquire_timeout(smx_sem_t sem,
245                                            double max_duration);
246 XBT_PUBLIC(unsigned int) simcall_sem_acquire_any(xbt_dynar_t sems);
247 XBT_PUBLIC(int) simcall_sem_get_capacity(smx_sem_t sem);
248
249 XBT_PUBLIC(size_t) simcall_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, smx_file_t stream);
250 XBT_PUBLIC(size_t) simcall_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, smx_file_t stream);
251 XBT_PUBLIC(smx_file_t) simcall_file_open(const char* storage, const char* path, const char* mode);
252 XBT_PUBLIC(int) simcall_file_close(const char* storage, smx_file_t fp);
253 XBT_PUBLIC(int) simcall_file_stat(const char* storage, smx_file_t fd, s_file_stat_t *buf);
254
255 SG_END_DECL()
256 #endif                          /* _SIMIX_SIMIX_H */