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