Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add sg_actor_list() and sg_actor_count()
[simgrid.git] / src / msg / msg_legacy.cpp
1 /* Copyright (c) 2004-2020. 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 #include "simgrid/Exception.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "src/msg/msg_private.hpp"
9 #include "xbt/functional.hpp"
10
11 #define MSG_CALL(type, oldname, args)
12
13 /* ************************** Engine *************************** */
14 void MSG_create_environment(const char* filename)
15 {
16   simgrid_load_platform(filename);
17 }
18
19 void MSG_launch_application(const char* filename)
20 {
21   simgrid_load_deployment(filename);
22 }
23 msg_error_t MSG_main()
24 {
25   simgrid_run();
26   return MSG_OK;
27 }
28 void MSG_function_register(const char* name, int (*code)(int, char**))
29 {
30   simgrid::kernel::actor::ActorCodeFactory code_factory = [code](std::vector<std::string> args) {
31     return simgrid::xbt::wrap_main(code, std::move(args));
32   };
33   simgrid::s4u::Engine::get_instance()->register_function(name, code_factory);
34 }
35 void MSG_function_register_default(int (*code)(int, char**))
36 {
37   simgrid::s4u::Engine::get_instance()->register_default(
38       [code](std::vector<std::string> args) { return simgrid::xbt::wrap_main(code, std::move(args)); });
39 }
40 double MSG_get_clock()
41 {
42   return simgrid_get_clock();
43 }
44
45 /* ************************** Mailboxes ************************ */
46 void MSG_mailbox_set_async(const char* alias)
47 {
48   sg_mailbox_set_receiver(alias);
49 }
50 int MSG_task_listen(const char* alias)
51 {
52   return sg_mailbox_listen(alias);
53 }
54
55 /* ************************** Actors *************************** */
56 void MSG_process_on_exit(int_f_int_pvoid_t fun, void* data)
57 {
58   sg_actor_on_exit(fun, data);
59 }
60
61 int MSG_process_get_PID(const_sg_actor_t actor)
62 {
63   return sg_actor_get_PID(actor);
64 }
65 int MSG_process_get_PPID(const_sg_actor_t actor)
66 {
67   return sg_actor_get_PPID(actor);
68 }
69 msg_process_t MSG_process_from_PID(int PID)
70 {
71   return sg_actor_by_PID(PID);
72 }
73 const char* MSG_process_get_name(const_sg_actor_t actor)
74 {
75   return sg_actor_get_name(actor);
76 }
77 sg_host_t MSG_process_get_host(const_sg_actor_t actor)
78 {
79   return sg_actor_get_host(actor);
80 }
81 xbt_dict_t MSG_process_get_properties(const_sg_actor_t actor)
82 {
83   return sg_actor_get_properties(actor);
84 }
85 const char* MSG_process_get_property_value(const_sg_actor_t actor, const char* name)
86 {
87   return sg_actor_get_property_value(actor, name);
88 }
89 void MSG_process_suspend(sg_actor_t actor)
90 {
91   sg_actor_suspend(actor);
92 }
93 void MSG_process_resume(sg_actor_t actor)
94 {
95   sg_actor_resume(actor);
96 }
97 int MSG_process_is_suspended(sg_actor_t actor)
98 {
99   return sg_actor_is_suspended(actor);
100 }
101 void MSG_process_restart(sg_actor_t actor)
102 {
103   sg_actor_restart(actor);
104 }
105 void MSG_process_auto_restart_set(sg_actor_t actor, int auto_restart)
106 {
107   sg_actor_set_auto_restart(actor, auto_restart);
108 }
109
110 void MSG_process_daemonize(sg_actor_t actor)
111 {
112   sg_actor_daemonize(actor);
113 }
114 void MSG_process_migrate(sg_actor_t actor, sg_host_t host)
115 {
116   sg_actor_set_host(actor, host);
117 }
118 void MSG_process_join(sg_actor_t actor, double timeout)
119 {
120   sg_actor_join(actor, timeout);
121 }
122 void MSG_process_kill(sg_actor_t actor)
123 {
124   sg_actor_kill(actor);
125 }
126 void MSG_process_killall()
127 {
128   sg_actor_kill_all();
129 }
130 void MSG_process_set_kill_time(sg_actor_t actor, double kill_time)
131 {
132   sg_actor_set_kill_time(actor, kill_time);
133 }
134 void MSG_process_yield()
135 {
136   sg_actor_yield();
137 }
138
139 msg_error_t MSG_process_sleep(double duration)
140 {
141   try {
142     sg_actor_sleep_for(duration);
143     return MSG_OK;
144   } catch (const simgrid::HostFailureException&) {
145     return MSG_HOST_FAILURE;
146   }
147 }
148
149 /** @brief Returns the user data of a process.
150  *
151  * This function checks whether @a process is a valid pointer and returns the user data associated to this process.
152  */
153 void* MSG_process_get_data(const_sg_actor_t process)
154 {
155   xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!");
156
157   /* get from SIMIX the MSG process data, and then the user data */
158   return sg_actor_data(process);
159 }
160
161 /** @brief Sets the user data of a process.
162  *
163  * This function checks whether @a process is a valid pointer and sets the user data associated to this process.
164  */
165 msg_error_t MSG_process_set_data(msg_process_t process, void* data)
166 {
167   xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!");
168   sg_actor_data_set(process, data);
169
170   return MSG_OK;
171 }
172
173 msg_process_t MSG_process_attach(const char* name, void* data, msg_host_t host, xbt_dict_t properties)
174 {
175   return sg_actor_attach(name, data, host, properties);
176 }
177
178 void MSG_process_detach()
179 {
180   sg_actor_detach();
181 }
182 aid_t MSG_process_self_PID()
183 {
184   return sg_actor_self_get_pid();
185 }
186
187 /** @brief Return the PPID of the current process.
188  *
189  * This function returns the PID of the parent of the currently running #msg_process_t.
190  */
191 aid_t MSG_process_self_PPID()
192 {
193   return sg_actor_self_get_ppid();
194 }
195
196 /** @brief Return the name of the current process. */
197 const char* MSG_process_self_name()
198 {
199   return sg_actor_self_get_name();
200 }
201 /** @brief Return the current process.
202  *
203  * This function returns the currently running #msg_process_t.
204  */
205 msg_process_t MSG_process_self()
206 {
207   return sg_actor_self();
208 }
209
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)
212 {
213   sg_actor_ref(process);
214 }
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)
217 {
218   sg_actor_unref(process);
219 }
220 /** @brief Return the current number MSG processes. */
221 int MSG_process_get_number() // XBT_ATTRIB_DEPRECATED_v330
222 {
223   return sg_actor_count();
224 }
225 /* ************************** NetZones *************************** */
226 sg_netzone_t MSG_zone_get_root()
227 {
228   return sg_zone_get_root();
229 }
230 const char* MSG_zone_get_name(const_sg_netzone_t zone)
231 {
232   return sg_zone_get_name(zone);
233 }
234 sg_netzone_t MSG_zone_get_by_name(const char* name)
235 {
236   return sg_zone_get_by_name(name);
237 }
238 void MSG_zone_get_sons(const_sg_netzone_t zone, xbt_dict_t whereto)
239 {
240   return sg_zone_get_sons(zone, whereto);
241 }
242 const char* MSG_zone_get_property_value(const_sg_netzone_t zone, const char* name)
243 {
244   return sg_zone_get_property_value(zone, name);
245 }
246 void MSG_zone_set_property_value(sg_netzone_t zone, const char* name, const char* value)
247 {
248   sg_zone_set_property_value(zone, name, value);
249 }
250 void MSG_zone_get_hosts(const_sg_netzone_t zone, xbt_dynar_t whereto)
251 {
252   sg_zone_get_hosts(zone, whereto);
253 }
254
255 /* ************************** Storages *************************** */
256 const char* MSG_storage_get_name(const_sg_storage_t storage)
257 {
258   return sg_storage_get_name(storage);
259 }
260 sg_storage_t MSG_storage_get_by_name(const char* name)
261 {
262   return sg_storage_get_by_name(name);
263 }
264 xbt_dict_t MSG_storage_get_properties(const_sg_storage_t storage)
265 {
266   return sg_storage_get_properties(storage);
267 }
268 void MSG_storage_set_property_value(sg_storage_t storage, const char* name, const char* value)
269 {
270   sg_storage_set_property_value(storage, name, value);
271 }
272 const char* MSG_storage_get_property_value(const_sg_storage_t storage, const char* name)
273 {
274   return sg_storage_get_property_value(storage, name);
275 }
276 xbt_dynar_t MSG_storages_as_dynar()
277 {
278   return sg_storages_as_dynar();
279 }
280 void MSG_storage_set_data(sg_storage_t storage, void* data)
281 {
282   sg_storage_set_data(storage, data);
283 }
284 void* MSG_storage_get_data(const_sg_storage_t storage)
285 {
286   return sg_storage_get_data(storage);
287 }
288 const char* MSG_storage_get_host(const_sg_storage_t storage)
289 {
290   return sg_storage_get_host(storage);
291 }
292 sg_size_t MSG_storage_read(sg_storage_t storage, sg_size_t size)
293 {
294   return sg_storage_read(storage, size);
295 }
296 sg_size_t MSG_storage_write(sg_storage_t storage, sg_size_t size)
297 {
298   return sg_storage_write(storage, size);
299 }
300
301 /* ************************** hosts *************************** */
302 xbt_dynar_t MSG_hosts_as_dynar() // XBT_ATTRIB_DEPRECATED_v330
303 {
304   size_t host_count = sg_host_count();
305   sg_host_t* list   = sg_host_list();
306
307   xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr);
308   for (size_t i = 0; i < host_count; i++)
309     xbt_dynar_push_as(res, sg_host_t, list[i]);
310   xbt_free(list);
311
312   return res;
313 }
314 size_t MSG_get_host_number()
315 {
316   return sg_host_count();
317 }
318 sg_host_t MSG_get_host_by_name(const char* name)
319 {
320   return sg_host_by_name(name);
321 }
322 sg_host_t MSG_host_by_name(const char* name)
323 {
324   return sg_host_by_name(name);
325 }
326 const char* MSG_host_get_name(const_sg_host_t host)
327 {
328   return sg_host_get_name(host);
329 }
330 void* MSG_host_get_data(const_sg_host_t host)
331 {
332   return sg_host_data(host);
333 }
334 void MSG_host_set_data(sg_host_t host, void* data)
335 {
336   return sg_host_data_set(host, data);
337 }
338 xbt_dict_t MSG_host_get_mounted_storage_list(sg_host_t host) // XBT_ATTRIB_DEPRECATED_v330
339 {
340   return sg_host_get_mounted_storage_list(host);
341 }
342 xbt_dynar_t MSG_host_get_attached_storage_lists(const_sg_host_t host)
343 {
344   return sg_host_get_attached_storage_list(host);
345 }
346 double MSG_host_get_speed(const_sg_host_t host)
347 {
348   return sg_host_speed(host);
349 }
350 double MSG_host_get_power_peak_at(const_sg_host_t host, int pstate_index)
351 {
352   return sg_host_get_pstate_speed(host, pstate_index);
353 }
354 int MSG_host_get_core_number(const_sg_host_t host)
355 {
356   return sg_host_core_count(host);
357 }
358 int MSG_host_get_nb_pstates(const_sg_host_t host)
359 {
360   return sg_host_get_nb_pstates(host);
361 }
362 int MSG_host_get_pstate(const_sg_host_t host)
363 {
364   return sg_host_get_pstate(host);
365 }
366 void MSG_host_set_pstate(sg_host_t host, int pstate)
367 {
368   sg_host_set_pstate(host, pstate);
369 }
370 void MSG_host_on(sg_host_t h)
371 {
372   sg_host_turn_on(h);
373 }
374 void MSG_host_off(sg_host_t h)
375 {
376   sg_host_turn_off(h);
377 }
378 int MSG_host_is_on(const_sg_host_t h)
379 {
380   return sg_host_is_on(h);
381 }
382 xbt_dict_t MSG_host_get_properties(const_sg_host_t host)
383 {
384   return sg_host_get_properties(host);
385 }
386 const char* MSG_host_get_property_value(const_sg_host_t host, const char* name)
387 {
388   return sg_host_get_property_value(host, name);
389 }
390 void MSG_host_set_property_value(sg_host_t host, const char* name, const char* value)
391 {
392   sg_host_set_property_value(host, name, value);
393 }
394 void MSG_host_get_process_list(const_sg_host_t host, xbt_dynar_t whereto)
395 {
396   sg_host_get_actor_list(host, whereto);
397 }
398 sg_host_t MSG_host_self()
399 {
400   return sg_host_self();
401 }
402
403 double MSG_host_get_load(const_sg_host_t host)
404 {
405   return sg_host_load(host);
406 }
407 /* ************************** Virtual Machines *************************** */
408 sg_vm_t MSG_vm_create_core(sg_host_t pm, const char* name)
409 {
410   return sg_vm_create_core(pm, name);
411 }
412 sg_vm_t MSG_vm_create_multicore(sg_host_t pm, const char* name, int coreAmount)
413 {
414   return sg_vm_create_multicore(pm, name, coreAmount);
415 }
416 int MSG_vm_is_created(sg_vm_t vm)
417 {
418   return sg_vm_is_created(vm);
419 }
420 int MSG_vm_is_running(sg_vm_t vm)
421 {
422   return sg_vm_is_running(vm);
423 }
424 int MSG_vm_is_suspended(sg_vm_t vm)
425 {
426   return sg_vm_is_suspended(vm);
427 }
428 const char* MSG_vm_get_name(const_sg_vm_t vm)
429 {
430   return sg_vm_get_name(vm);
431 }
432 void MSG_vm_set_ramsize(sg_vm_t vm, size_t size)
433 {
434   sg_vm_set_ramsize(vm, size);
435 }
436 size_t MSG_vm_get_ramsize(const_sg_vm_t vm)
437 {
438   return sg_vm_get_ramsize(vm);
439 }
440 sg_host_t MSG_vm_get_pm(const_sg_vm_t vm)
441 {
442   return sg_vm_get_pm(vm);
443 }
444 void MSG_vm_set_bound(sg_vm_t vm, double bound)
445 {
446   sg_vm_set_bound(vm, bound);
447 }
448 void MSG_vm_start(sg_vm_t vm)
449 {
450   sg_vm_start(vm);
451 }
452 void MSG_vm_suspend(sg_vm_t vm)
453 {
454   sg_vm_suspend(vm);
455 }
456 void MSG_vm_resume(sg_vm_t vm)
457 {
458   sg_vm_resume(vm);
459 }
460 void MSG_vm_shutdown(sg_vm_t vm)
461 {
462   sg_vm_shutdown(vm);
463 }
464 void MSG_vm_destroy(sg_vm_t vm)
465 {
466   sg_vm_destroy(vm);
467 }
468 /********* barriers ************/
469 sg_bar_t MSG_barrier_init(unsigned int count)
470 {
471   return sg_barrier_init(count);
472 }
473
474 void MSG_barrier_destroy(const_sg_bar_t bar)
475 {
476   sg_barrier_destroy(bar);
477 }
478
479 int MSG_barrier_wait(sg_bar_t bar)
480 {
481   return sg_barrier_wait(bar);
482 }
483
484 sg_sem_t MSG_sem_init(int initial_value)
485 {
486   return sg_sem_init(initial_value);
487 }
488 void MSG_sem_acquire(sg_sem_t sem)
489 {
490   sg_sem_acquire(sem);
491 }
492 int MSG_sem_acquire_timeout(sg_sem_t sem, double timeout)
493 {
494   return sg_sem_acquire_timeout(sem, timeout);
495 }
496 void MSG_sem_release(sg_sem_t sem)
497 {
498   sg_sem_release(sem);
499 }
500 int MSG_sem_get_capacity(sg_sem_t sem)
501 {
502   return sg_sem_get_capacity(sem);
503 }
504 void MSG_sem_destroy(const_sg_sem_t sem)
505 {
506   sg_sem_destroy(sem);
507 }
508 int MSG_sem_would_block(sg_sem_t sem)
509 {
510   return sg_sem_would_block(sem);
511 }