Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New trace replayer, as fast as hell, and as boring as hell, too
[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/function_types.h"
14 #include "simix/datatypes.h"
15 #include "simix/context.h"
16
17 SG_BEGIN_DECL()
18
19 /********************************** Global ************************************/
20 /* Initialization and exit */
21 XBT_PUBLIC(void) SIMIX_global_init(int *argc, char **argv);
22 XBT_PUBLIC(void) SIMIX_clean(void);
23
24
25 XBT_PUBLIC(void) SIMIX_function_register_process_cleanup(void_pfn_smxprocess_t function);
26 XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function);
27 XBT_PUBLIC(void) SIMIX_function_register_process_kill(void_f_pvoid_t function);
28
29 /* Simulation execution */
30 XBT_PUBLIC(void) SIMIX_run(void);    
31
32 /* Timer functions FIXME: should these be public? */
33 XBT_PUBLIC(void) SIMIX_timer_set(double date, void *function, void *arg);
34 XBT_PUBLIC(double) SIMIX_timer_next(void);
35
36 XBT_PUBLIC(void) SIMIX_display_process_status(void);
37
38 /******************************* Environment **********************************/
39 XBT_PUBLIC(void) SIMIX_create_environment(const char *file);
40
41 /******************************** Deployment **********************************/
42
43 XBT_PUBLIC(void) SIMIX_function_register(const char *name, xbt_main_func_t code);
44 XBT_PUBLIC(void) SIMIX_function_register_default(xbt_main_func_t code);
45 XBT_PUBLIC(xbt_main_func_t) SIMIX_get_registered_function(const char *name);
46 XBT_PUBLIC(void) SIMIX_launch_application(const char *file);
47 XBT_PUBLIC(void) SIMIX_process_set_function(const char* process_host,
48                                             const char *process_function,
49                                             xbt_dynar_t arguments,
50                                             double process_start_time,
51                                             double process_kill_time);
52
53 /*********************************** Host *************************************/
54 XBT_PUBLIC(xbt_dict_t) SIMIX_host_get_dict(void);
55 XBT_PUBLIC(smx_host_t) SIMIX_host_get_by_name(const char *name);
56 XBT_PUBLIC(smx_host_t) SIMIX_host_self(void);
57 XBT_PUBLIC(const char*) SIMIX_host_self_get_name(void);
58 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 */
59 XBT_PUBLIC(void) SIMIX_host_self_set_data(void *data);
60 XBT_PUBLIC(void*) SIMIX_host_self_get_data(void);
61
62 /********************************* Process ************************************/
63 XBT_PUBLIC(void) SIMIX_process_cleanup(smx_process_t arg);
64 XBT_PUBLIC(int) SIMIX_process_count(void);
65 XBT_PUBLIC(smx_process_t) SIMIX_process_self(void);
66 XBT_PUBLIC(const char*) SIMIX_process_self_get_name(void);
67 XBT_PUBLIC(void) SIMIX_process_self_set_data(void *data);
68 XBT_PUBLIC(void*) SIMIX_process_self_get_data(void);
69 XBT_PUBLIC(smx_context_t) SIMIX_process_get_context(smx_process_t);
70 XBT_PUBLIC(void) SIMIX_process_set_context(smx_process_t p,smx_context_t c);
71
72 /****************************** Communication *********************************/
73 XBT_PUBLIC(void) SIMIX_comm_set_copy_data_callback(void (*callback) (smx_action_t, size_t));
74 XBT_PUBLIC(void) SIMIX_comm_copy_pointer_callback(smx_action_t comm, size_t buff_size);
75 XBT_PUBLIC(void) SIMIX_comm_copy_buffer_callback(smx_action_t comm, size_t buff_size);
76
77 /******************************************************************************/
78 /*                        SIMIX Smurf Proxy Functions                         */
79 /******************************************************************************/
80 /* These functions issue request through the Smurf proxy.                     */
81 /* They cannot be called from maestro's context, and they are thread safe.    */
82 /******************************************************************************/
83
84 XBT_INLINE XBT_PUBLIC(double) SIMIX_get_clock(void);
85
86 /******************************* Host Requests ********************************/
87 /* FIXME: use handlers and keep smx_host_t hidden from higher levels */
88 XBT_PUBLIC(xbt_dict_t) SIMIX_req_host_get_dict(void);
89 XBT_INLINE XBT_PUBLIC(smx_host_t) SIMIX_req_host_get_by_name(const char *name);
90 XBT_PUBLIC(const char *) SIMIX_req_host_get_name(smx_host_t host);
91 XBT_PUBLIC(xbt_dict_t) SIMIX_req_host_get_properties(smx_host_t host);
92 XBT_PUBLIC(double) SIMIX_req_host_get_speed(smx_host_t host);
93 XBT_PUBLIC(double) SIMIX_req_host_get_available_speed(smx_host_t host);
94 /* Two possible states, 1 - CPU ON and 0 CPU OFF */
95 XBT_PUBLIC(int) SIMIX_req_host_get_state(smx_host_t host);
96 XBT_PUBLIC(void *) SIMIX_req_host_get_data(smx_host_t host);
97
98 XBT_PUBLIC(void) SIMIX_req_host_set_data(smx_host_t host, void *data);
99
100 XBT_PUBLIC(smx_action_t) SIMIX_req_host_execute(const char *name, smx_host_t host,
101                                             double computation_amount);
102 XBT_PUBLIC(smx_action_t) SIMIX_req_host_parallel_execute(const char *name,
103                                                      int host_nb,
104                                                      smx_host_t *host_list,
105                                                      double *computation_amount,
106                                                      double *communication_amount,
107                                                      double amount,
108                                                      double rate);
109 XBT_PUBLIC(void) SIMIX_req_host_execution_destroy(smx_action_t execution);
110 XBT_PUBLIC(void) SIMIX_req_host_execution_cancel(smx_action_t execution);
111 XBT_PUBLIC(double) SIMIX_req_host_execution_get_remains(smx_action_t execution);
112 XBT_PUBLIC(e_smx_state_t) SIMIX_req_host_execution_get_state(smx_action_t execution);
113 XBT_PUBLIC(void) SIMIX_req_host_execution_set_priority(smx_action_t execution, double priority);
114 XBT_PUBLIC(void) SIMIX_req_host_execution_wait(smx_action_t execution);
115
116
117 /**************************** Process Requests ********************************/
118 /* Constructor and Destructor */
119 XBT_PUBLIC(smx_process_t) SIMIX_req_process_create(const char *name,
120                                                xbt_main_func_t code,
121                                                void *data,
122                                                const char *hostname,
123                                                int argc, char **argv,
124                                                xbt_dict_t properties);
125
126 XBT_PUBLIC(void) SIMIX_req_process_kill(smx_process_t process);
127
128 /* Process handling */
129 XBT_PUBLIC(void) SIMIX_req_process_cleanup(void *arg); /* FIXME: This function shouldn't be called from outside SIMIX */
130 XBT_PUBLIC(void) SIMIX_req_process_change_host(smx_process_t process,
131                                            const char *source, const char *dest);
132 XBT_PUBLIC(void) SIMIX_req_process_suspend(smx_process_t process);
133 XBT_PUBLIC(void) SIMIX_req_process_resume(smx_process_t process);
134
135 /* Getters and Setters */
136 XBT_PUBLIC(int) SIMIX_req_process_count(void);
137 XBT_PUBLIC(void *) SIMIX_req_process_get_data(smx_process_t process);
138 XBT_PUBLIC(void) SIMIX_req_process_set_data(smx_process_t process, void *data);
139 XBT_INLINE XBT_PUBLIC(smx_host_t) SIMIX_req_process_get_host(smx_process_t process);
140 XBT_PUBLIC(const char *) SIMIX_req_process_get_name(smx_process_t process);
141 XBT_PUBLIC(int) SIMIX_req_process_is_suspended(smx_process_t process);
142 XBT_PUBLIC(xbt_dict_t) SIMIX_req_process_get_properties(smx_process_t host);
143
144 /* Sleep control */
145 XBT_PUBLIC(e_smx_state_t) SIMIX_req_process_sleep(double duration);
146
147 /************************** Comunication Requests *****************************/
148 /***** Rendez-vous points *****/
149 XBT_PUBLIC(smx_rdv_t) SIMIX_req_rdv_create(const char *name);
150 XBT_PUBLIC(void) SIMIX_req_rdv_destroy(smx_rdv_t rvp);
151 XBT_PUBLIC(smx_rdv_t) SIMIX_req_rdv_get_by_name(const char *name);
152 XBT_PUBLIC(int) SIMIX_req_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host);
153 XBT_PUBLIC(smx_action_t) SIMIX_req_rdv_get_head(smx_rdv_t rdv);
154
155 /***** Communication Requests *****/
156
157 /* Constructors and Destructor */
158 XBT_PUBLIC(smx_action_t) SIMIX_req_comm_isend(smx_rdv_t rdv, double task_size,
159                                            double rate, void *src_buff,
160                                            size_t src_buff_size,
161                                            int (*match_fun)(void *, void *),
162                                            void *data);
163
164 XBT_PUBLIC(smx_action_t) SIMIX_req_comm_irecv(smx_rdv_t rdv, void *dst_buff,
165                                            size_t * dst_buff_size,
166                                            int (*match_fun)(void *, void *),
167                                            void *data);
168
169 XBT_PUBLIC(void) SIMIX_req_comm_destroy(smx_action_t comm);
170
171 /* Communication handling */
172 XBT_INLINE XBT_PUBLIC(void) SIMIX_req_comm_cancel(smx_action_t comm);
173
174 /* FIXME: waitany is going to be a vararg function, and should take a timeout */
175 XBT_PUBLIC(unsigned int) SIMIX_req_comm_waitany(xbt_dynar_t comms);
176 XBT_PUBLIC(void) SIMIX_req_comm_wait(smx_action_t comm, double timeout);
177 XBT_PUBLIC(int) SIMIX_req_comm_test(smx_action_t comm);
178 XBT_PUBLIC(int) SIMIX_req_comm_testany(xbt_dynar_t comms);
179
180 /* Getters and setters */
181 XBT_PUBLIC(double) SIMIX_req_comm_get_remains(smx_action_t comm);
182 XBT_PUBLIC(e_smx_state_t) SIMIX_req_comm_get_state(smx_action_t comm);
183 XBT_PUBLIC(void *) SIMIX_req_comm_get_src_data(smx_action_t comm);
184 XBT_PUBLIC(void *) SIMIX_req_comm_get_dst_data(smx_action_t comm);
185 XBT_PUBLIC(void *) SIMIX_req_comm_get_src_buff(smx_action_t comm);
186 XBT_PUBLIC(void *) SIMIX_req_comm_get_dst_buff(smx_action_t comm);
187 XBT_PUBLIC(size_t) SIMIX_req_comm_get_src_buff_size(smx_action_t comm);
188 XBT_PUBLIC(size_t) SIMIX_req_comm_get_dst_buff_size(smx_action_t comm);
189 XBT_PUBLIC(smx_process_t) SIMIX_req_comm_get_src_proc(smx_action_t comm);
190 XBT_PUBLIC(smx_process_t) SIMIX_req_comm_get_dst_proc(smx_action_t comm);
191 XBT_PUBLIC(void) SIMIX_req_comm_set_copy_data_callback(void (*callback)(smx_action_t,size_t));
192 XBT_PUBLIC(void) SIMIX_req_comm_copy_pointer_callback(smx_action_t comm, size_t buff_size);
193 XBT_PUBLIC(void) SIMIX_req_comm_copy_buffer_callback(smx_action_t comm, size_t buff_size);
194
195 #ifdef HAVE_LATENCY_BOUND_TRACKING
196 XBT_PUBLIC(int) SIMIX_req_comm_is_latency_bounded(smx_action_t comm);
197 #endif
198
199 #ifdef HAVE_TRACING
200 /************************** Tracing handling **********************************/
201 XBT_PUBLIC(void) SIMIX_req_set_category(smx_action_t action, const char *category);
202 #endif
203
204 /************************** Synchro handling **********************************/
205
206 XBT_PUBLIC(smx_mutex_t) SIMIX_req_mutex_init(void);
207 XBT_PUBLIC(void) SIMIX_req_mutex_destroy(smx_mutex_t mutex);
208 XBT_PUBLIC(void) SIMIX_req_mutex_lock(smx_mutex_t mutex);
209 XBT_PUBLIC(int) SIMIX_req_mutex_trylock(smx_mutex_t mutex);
210 XBT_PUBLIC(void) SIMIX_req_mutex_unlock(smx_mutex_t mutex);
211
212 XBT_PUBLIC(smx_cond_t) SIMIX_req_cond_init(void);
213 XBT_PUBLIC(void) SIMIX_req_cond_destroy(smx_cond_t cond);
214 XBT_PUBLIC(void) SIMIX_req_cond_signal(smx_cond_t cond);
215 XBT_PUBLIC(void) SIMIX_req_cond_wait(smx_cond_t cond, smx_mutex_t mutex);
216 XBT_PUBLIC(void) SIMIX_req_cond_wait_timeout(smx_cond_t cond,
217                                          smx_mutex_t mutex,
218                                          double max_duration);
219 XBT_PUBLIC(void) SIMIX_req_cond_broadcast(smx_cond_t cond);
220
221 XBT_PUBLIC(smx_sem_t) SIMIX_req_sem_init(int capacity);
222 XBT_PUBLIC(void) SIMIX_req_sem_destroy(smx_sem_t sem);
223 XBT_PUBLIC(void) SIMIX_req_sem_release(smx_sem_t sem);
224 XBT_PUBLIC(void) SIMIX_req_sem_release_forever(smx_sem_t sem);
225 XBT_PUBLIC(int) SIMIX_req_sem_would_block(smx_sem_t sem);
226 XBT_PUBLIC(void) SIMIX_req_sem_block_onto(smx_sem_t sem);
227 XBT_PUBLIC(void) SIMIX_req_sem_acquire(smx_sem_t sem);
228 XBT_PUBLIC(void) SIMIX_req_sem_acquire_timeout(smx_sem_t sem,
229                                            double max_duration);
230 XBT_PUBLIC(unsigned int) SIMIX_req_sem_acquire_any(xbt_dynar_t sems);
231 XBT_PUBLIC(int) SIMIX_req_sem_get_capacity(smx_sem_t sem);
232
233 /* functions to let the state machine context factory mess with simix flow */
234 XBT_PUBLIC(void*) SIMIX_request_get_result(int id);
235 XBT_PUBLIC(int) SIMIX_request_last_id(void);
236
237 SG_END_DECL()
238 #endif                          /* _SIMIX_SIMIX_H */