1 /* Copyright (c) 2004-2020. 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. */
6 #include "simgrid/Exception.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "src/msg/msg_private.hpp"
9 #include "xbt/functional.hpp"
11 #define MSG_CALL(type, oldname, args)
13 /* ************************** Engine *************************** */
14 void MSG_create_environment(const char* filename)
16 simgrid_load_platform(filename);
19 void MSG_launch_application(const char* filename)
21 simgrid_load_deployment(filename);
23 msg_error_t MSG_main()
28 void MSG_function_register(const char* name, int (*code)(int, char**))
30 simgrid::kernel::actor::ActorCodeFactory code_factory = [code](std::vector<std::string> args) {
31 return simgrid::xbt::wrap_main(code, std::move(args));
33 simgrid::s4u::Engine::get_instance()->register_function(name, code_factory);
35 void MSG_function_register_default(int (*code)(int, char**))
37 simgrid::s4u::Engine::get_instance()->register_default(
38 [code](std::vector<std::string> args) { return simgrid::xbt::wrap_main(code, std::move(args)); });
40 double MSG_get_clock()
42 return simgrid_get_clock();
45 /* ************************** Mailboxes ************************ */
46 void MSG_mailbox_set_async(const char* alias)
48 sg_mailbox_set_receiver(alias);
50 int MSG_task_listen(const char* alias)
52 return sg_mailbox_listen(alias);
55 /* ************************** Actors *************************** */
56 void MSG_process_on_exit(int_f_int_pvoid_t fun, void* data)
58 sg_actor_on_exit(fun, data);
61 int MSG_process_get_PID(const_sg_actor_t actor)
63 return sg_actor_get_PID(actor);
65 int MSG_process_get_PPID(const_sg_actor_t actor)
67 return sg_actor_get_PPID(actor);
69 msg_process_t MSG_process_from_PID(int PID)
71 return sg_actor_by_PID(PID);
73 const char* MSG_process_get_name(const_sg_actor_t actor)
75 return sg_actor_get_name(actor);
77 sg_host_t MSG_process_get_host(const_sg_actor_t actor)
79 return sg_actor_get_host(actor);
81 xbt_dict_t MSG_process_get_properties(const_sg_actor_t actor)
83 return sg_actor_get_properties(actor);
85 const char* MSG_process_get_property_value(const_sg_actor_t actor, const char* name)
87 return sg_actor_get_property_value(actor, name);
89 void MSG_process_suspend(sg_actor_t actor)
91 sg_actor_suspend(actor);
93 void MSG_process_resume(sg_actor_t actor)
95 sg_actor_resume(actor);
97 int MSG_process_is_suspended(sg_actor_t actor)
99 return sg_actor_is_suspended(actor);
101 void MSG_process_restart(sg_actor_t actor)
103 sg_actor_restart(actor);
105 void MSG_process_auto_restart_set(sg_actor_t actor, int auto_restart)
107 sg_actor_set_auto_restart(actor, auto_restart);
110 void MSG_process_daemonize(sg_actor_t actor)
112 sg_actor_daemonize(actor);
114 void MSG_process_migrate(sg_actor_t actor, sg_host_t host)
116 sg_actor_set_host(actor, host);
118 void MSG_process_join(sg_actor_t actor, double timeout)
120 sg_actor_join(actor, timeout);
122 void MSG_process_kill(sg_actor_t actor)
124 sg_actor_kill(actor);
126 void MSG_process_killall()
130 void MSG_process_set_kill_time(sg_actor_t actor, double kill_time)
132 sg_actor_set_kill_time(actor, kill_time);
134 void MSG_process_yield()
139 msg_error_t MSG_process_sleep(double duration)
142 sg_actor_sleep_for(duration);
144 } catch (const simgrid::HostFailureException&) {
145 return MSG_HOST_FAILURE;
149 /** @brief Returns the user data of a process.
151 * This function checks whether @a process is a valid pointer and returns the user data associated to this process.
153 void* MSG_process_get_data(const_sg_actor_t process)
155 xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!");
157 /* get from SIMIX the MSG process data, and then the user data */
158 return sg_actor_data(process);
161 /** @brief Sets the user data of a process.
163 * This function checks whether @a process is a valid pointer and sets the user data associated to this process.
165 msg_error_t MSG_process_set_data(msg_process_t process, void* data)
167 xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!");
168 sg_actor_data_set(process, data);
173 msg_process_t MSG_process_attach(const char* name, void* data, msg_host_t host, xbt_dict_t properties)
175 return sg_actor_attach(name, data, host, properties);
178 void MSG_process_detach()
182 aid_t MSG_process_self_PID()
184 return sg_actor_self_get_pid();
187 /** @brief Return the PPID of the current process.
189 * This function returns the PID of the parent of the currently running #msg_process_t.
191 aid_t MSG_process_self_PPID()
193 return sg_actor_self_get_ppid();
196 /** @brief Return the name of the current process. */
197 const char* MSG_process_self_name()
199 return sg_actor_self_get_name();
201 /** @brief Return the current process.
203 * This function returns the currently running #msg_process_t.
205 msg_process_t MSG_process_self()
207 return sg_actor_self();
210 /** @brief Take an extra reference on that process to prevent it to be garbage-collected */
211 void MSG_process_ref(const_sg_actor_t process)
213 sg_actor_ref(process);
215 /** @brief Release a reference on that process so that it can get be garbage-collected */
216 void MSG_process_unref(const_sg_actor_t process)
218 sg_actor_unref(process);
220 /** @brief Return the current number MSG processes. */
221 int MSG_process_get_number()
223 return simgrid_get_actor_count();
225 /* ************************** NetZones *************************** */
226 sg_netzone_t MSG_zone_get_root()
228 return sg_zone_get_root();
230 const char* MSG_zone_get_name(const_sg_netzone_t zone)
232 return sg_zone_get_name(zone);
234 sg_netzone_t MSG_zone_get_by_name(const char* name)
236 return sg_zone_get_by_name(name);
238 void MSG_zone_get_sons(const_sg_netzone_t zone, xbt_dict_t whereto)
240 return sg_zone_get_sons(zone, whereto);
242 const char* MSG_zone_get_property_value(const_sg_netzone_t zone, const char* name)
244 return sg_zone_get_property_value(zone, name);
246 void MSG_zone_set_property_value(sg_netzone_t zone, const char* name, const char* value)
248 sg_zone_set_property_value(zone, name, value);
250 void MSG_zone_get_hosts(const_sg_netzone_t zone, xbt_dynar_t whereto)
252 sg_zone_get_hosts(zone, whereto);
255 /* ************************** Storages *************************** */
256 const char* MSG_storage_get_name(const_sg_storage_t storage)
258 return sg_storage_get_name(storage);
260 sg_storage_t MSG_storage_get_by_name(const char* name)
262 return sg_storage_get_by_name(name);
264 xbt_dict_t MSG_storage_get_properties(const_sg_storage_t storage)
266 return sg_storage_get_properties(storage);
268 void MSG_storage_set_property_value(sg_storage_t storage, const char* name, const char* value)
270 sg_storage_set_property_value(storage, name, value);
272 const char* MSG_storage_get_property_value(const_sg_storage_t storage, const char* name)
274 return sg_storage_get_property_value(storage, name);
276 xbt_dynar_t MSG_storages_as_dynar()
278 return sg_storages_as_dynar();
280 void MSG_storage_set_data(sg_storage_t storage, void* data)
282 sg_storage_set_data(storage, data);
284 void* MSG_storage_get_data(const_sg_storage_t storage)
286 return sg_storage_get_data(storage);
288 const char* MSG_storage_get_host(const_sg_storage_t storage)
290 return sg_storage_get_host(storage);
292 sg_size_t MSG_storage_read(sg_storage_t storage, sg_size_t size)
294 return sg_storage_read(storage, size);
296 sg_size_t MSG_storage_write(sg_storage_t storage, sg_size_t size)
298 return sg_storage_write(storage, size);
301 /* ************************** hosts *************************** */
302 xbt_dynar_t MSG_hosts_as_dynar()
304 return sg_hosts_as_dynar();
306 size_t MSG_get_host_number()
308 return sg_host_count();
310 sg_host_t MSG_get_host_by_name(const char* name)
312 return sg_host_by_name(name);
314 sg_host_t MSG_host_by_name(const char* name)
316 return sg_host_by_name(name);
318 const char* MSG_host_get_name(const_sg_host_t host)
320 return sg_host_get_name(host);
322 void* MSG_host_get_data(const_sg_host_t host)
324 return sg_host_data(host);
326 void MSG_host_set_data(sg_host_t host, void* data)
328 return sg_host_data_set(host, data);
330 xbt_dict_t MSG_host_get_mounted_storage_list(sg_host_t host) // XBT_ATTRIB_DEPRECATED_v330
332 return sg_host_get_mounted_storage_list(host);
334 xbt_dynar_t MSG_host_get_attached_storage_lists(const_sg_host_t host)
336 return sg_host_get_attached_storage_list(host);
338 double MSG_host_get_speed(const_sg_host_t host)
340 return sg_host_speed(host);
342 double MSG_host_get_power_peak_at(const_sg_host_t host, int pstate_index)
344 return sg_host_get_pstate_speed(host, pstate_index);
346 int MSG_host_get_core_number(const_sg_host_t host)
348 return sg_host_core_count(host);
350 int MSG_host_get_nb_pstates(const_sg_host_t host)
352 return sg_host_get_nb_pstates(host);
354 int MSG_host_get_pstate(const_sg_host_t host)
356 return sg_host_get_pstate(host);
358 void MSG_host_set_pstate(sg_host_t host, int pstate)
360 sg_host_set_pstate(host, pstate);
362 void MSG_host_on(sg_host_t h)
366 void MSG_host_off(sg_host_t h)
370 int MSG_host_is_on(const_sg_host_t h)
372 return sg_host_is_on(h);
374 xbt_dict_t MSG_host_get_properties(const_sg_host_t host)
376 return sg_host_get_properties(host);
378 const char* MSG_host_get_property_value(const_sg_host_t host, const char* name)
380 return sg_host_get_property_value(host, name);
382 void MSG_host_set_property_value(sg_host_t host, const char* name, const char* value)
384 sg_host_set_property_value(host, name, value);
386 void MSG_host_get_process_list(const_sg_host_t host, xbt_dynar_t whereto)
388 sg_host_get_actor_list(host, whereto);
390 sg_host_t MSG_host_self()
392 return sg_host_self();
395 double MSG_host_get_load(const_sg_host_t host)
397 return sg_host_load(host);
399 /* ************************** Virtual Machines *************************** */
400 sg_vm_t MSG_vm_create_core(sg_host_t pm, const char* name)
402 return sg_vm_create_core(pm, name);
404 sg_vm_t MSG_vm_create_multicore(sg_host_t pm, const char* name, int coreAmount)
406 return sg_vm_create_multicore(pm, name, coreAmount);
408 int MSG_vm_is_created(sg_vm_t vm)
410 return sg_vm_is_created(vm);
412 int MSG_vm_is_running(sg_vm_t vm)
414 return sg_vm_is_running(vm);
416 int MSG_vm_is_suspended(sg_vm_t vm)
418 return sg_vm_is_suspended(vm);
420 const char* MSG_vm_get_name(const_sg_vm_t vm)
422 return sg_vm_get_name(vm);
424 void MSG_vm_set_ramsize(sg_vm_t vm, size_t size)
426 sg_vm_set_ramsize(vm, size);
428 size_t MSG_vm_get_ramsize(const_sg_vm_t vm)
430 return sg_vm_get_ramsize(vm);
432 sg_host_t MSG_vm_get_pm(const_sg_vm_t vm)
434 return sg_vm_get_pm(vm);
436 void MSG_vm_set_bound(sg_vm_t vm, double bound)
438 sg_vm_set_bound(vm, bound);
440 void MSG_vm_start(sg_vm_t vm)
444 void MSG_vm_suspend(sg_vm_t vm)
448 void MSG_vm_resume(sg_vm_t vm)
452 void MSG_vm_shutdown(sg_vm_t vm)
456 void MSG_vm_destroy(sg_vm_t vm)
460 /********* barriers ************/
461 sg_bar_t MSG_barrier_init(unsigned int count)
463 return sg_barrier_init(count);
466 void MSG_barrier_destroy(const_sg_bar_t bar)
468 sg_barrier_destroy(bar);
471 int MSG_barrier_wait(sg_bar_t bar)
473 return sg_barrier_wait(bar);
476 sg_sem_t MSG_sem_init(int initial_value)
478 return sg_sem_init(initial_value);
480 void MSG_sem_acquire(sg_sem_t sem)
484 int MSG_sem_acquire_timeout(sg_sem_t sem, double timeout)
486 return sg_sem_acquire_timeout(sem, timeout);
488 void MSG_sem_release(sg_sem_t sem)
492 int MSG_sem_get_capacity(sg_sem_t sem)
494 return sg_sem_get_capacity(sem);
496 void MSG_sem_destroy(const_sg_sem_t sem)
500 int MSG_sem_would_block(sg_sem_t sem)
502 return sg_sem_would_block(sem);