Logo AND Algorithmique Numérique Distribuée

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