Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add zone.h and storage.h
[simgrid.git] / include / simgrid / msg.h
1 /* Copyright (c) 2004-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_MSG_H
7 #define SIMGRID_MSG_H
8
9 #include <simgrid/forward.h>
10 #include <simgrid/host.h>
11 #include <simgrid/instr.h>
12 #include <simgrid/plugins/live_migration.h>
13 #include <simgrid/storage.h>
14 #include <simgrid/vm.h>
15 #include <simgrid/zone.h>
16 #include <xbt/base.h>
17 #include <xbt/dict.h>
18 #include <xbt/dynar.h>
19
20 #ifdef __cplusplus
21 #include <map>
22 #include <simgrid/simix.h>
23 namespace simgrid {
24 namespace msg {
25 class Comm;
26 }
27 }
28 typedef simgrid::msg::Comm sg_msg_Comm;
29 #else
30 typedef struct msg_Comm sg_msg_Comm;
31 #endif
32
33 SG_BEGIN_DECL()
34
35 /* *************************** Network Zones ******************************** */
36 #define msg_as_t msg_netzone_t /* portability macro */
37 typedef sg_netzone_t msg_netzone_t;
38
39 #define MSG_zone_get_root() sg_zone_get_root()
40 #define MSG_zone_get_name(zone) sg_zone_get_name(zone)
41 #define MSG_zone_get_by_name(name) sg_zone_get_by_name(name)
42 #define MSG_zone_get_sons(zone, whereto) sg_zone_get_sons(zone, whereto)
43 #define MSG_zone_get_property_value(zone, name) sg_zone_get_property_value(zone, name)
44 #define MSG_zone_set_property_value(zone, name, value) sg_zone_set_property_value(zone, name, value)
45 #define MSG_zone_get_hosts(zone, whereto) sg_zone_get_hosts(zone, whereto)
46
47 /* ******************************** Hosts ************************************ */
48 typedef sg_host_t msg_host_t;
49
50 #define MSG_get_host_number() sg_host_count()
51 #define MSG_get_host_by_name(n) sg_host_by_name(n) /* Rewrite the old name into the new one transparently */
52
53 #define MSG_hosts_as_dynar() sg_hosts_as_dynar()
54
55 #define MSG_host_by_name(name) sg_host_by_name(name)
56 #define MSG_host_get_name(host) sg_host_get_name(host)
57 #define MSG_host_get_data(host) sg_host_user(host)
58 #define MSG_host_set_data(host, data) sg_host_user_set(host, data)
59 #define MSG_host_get_mounted_storage_list(host) sg_host_get_mounted_storage_list(host)
60 #define MSG_host_get_attached_storage_list(host) host_get_attached_storage_list(host)
61 #define MSG_host_get_speed(host) sg_host_speed(host)
62 #define MSG_host_get_power_peak_at(host, pstate_index) sg_host_get_pstate_speed(host, pstate_index)
63 #define MSG_host_get_core_number(host) sg_host_core_count(host)
64 #define MSG_host_self() sg_host_self()
65 #define MSG_host_get_nb_pstates(host) sg_host_get_nb_pstates(host)
66 #define MSG_host_get_pstate(h) sg_host_get_pstate(h)
67 #define MSG_host_set_pstate(h, pstate) sg_host_set_pstate(h, pstate)
68 #define MSG_host_on(h) sg_host_turn_on(h)
69 #define MSG_host_off(h) sg_host_turn_off(h)
70 #define MSG_host_is_on(h) sg_host_is_on(h)
71 #define MSG_host_is_off(h) sg_host_is_off(h)
72 #define MSG_host_get_properties(host) sg_host_get_properties(host)
73 #define MSG_host_get_property_value(host, name) sg_host_get_property_value(host, name)
74 #define MSG_host_set_property_value(host, name, value) sg_host_set_property_value(host, name, value)
75 #define MSG_host_get_process_list(host, whereto) sg_host_get_actor_list(host, whereto)
76
77 XBT_ATTRIB_DEPRECATED_v320("Use MSG_host_get_speed(): v3.20 will drop MSG_host_get_current_power_peak() "
78                            "completely.") static inline double MSG_host_get_current_power_peak(msg_host_t host)
79 {
80   return sg_host_speed(host);
81 }
82
83 /* ******************************** VMs ************************************* */
84 typedef sg_vm_t msg_vm_t;
85
86 #define MSG_vm_create_core(vm, name) sg_vm_create_core(vm, name)
87 #define MSG_vm_create_multicore(vm, name, coreAmount) sg_vm_create_multicore(vm, name, coreAmount)
88 XBT_ATTRIB_DEPRECATED_v322("Use sg_vm_create_migratable() from the live migration plugin: "
89                            "v3.22 will drop MSG_vm_create() completely.") XBT_PUBLIC sg_vm_t
90     MSG_vm_create(sg_host_t ind_pm, const char* name, int coreAmount, int ramsize, int mig_netspeed, int dp_intensity);
91
92 #define MSG_vm_is_created(vm) sg_vm_is_created(vm)
93 #define MSG_vm_is_running(vm) sg_vm_is_running(vm)
94 #define MSG_vm_is_suspended(vm) sg_vm_is_suspended(vm)
95
96 #define MSG_vm_get_name(vm) sg_vm_get_name(vm)
97 #define MSG_vm_set_ramsize(vm, size) sg_vm_set_ramsize(vm, size)
98 #define MSG_vm_get_ramsize(vm) sg_vm_get_ramsize(vm)
99 #define MSG_vm_set_bound(vm, bound) sg_vm_set_bound(vm, bound)
100 #define MSG_vm_get_pm(vm) sg_vm_get_pm(vm)
101
102 #define MSG_vm_start(vm) sg_vm_start(vm)
103 #define MSG_vm_suspend(vm) sg_vm_suspend(vm)
104 #define MSG_vm_resume(vm) sg_vm_resume(vm)
105 #define MSG_vm_shutdown(vm) sg_vm_shutdown(vm)
106 #define MSG_vm_destroy(vm) sg_vm_destroy(vm)
107
108 /* ******************************** Storage ************************************ */
109 typedef sg_storage_t msg_storage_t;
110
111 #define MSG_storage_get_name(storage) sg_storage_get_name(storage)
112 #define MSG_storage_get_by_name(name) sg_storage_get_by_name(name)
113 #define MSG_storage_get_properties(storage) sg_storage_get_properties(storage)
114 #define MSG_storage_set_property_value(storage, name, value) sg_storage_set_property_value(storage, name, value)
115 #define MSG_storage_get_property_value(storage, name) sg_storage_get_property_value(storage, name)
116 #define MSG_storages_as_dynar() sg_storages_as_dynar()
117 #define MSG_storage_set_data(storage, data) sg_storage_set_data(storage, data)
118 #define MSG_storage_get_data(storage) sg_storage_get_data(storage)
119 #define MSG_storage_get_host(storage) sg_storage_get_host(storage)
120 #define MSG_storage_read(storage, size) sg_storage_read(storage, size)
121 #define MSG_storage_write(storage, size) sg_storage_write(storage, size)
122
123 /* ******************************** File ************************************ */
124 typedef sg_file_t msg_file_t;
125 XBT_PUBLIC_DATA int sg_storage_max_file_descriptors;
126
127 /**
128  * \brief @brief Communication action.
129  * \ingroup msg_task_usage
130  *
131  * Object representing an ongoing communication between processes. Such beast is usually obtained by using #MSG_task_isend, #MSG_task_irecv or friends.
132  */
133 typedef sg_msg_Comm* msg_comm_t;
134
135 /* ******************************** Task ************************************ */
136
137 typedef struct s_simdata_task_t* simdata_task_t;
138
139 typedef struct msg_task {
140   char* name;             /**< @brief task name if any */
141   simdata_task_t simdata; /**< @brief simulator data */
142   void* data;             /**< @brief user data */
143   long long int counter;  /* task unique identifier for instrumentation */
144   char* category;         /* task category for instrumentation */
145 } s_msg_task_t;
146
147 /** @brief Task datatype.
148     @ingroup m_task_management
149
150     A <em>task</em> may then be defined by a <em>computing
151     amount</em>, a <em>message size</em> and some <em>private
152     data</em>.
153  */
154
155 typedef struct msg_task* msg_task_t;
156
157 /** \brief Default value for an uninitialized #msg_task_t.
158     \ingroup m_task_management
159 */
160 #define MSG_TASK_UNINITIALIZED NULL
161
162 /* ****************************** Process *********************************** */
163
164 /** @brief Process datatype.
165     @ingroup m_process_management
166
167     A process may be defined as a <em>code</em>, with some
168     <em>private data</em>, executing in a <em>location</em>.
169
170     You should not access directly to the fields of the pointed
171     structure, but always use the provided API to interact with
172     processes.
173  */
174 typedef s4u_Actor* msg_process_t;
175
176 /** @brief Return code of most MSG functions
177     @ingroup msg_simulation
178     @{ */
179 /* Keep these code as binary values: java bindings manipulate | of these values */
180 typedef enum {
181   MSG_OK = 0,                 /**< @brief Everything is right. Keep on going this way ! */
182   MSG_TIMEOUT = 1,            /**< @brief nothing good happened before the timer you provided elapsed */
183   MSG_TRANSFER_FAILURE = 2,   /**< @brief There has been a problem during you task
184       transfer. Either the network is down or the remote host has been
185       shutdown. */
186   MSG_HOST_FAILURE = 4,       /**< @brief System shutdown. The host on which you are
187       running has just been rebooted. Free your datastructures and
188       return now !*/
189   MSG_TASK_CANCELED = 8      /**< @brief Canceled task. This task has been canceled by somebody!*/
190 } msg_error_t;
191 /** @} */
192
193 /************************** Global ******************************************/
194 XBT_PUBLIC void MSG_config(const char* key, const char* value);
195 /** \ingroup msg_simulation
196  *  \brief Initialize the MSG internal data.
197  *  \hideinitializer
198  *
199  *  It also check that the link-time and compile-time versions of SimGrid do
200  *  match, so you should use this version instead of the #MSG_init_nocheck
201  *  function that does the same initializations, but without this check.
202  *
203  *  We allow to link against compiled versions that differ in the patch level.
204  */
205 #define MSG_init(argc,argv)  do {                                                          \
206   sg_version_check(SIMGRID_VERSION_MAJOR,SIMGRID_VERSION_MINOR,SIMGRID_VERSION_PATCH);\
207     MSG_init_nocheck(argc,argv);                                                        \
208   } while (0)
209
210 XBT_PUBLIC void MSG_init_nocheck(int* argc, char** argv);
211 XBT_PUBLIC msg_error_t MSG_main();
212 XBT_PUBLIC void MSG_function_register(const char* name, xbt_main_func_t code);
213 XBT_PUBLIC void MSG_function_register_default(xbt_main_func_t code);
214 XBT_PUBLIC void MSG_create_environment(const char* file);
215 XBT_PUBLIC void MSG_launch_application(const char* file);
216 /*Bypass the parser */
217 XBT_PUBLIC void MSG_set_function(const char* host_id, const char* function_name, xbt_dynar_t arguments);
218
219 XBT_PUBLIC double MSG_get_clock();
220 XBT_PUBLIC unsigned long int MSG_get_sent_msg();
221
222 /************************** Process handling *********************************/
223 XBT_PUBLIC msg_process_t MSG_process_create(const char* name, xbt_main_func_t code, void* data, msg_host_t host);
224 XBT_PUBLIC msg_process_t MSG_process_create_with_arguments(const char* name, xbt_main_func_t code, void* data,
225                                                            msg_host_t host, int argc, char** argv);
226 XBT_PUBLIC msg_process_t MSG_process_create_with_environment(const char* name, xbt_main_func_t code, void* data,
227                                                              msg_host_t host, int argc, char** argv,
228                                                              xbt_dict_t properties);
229
230 XBT_PUBLIC msg_process_t MSG_process_attach(const char* name, void* data, msg_host_t host, xbt_dict_t properties);
231 XBT_PUBLIC void MSG_process_detach();
232
233 XBT_PUBLIC void MSG_process_kill(msg_process_t process);
234 XBT_PUBLIC int MSG_process_killall();
235 XBT_PUBLIC msg_error_t MSG_process_migrate(msg_process_t process, msg_host_t host);
236 XBT_PUBLIC void MSG_process_yield();
237
238 XBT_PUBLIC void* MSG_process_get_data(msg_process_t process);
239 XBT_PUBLIC msg_error_t MSG_process_set_data(msg_process_t process, void* data);
240 XBT_PUBLIC void MSG_process_set_data_cleanup(void_f_pvoid_t data_cleanup);
241 XBT_PUBLIC msg_host_t MSG_process_get_host(msg_process_t process);
242 XBT_PUBLIC msg_process_t MSG_process_from_PID(int PID);
243 XBT_PUBLIC int MSG_process_get_PID(msg_process_t process);
244 XBT_PUBLIC int MSG_process_get_PPID(msg_process_t process);
245 XBT_PUBLIC const char* MSG_process_get_name(msg_process_t process);
246 XBT_PUBLIC int MSG_process_self_PID();
247 XBT_PUBLIC int MSG_process_self_PPID();
248 XBT_PUBLIC const char* MSG_process_self_name();
249 XBT_PUBLIC msg_process_t MSG_process_self();
250 XBT_PUBLIC xbt_dynar_t MSG_processes_as_dynar();
251 XBT_PUBLIC int MSG_process_get_number();
252
253 XBT_PUBLIC msg_error_t MSG_process_set_kill_time(msg_process_t process, double kill_time);
254
255 /*property handlers*/
256 XBT_PUBLIC xbt_dict_t MSG_process_get_properties(msg_process_t process);
257 XBT_PUBLIC const char* MSG_process_get_property_value(msg_process_t process, const char* name);
258
259 XBT_PUBLIC msg_error_t MSG_process_suspend(msg_process_t process);
260 XBT_PUBLIC msg_error_t MSG_process_resume(msg_process_t process);
261 XBT_PUBLIC int MSG_process_is_suspended(msg_process_t process);
262 XBT_PUBLIC void MSG_process_on_exit(int_f_pvoid_pvoid_t fun, void* data);
263 XBT_PUBLIC void MSG_process_auto_restart_set(msg_process_t process, int auto_restart);
264
265 XBT_PUBLIC void MSG_process_daemonize(msg_process_t process);
266 XBT_PUBLIC msg_process_t MSG_process_restart(msg_process_t process);
267 XBT_PUBLIC void MSG_process_ref(msg_process_t process);
268 XBT_PUBLIC void MSG_process_unref(msg_process_t process);
269
270 /************************** Task handling ************************************/
271 XBT_PUBLIC msg_task_t MSG_task_create(const char* name, double flops_amount, double bytes_amount, void* data);
272 XBT_PUBLIC msg_task_t MSG_parallel_task_create(const char* name, int host_nb, const msg_host_t* host_list,
273                                                double* flops_amount, double* bytes_amount, void* data);
274 XBT_PUBLIC void* MSG_task_get_data(msg_task_t task);
275 XBT_PUBLIC void MSG_task_set_data(msg_task_t task, void* data);
276 XBT_PUBLIC void MSG_task_set_copy_callback(void (*callback)(msg_task_t task, msg_process_t src, msg_process_t dst));
277 XBT_PUBLIC msg_process_t MSG_task_get_sender(msg_task_t task);
278 XBT_PUBLIC msg_host_t MSG_task_get_source(msg_task_t task);
279 XBT_PUBLIC const char* MSG_task_get_name(msg_task_t task);
280 XBT_PUBLIC void MSG_task_set_name(msg_task_t task, const char* name);
281 XBT_PUBLIC msg_error_t MSG_task_cancel(msg_task_t task);
282 XBT_PUBLIC msg_error_t MSG_task_destroy(msg_task_t task);
283
284 XBT_PUBLIC msg_error_t MSG_task_execute(msg_task_t task);
285 XBT_PUBLIC msg_error_t MSG_parallel_task_execute(msg_task_t task);
286 XBT_PUBLIC msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeout);
287 XBT_PUBLIC void MSG_task_set_priority(msg_task_t task, double priority);
288 XBT_PUBLIC void MSG_task_set_bound(msg_task_t task, double bound);
289
290 XBT_PUBLIC msg_error_t MSG_process_join(msg_process_t process, double timeout);
291 XBT_PUBLIC msg_error_t MSG_process_sleep(double nb_sec);
292
293 XBT_PUBLIC void MSG_task_set_flops_amount(msg_task_t task, double flops_amount);
294 XBT_PUBLIC double MSG_task_get_flops_amount(msg_task_t task);
295 XBT_PUBLIC double MSG_task_get_remaining_work_ratio(msg_task_t task);
296 XBT_PUBLIC void MSG_task_set_bytes_amount(msg_task_t task, double bytes_amount);
297
298 XBT_PUBLIC double MSG_task_get_remaining_communication(msg_task_t task);
299 XBT_PUBLIC double MSG_task_get_bytes_amount(msg_task_t task);
300
301 XBT_PUBLIC msg_error_t MSG_task_receive_ext(msg_task_t* task, const char* alias, double timeout, msg_host_t host);
302
303 XBT_PUBLIC msg_error_t MSG_task_receive_with_timeout(msg_task_t* task, const char* alias, double timeout);
304
305 XBT_PUBLIC msg_error_t MSG_task_receive(msg_task_t* task, const char* alias);
306 #define MSG_task_recv(t,a) MSG_task_receive(t,a)
307
308 XBT_PUBLIC msg_error_t MSG_task_receive_ext_bounded(msg_task_t* task, const char* alias, double timeout,
309                                                     msg_host_t host, double rate);
310
311 XBT_PUBLIC msg_error_t MSG_task_receive_with_timeout_bounded(msg_task_t* task, const char* alias, double timeout,
312                                                              double rate);
313 XBT_PUBLIC msg_error_t MSG_task_receive_bounded(msg_task_t* task, const char* alias, double rate);
314 #define MSG_task_recv_bounded(t,a,r) MSG_task_receive_bounded(t,a,r)
315
316 XBT_PUBLIC msg_comm_t MSG_task_isend(msg_task_t task, const char* alias);
317 XBT_PUBLIC msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char* alias, double maxrate);
318 XBT_ATTRIB_DEPRECATED_v320(
319     "This function will be removed from SimGrid v3.20. If you really need this function, please speak up quickly.")
320     XBT_PUBLIC msg_comm_t MSG_task_isend_with_matching(msg_task_t task, const char* alias,
321                                                        int (*match_fun)(void*, void*, void*), void* match_data);
322
323 XBT_PUBLIC void MSG_task_dsend(msg_task_t task, const char* alias, void_f_pvoid_t cleanup);
324 XBT_PUBLIC void MSG_task_dsend_bounded(msg_task_t task, const char* alias, void_f_pvoid_t cleanup, double maxrate);
325 XBT_PUBLIC msg_comm_t MSG_task_irecv(msg_task_t* task, const char* alias);
326 XBT_PUBLIC msg_comm_t MSG_task_irecv_bounded(msg_task_t* task, const char* alias, double rate);
327 XBT_PUBLIC int MSG_comm_test(msg_comm_t comm);
328 XBT_PUBLIC int MSG_comm_testany(xbt_dynar_t comms);
329 XBT_PUBLIC void MSG_comm_destroy(msg_comm_t comm);
330 XBT_PUBLIC msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout);
331 XBT_PUBLIC void MSG_comm_waitall(msg_comm_t* comm, int nb_elem, double timeout);
332 XBT_PUBLIC int MSG_comm_waitany(xbt_dynar_t comms);
333 XBT_PUBLIC msg_task_t MSG_comm_get_task(msg_comm_t comm);
334 XBT_PUBLIC msg_error_t MSG_comm_get_status(msg_comm_t comm);
335
336 XBT_PUBLIC int MSG_task_listen(const char* alias);
337 XBT_PUBLIC msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char* alias, double timeout);
338 XBT_PUBLIC msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char* alias, double timeout,
339                                                           double maxrate);
340 XBT_PUBLIC msg_error_t MSG_task_send(msg_task_t task, const char* alias);
341 XBT_PUBLIC msg_error_t MSG_task_send_bounded(msg_task_t task, const char* alias, double rate);
342 XBT_PUBLIC int MSG_task_listen_from(const char* alias);
343 XBT_PUBLIC void MSG_task_set_category(msg_task_t task, const char* category);
344 XBT_PUBLIC const char* MSG_task_get_category(msg_task_t task);
345
346 /************************** Mailbox handling ************************************/
347
348 /* @brief MSG_mailbox_set_async - set a mailbox as eager
349  * Sets the mailbox to a permanent receiver mode. Messages sent to this mailbox will then be sent just after the send
350  * is issued, without waiting for the corresponding receive.
351  * This call should be done before issuing any receive, and on the receiver's side only
352  * @param alias    The alias of the mailbox to modify.
353  */
354 XBT_PUBLIC void MSG_mailbox_set_async(const char* alias);
355
356 /************************** Action handling **********************************/
357 XBT_PUBLIC msg_error_t MSG_action_trace_run(char* path);
358 XBT_PUBLIC void MSG_action_init();
359 XBT_PUBLIC void MSG_action_exit();
360
361 /** @brief Opaque type representing a semaphore
362  *  @ingroup msg_synchro
363  *  @hideinitializer
364  */
365 typedef struct s_smx_sem_t* msg_sem_t; // Yeah that's a rename of the smx_sem_t which doesnt require smx_sem_t to be
366                                        // declared here
367 XBT_PUBLIC msg_sem_t MSG_sem_init(int initial_value);
368 XBT_PUBLIC void MSG_sem_acquire(msg_sem_t sem);
369 XBT_PUBLIC msg_error_t MSG_sem_acquire_timeout(msg_sem_t sem, double timeout);
370 XBT_PUBLIC void MSG_sem_release(msg_sem_t sem);
371 XBT_PUBLIC int MSG_sem_get_capacity(msg_sem_t sem);
372 XBT_PUBLIC void MSG_sem_destroy(msg_sem_t sem);
373 XBT_PUBLIC int MSG_sem_would_block(msg_sem_t sem);
374
375 /** @brief Opaque type representing a barrier identifier
376  *  @ingroup msg_synchro
377  *  @hideinitializer
378  */
379
380 #define MSG_BARRIER_SERIAL_PROCESS -1
381 typedef struct s_msg_bar_t* msg_bar_t;
382 XBT_PUBLIC msg_bar_t MSG_barrier_init(unsigned int count);
383 XBT_PUBLIC void MSG_barrier_destroy(msg_bar_t bar);
384 XBT_PUBLIC int MSG_barrier_wait(msg_bar_t bar);
385
386 /* ****************************************************************************************** */
387 /* Used only by the bindings -- unclean pimple, please ignore if you're not writing a binding */
388 XBT_PUBLIC smx_context_t MSG_process_get_smx_ctx(msg_process_t process);
389
390 SG_END_DECL()
391
392 #ifdef __cplusplus
393 XBT_PUBLIC msg_process_t MSG_process_create_from_stdfunc(const char* name, std::function<void()> code, void* data,
394                                                          msg_host_t host,
395                                                          std::map<std::string, std::string>* properties);
396 #endif
397
398 #endif