Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add sg_actor_execute_with_priority
[simgrid.git] / src / s4u / s4u_Actor.cpp
1 /* Copyright (c) 2006-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/actor.h"
8 #include "simgrid/modelchecker.h"
9 #include "simgrid/s4u/Actor.hpp"
10 #include "simgrid/s4u/Exec.hpp"
11 #include "simgrid/s4u/Host.hpp"
12 #include "simgrid/s4u/VirtualMachine.hpp"
13 #include "src/include/mc/mc.h"
14 #include "src/kernel/EngineImpl.hpp"
15 #include "src/kernel/activity/ExecImpl.hpp"
16 #include "src/mc/mc_replay.hpp"
17 #include "src/surf/HostImpl.hpp"
18
19 #include <algorithm>
20 #include <sstream>
21
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_actor, s4u, "S4U actors");
23
24 namespace simgrid {
25
26 template class xbt::Extendable<s4u::Actor>;
27
28 namespace s4u {
29
30 xbt::signal<void(Actor&)> s4u::Actor::on_creation;
31 xbt::signal<void(Actor const&)> s4u::Actor::on_suspend;
32 xbt::signal<void(Actor const&)> s4u::Actor::on_resume;
33 xbt::signal<void(Actor const&)> s4u::Actor::on_sleep;
34 xbt::signal<void(Actor const&)> s4u::Actor::on_wake_up;
35 xbt::signal<void(Actor const&)> s4u::Actor::on_migration_start; // deprecated
36 xbt::signal<void(Actor const&)> s4u::Actor::on_migration_end;   // deprecated
37 xbt::signal<void(Actor const&, Host const& previous_location)> s4u::Actor::on_host_change;
38 xbt::signal<void(Actor const&)> s4u::Actor::on_termination;
39 xbt::signal<void(Actor const&)> s4u::Actor::on_destruction;
40
41 // ***** Actor creation *****
42 Actor* Actor::self()
43 {
44   kernel::context::Context* self_context = kernel::context::Context::self();
45   if (self_context == nullptr)
46     return nullptr;
47
48   return self_context->get_actor()->ciface();
49 }
50
51 ActorPtr Actor::init(const std::string& name, s4u::Host* host)
52 {
53   kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
54   kernel::actor::ActorImpl* actor =
55       kernel::actor::simcall([self, &name, host] { return self->init(name, host).get(); });
56   return actor->iface();
57 }
58
59 ActorPtr Actor::start(const std::function<void()>& code)
60 {
61   simgrid::kernel::actor::simcall([this, &code] { pimpl_->start(code); });
62   return this;
63 }
64
65 ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::function<void()>& code)
66 {
67   kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
68   kernel::actor::ActorImpl* actor =
69       kernel::actor::simcall([self, &name, host, &code] { return self->init(name, host)->start(code); });
70
71   return actor->iface();
72 }
73
74 ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::string& function,
75                        std::vector<std::string> args)
76 {
77   const simgrid::kernel::actor::ActorCodeFactory& factory =
78       simgrid::kernel::EngineImpl::get_instance()->get_function(function);
79   return create(name, host, factory(std::move(args)));
80 }
81
82 void intrusive_ptr_add_ref(const Actor* actor)
83 {
84   intrusive_ptr_add_ref(actor->pimpl_);
85 }
86 void intrusive_ptr_release(const Actor* actor)
87 {
88   intrusive_ptr_release(actor->pimpl_);
89 }
90 int Actor::get_refcount()
91 {
92   return pimpl_->get_refcount();
93 }
94
95 // ***** Actor methods *****
96
97 void Actor::join()
98 {
99   join(-1);
100 }
101
102 void Actor::join(double timeout)
103 {
104   kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
105   kernel::actor::ActorImpl* target = pimpl_;
106   kernel::actor::simcall_blocking<void>([issuer, target, timeout] {
107     if (target->finished_) {
108       // The joined process is already finished, just wake up the issuer right away
109       issuer->simcall_answer();
110     } else {
111       kernel::activity::ActivityImplPtr sync = issuer->join(target, timeout);
112       sync->register_simcall(&issuer->simcall);
113     }
114   });
115 }
116
117 void Actor::set_auto_restart(bool autorestart)
118 {
119   kernel::actor::simcall([this, autorestart]() {
120     xbt_assert(autorestart && not pimpl_->has_to_auto_restart()); // FIXME: handle all cases
121     pimpl_->set_auto_restart(autorestart);
122
123     kernel::actor::ProcessArg* arg = new kernel::actor::ProcessArg(pimpl_->get_host(), pimpl_);
124     XBT_DEBUG("Adding %s to the actors_at_boot_ list of Host %s", arg->name.c_str(), arg->host->get_cname());
125     pimpl_->get_host()->pimpl_->add_actor_at_boot(arg);
126   });
127 }
128
129 void Actor::on_exit(const std::function<void(bool /*failed*/)>& fun) const
130 {
131   kernel::actor::simcall([this, &fun] { pimpl_->on_exit->emplace_back(fun); });
132 }
133
134 void Actor::set_host(Host* new_host)
135 {
136   if (s4u::Actor::on_migration_start.get_slot_count() > 0) { // XBT_ATTRIB_DEPRECATED_v329
137     static bool already_warned = false;
138     if (not already_warned) {
139       XBT_INFO("Please use s4u::Actor::on_host_change instead of s4u::Actor::on_migration_start. This will be removed "
140                "in v3.29");
141       already_warned = true;
142     }
143     s4u::Actor::on_migration_start(*this);
144   }
145
146   const s4u::Host* previous_location = get_host();
147
148   kernel::actor::simcall([this, new_host]() {
149     if (pimpl_->waiting_synchro != nullptr) {
150       // The actor is blocked on an activity. If it's an exec, migrate it too.
151       // FIXME: implement the migration of other kinds of activities
152       kernel::activity::ExecImplPtr exec =
153           boost::dynamic_pointer_cast<kernel::activity::ExecImpl>(pimpl_->waiting_synchro);
154       xbt_assert(exec.get() != nullptr, "We can only migrate blocked actors when they are blocked on executions.");
155       exec->migrate(new_host);
156     }
157     this->pimpl_->set_host(new_host);
158   });
159
160   if (s4u::Actor::on_migration_end.get_slot_count() > 0) { // XBT_ATTRIB_DEPRECATED_v329
161     static bool already_warned = false;
162     if (not already_warned) {
163       XBT_INFO("Please use s4u::Actor::on_host_change instead of s4u::Actor::on_migration_end. This will be removed in "
164                "v3.29");
165       already_warned = true;
166     }
167     s4u::Actor::on_migration_end(*this);
168   }
169
170   s4u::Actor::on_host_change(*this, *previous_location);
171 }
172
173 s4u::Host* Actor::get_host() const
174 {
175   return this->pimpl_->get_host();
176 }
177
178 void Actor::daemonize()
179 {
180   kernel::actor::simcall([this]() { pimpl_->daemonize(); });
181 }
182
183 bool Actor::is_daemon() const
184 {
185   return this->pimpl_->is_daemon();
186 }
187
188 const simgrid::xbt::string& Actor::get_name() const
189 {
190   return this->pimpl_->get_name();
191 }
192
193 const char* Actor::get_cname() const
194 {
195   return this->pimpl_->get_cname();
196 }
197
198 aid_t Actor::get_pid() const
199 {
200   return this->pimpl_->get_pid();
201 }
202
203 aid_t Actor::get_ppid() const
204 {
205   return this->pimpl_->get_ppid();
206 }
207
208 void Actor::suspend()
209 {
210   kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
211   kernel::actor::ActorImpl* target = pimpl_;
212   s4u::Actor::on_suspend(*this);
213   kernel::actor::simcall_blocking<void>([issuer, target]() {
214     target->suspend();
215     if (target != issuer) {
216       /* If we are suspending ourselves, then just do not finish the simcall now */
217       issuer->simcall_answer();
218     }
219   });
220 }
221
222 void Actor::resume()
223 {
224   kernel::actor::simcall([this] { pimpl_->resume(); });
225   s4u::Actor::on_resume(*this);
226 }
227
228 bool Actor::is_suspended()
229 {
230   return pimpl_->is_suspended();
231 }
232
233 void Actor::set_kill_time(double kill_time)
234 {
235   kernel::actor::simcall([this, kill_time] { pimpl_->set_kill_time(kill_time); });
236 }
237
238 /** @brief Get the kill time of an actor(or 0 if unset). */
239 double Actor::get_kill_time()
240 {
241   return pimpl_->get_kill_time();
242 }
243
244 void Actor::kill()
245 {
246   kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
247   kernel::actor::simcall([this, self] { self->kill(pimpl_); });
248 }
249
250 // ***** Static functions *****
251
252 ActorPtr Actor::by_pid(aid_t pid)
253 {
254   kernel::actor::ActorImpl* actor = SIMIX_process_from_PID(pid);
255   if (actor != nullptr)
256     return actor->iface();
257   else
258     return ActorPtr();
259 }
260
261 void Actor::kill_all()
262 {
263   kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
264   kernel::actor::simcall([self] { self->kill_all(); });
265 }
266
267 const std::unordered_map<std::string, std::string>* Actor::get_properties() const
268 {
269   return pimpl_->get_properties();
270 }
271
272 /** Retrieve the property value (or nullptr if not set) */
273 const char* Actor::get_property(const std::string& key) const
274 {
275   return pimpl_->get_property(key);
276 }
277
278 void Actor::set_property(const std::string& key, const std::string& value)
279 {
280   kernel::actor::simcall([this, &key, &value] { pimpl_->set_property(key, value); });
281 }
282
283 Actor* Actor::restart()
284 {
285   return kernel::actor::simcall([this]() { return pimpl_->restart(); });
286 }
287
288 // ***** this_actor *****
289
290 namespace this_actor {
291
292 /** Returns true if run from the kernel mode, and false if run from a real actor
293  *
294  * Everything that is run out of any actor (simulation setup before the engine is run,
295  * computing the model evolutions as a result to the actors' action, etc) is run in
296  * kernel mode, just as in any operating systems.
297  *
298  * In SimGrid, the actor in charge of doing the stuff in kernel mode is called Maestro,
299  * because it is the one scheduling when the others should move or wait.
300  */
301 bool is_maestro()
302 {
303   return SIMIX_is_maestro();
304 }
305
306 void sleep_for(double duration)
307 {
308   xbt_assert(std::isfinite(duration), "duration is not finite!");
309
310   if (duration > 0) {
311     kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
312     Actor::on_sleep(*issuer->ciface());
313
314     kernel::actor::simcall_blocking<void>([issuer, duration]() {
315       if (MC_is_active() || MC_record_replay_is_active()) {
316         MC_process_clock_add(issuer, duration);
317         issuer->simcall_answer();
318         return;
319       }
320       kernel::activity::ActivityImplPtr sync = issuer->sleep(duration);
321       sync->register_simcall(&issuer->simcall);
322     });
323
324     Actor::on_wake_up(*issuer->ciface());
325   }
326 }
327
328 void yield()
329 {
330   kernel::actor::simcall([] { /* do nothing*/ });
331 }
332
333 XBT_PUBLIC void sleep_until(double wakeup_time)
334 {
335   double now = SIMIX_get_clock();
336   if (wakeup_time > now)
337     sleep_for(wakeup_time - now);
338 }
339
340 void execute(double flops)
341 {
342   execute(flops, 1.0 /* priority */);
343 }
344
345 void execute(double flops, double priority)
346 {
347   exec_init(flops)->set_priority(priority)->start()->wait();
348 }
349
350 void parallel_execute(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
351                       const std::vector<double>& bytes_amounts)
352 {
353   exec_init(hosts, flops_amounts, bytes_amounts)->wait();
354 }
355
356 void parallel_execute(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
357                       const std::vector<double>& bytes_amounts, double timeout) // XBT_ATTRIB_DEPRECATED_v329
358 {
359   exec_init(hosts, flops_amounts, bytes_amounts)->wait_for(timeout);
360 }
361
362 ExecPtr exec_init(double flops_amount)
363 {
364   ExecPtr exec = ExecPtr(new Exec());
365   exec->set_flops_amount(flops_amount)->set_host(get_host());
366   return exec;
367 }
368
369 ExecPtr exec_init(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
370                   const std::vector<double>& bytes_amounts)
371 {
372   xbt_assert(hosts.size() > 0, "Your parallel executions must span over at least one host.");
373   xbt_assert(hosts.size() == flops_amounts.size() || flops_amounts.empty(),
374              "Host count (%zu) does not match flops_amount count (%zu).", hosts.size(), flops_amounts.size());
375   xbt_assert(hosts.size() * hosts.size() == bytes_amounts.size() || bytes_amounts.empty(),
376              "bytes_amounts must be a matrix of size host_count * host_count (%zu*%zu), but it's of size %zu.",
377              hosts.size(), hosts.size(), flops_amounts.size());
378   /* Check that we are not mixing VMs and PMs in the parallel task */
379   bool is_a_vm = (nullptr != dynamic_cast<VirtualMachine*>(hosts.front()));
380   xbt_assert(std::all_of(hosts.begin(), hosts.end(),
381                          [is_a_vm](s4u::Host* elm) {
382                            bool tmp_is_a_vm = (nullptr != dynamic_cast<VirtualMachine*>(elm));
383                            return is_a_vm == tmp_is_a_vm;
384                          }),
385              "parallel_execute: mixing VMs and PMs is not supported (yet).");
386   /* checking for infinite values */
387   xbt_assert(std::all_of(flops_amounts.begin(), flops_amounts.end(), [](double elm) { return std::isfinite(elm); }),
388              "flops_amounts comprises infinite values!");
389   xbt_assert(std::all_of(bytes_amounts.begin(), bytes_amounts.end(), [](double elm) { return std::isfinite(elm); }),
390              "flops_amounts comprises infinite values!");
391
392   ExecPtr exec = ExecPtr(new Exec());
393   exec->set_flops_amounts(flops_amounts)->set_bytes_amounts(bytes_amounts)->set_hosts(hosts);
394   return exec;
395 }
396
397 ExecPtr exec_async(double flops)
398 {
399   ExecPtr res = exec_init(flops);
400   res->start();
401   return res;
402 }
403
404 aid_t get_pid()
405 {
406   return simgrid::kernel::actor::ActorImpl::self()->get_pid();
407 }
408
409 aid_t get_ppid()
410 {
411   return simgrid::kernel::actor::ActorImpl::self()->get_ppid();
412 }
413
414 std::string get_name()
415 {
416   return simgrid::kernel::actor::ActorImpl::self()->get_name();
417 }
418
419 const char* get_cname()
420 {
421   return simgrid::kernel::actor::ActorImpl::self()->get_cname();
422 }
423
424 Host* get_host()
425 {
426   return simgrid::kernel::actor::ActorImpl::self()->get_host();
427 }
428
429 void suspend()
430 {
431   kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self();
432   s4u::Actor::on_suspend(*self->ciface());
433   kernel::actor::simcall_blocking<void>([self] { self->suspend(); });
434 }
435
436 void exit()
437 {
438   kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self();
439   simgrid::kernel::actor::simcall([self] { self->exit(); });
440 }
441
442 void on_exit(const std::function<void(bool)>& fun)
443 {
444   simgrid::kernel::actor::ActorImpl::self()->iface()->on_exit(fun);
445 }
446
447 /** @brief Moves the current actor to another host
448  *
449  * @see simgrid::s4u::Actor::migrate() for more information
450  */
451 void set_host(Host* new_host)
452 {
453   simgrid::kernel::actor::ActorImpl::self()->iface()->set_host(new_host);
454 }
455 void migrate(Host* new_host) // deprecated
456 {
457   set_host(new_host);
458 }
459
460 } // namespace this_actor
461 } // namespace s4u
462 } // namespace simgrid
463
464 /* **************************** Public C interface *************************** */
465
466 sg_actor_t sg_actor_init(const char* name, sg_host_t host)
467 {
468   return simgrid::s4u::Actor::init(name, host).get();
469 }
470
471 void sg_actor_start(sg_actor_t actor, xbt_main_func_t code, int argc, const char* const* argv)
472 {
473   simgrid::kernel::actor::ActorCode function;
474   if (code)
475     function = simgrid::xbt::wrap_main(code, argc, argv);
476   actor->start(std::move(function));
477 }
478
479 sg_actor_t sg_actor_create(const char* name, sg_host_t host, xbt_main_func_t code, int argc, const char* const* argv)
480 {
481   simgrid::kernel::actor::ActorCode function = simgrid::xbt::wrap_main(code, argc, argv);
482   return simgrid::s4u::Actor::init(name, host)->start(std::move(function)).get();
483 }
484
485 void sg_actor_exit()
486 {
487   simgrid::s4u::this_actor::exit();
488 }
489
490 /**
491  * @brief Returns the process ID of @a actor.
492  *
493  * This function checks whether @a actor is a valid pointer and return its PID (or 0 in case of problem).
494  */
495
496 aid_t sg_actor_get_PID(const_sg_actor_t actor)
497 {
498   /* Do not raise an exception here: this function is called by the logs
499    * and the exceptions, so it would be called back again and again */
500   if (actor == nullptr || actor->get_impl() == nullptr)
501     return 0;
502   return actor->get_pid();
503 }
504
505 /**
506  * @brief Returns the process ID of the parent of @a actor.
507  *
508  * This function checks whether @a actor is a valid pointer and return its parent's PID.
509  * Returns -1 if the actor has not been created by any other actor.
510  */
511 aid_t sg_actor_get_PPID(const_sg_actor_t actor)
512 {
513   return actor->get_ppid();
514 }
515
516 /**
517  * @brief Return a #sg_actor_t given its PID.
518  *
519  * This function search in the list of all the created sg_actor_t for a sg_actor_t  whose PID is equal to @a PID.
520  * If none is found, @c nullptr is returned.
521    Note that the PID are unique in the whole simulation, not only on a given host.
522  */
523 sg_actor_t sg_actor_by_PID(aid_t pid)
524 {
525   return simgrid::s4u::Actor::by_pid(pid).get();
526 }
527
528 /** @brief Return the name of an actor. */
529 const char* sg_actor_get_name(const_sg_actor_t actor)
530 {
531   return actor->get_cname();
532 }
533
534 sg_host_t sg_actor_get_host(const_sg_actor_t actor)
535 {
536   return actor->get_host();
537 }
538
539 /**
540  * @brief Returns the value of a given actor property
541  *
542  * @param actor an actor
543  * @param name a property name
544  * @return value of a property (or nullptr if the property is not set)
545  */
546 const char* sg_actor_get_property_value(const_sg_actor_t actor, const char* name)
547 {
548   return actor->get_property(name);
549 }
550
551 /**
552  * @brief Return the list of properties
553  *
554  * This function returns all the parameters associated with an actor
555  */
556 xbt_dict_t sg_actor_get_properties(const_sg_actor_t actor)
557 {
558   xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
559   xbt_dict_t as_dict                        = xbt_dict_new_homogeneous(xbt_free_f);
560   const std::unordered_map<std::string, std::string>* props = actor->get_properties();
561   if (props == nullptr)
562     return nullptr;
563   for (auto const& kv : *props) {
564     xbt_dict_set(as_dict, kv.first.c_str(), xbt_strdup(kv.second.c_str()));
565   }
566   return as_dict;
567 }
568
569 /**
570  * @brief Suspend the actor.
571  *
572  * This function suspends the actor by suspending the task on which it was waiting for the completion.
573  */
574 void sg_actor_suspend(sg_actor_t actor)
575 {
576   xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
577   actor->suspend();
578 }
579
580 /**
581  * @brief Resume a suspended actor.
582  *
583  * This function resumes a suspended actor by resuming the task on which it was waiting for the completion.
584  */
585 void sg_actor_resume(sg_actor_t actor)
586 {
587   xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
588   actor->resume();
589 }
590
591 /**
592  * @brief Returns true if the actor is suspended .
593  *
594  * This checks whether an actor is suspended or not by inspecting the task on which it was waiting for the completion.
595  */
596 int sg_actor_is_suspended(sg_actor_t actor)
597 {
598   return actor->is_suspended();
599 }
600
601 /** @brief Restarts an actor from the beginning. */
602 sg_actor_t sg_actor_restart(sg_actor_t actor)
603 {
604   return actor->restart();
605 }
606
607 /**
608  * @brief Sets the "auto-restart" flag of the actor.
609  * If the flag is set to 1, the actor will be automatically restarted when its host comes back up.
610  */
611 void sg_actor_set_auto_restart(sg_actor_t actor, int auto_restart)
612 {
613   actor->set_auto_restart(auto_restart);
614 }
615
616 /** @brief This actor will be terminated automatically when the last non-daemon actor finishes */
617 void sg_actor_daemonize(sg_actor_t actor)
618 {
619   actor->daemonize();
620 }
621
622 /** Returns whether or not this actor has been daemonized or not */
623 int sg_actor_is_daemon(const_sg_actor_t actor)
624 {
625   return actor->is_daemon();
626 }
627
628 /**
629  * @brief Migrates an actor to another location.
630  *
631  * This function changes the value of the #sg_host_t on  which @a actor is running.
632  */
633 void sg_actor_set_host(sg_actor_t actor, sg_host_t host)
634 {
635   actor->set_host(host);
636 }
637 void sg_actor_migrate(sg_actor_t process, sg_host_t host) // deprecated
638 {
639   process->set_host(host);
640 }
641
642 /**
643  * @brief Wait for the completion of a #sg_actor_t.
644  *
645  * @param actor the actor to wait for
646  * @param timeout wait until the actor is over, or the timeout expires
647  */
648 void sg_actor_join(sg_actor_t actor, double timeout)
649 {
650   actor->join(timeout);
651 }
652
653 void sg_actor_kill(sg_actor_t actor)
654 {
655   actor->kill();
656 }
657
658 void sg_actor_kill_all()
659 {
660   simgrid::s4u::Actor::kill_all();
661 }
662
663 /**
664  * @brief Set the kill time of an actor.
665  *
666  * @param actor an actor
667  * @param kill_time the time when the actor is killed.
668  */
669 void sg_actor_set_kill_time(sg_actor_t actor, double kill_time)
670 {
671   actor->set_kill_time(kill_time);
672 }
673
674 /** Yield the current actor; let the other actors execute first */
675 void sg_actor_yield()
676 {
677   simgrid::s4u::this_actor::yield();
678 }
679
680 void sg_actor_sleep_for(double duration)
681 {
682   simgrid::s4u::this_actor::sleep_for(duration);
683 }
684
685 void sg_actor_sleep_until(double wakeup_time)
686 {
687   simgrid::s4u::this_actor::sleep_until(wakeup_time);
688 }
689
690 sg_actor_t sg_actor_attach(const char* name, void* data, sg_host_t host, xbt_dict_t properties)
691 {
692   xbt_assert(host != nullptr, "Invalid parameters: host and code params must not be nullptr");
693   std::unordered_map<std::string, std::string> props;
694   xbt_dict_cursor_t cursor = nullptr;
695   char* key;
696   char* value;
697   xbt_dict_foreach (properties, cursor, key, value)
698     props[key] = value;
699   xbt_dict_free(&properties);
700
701   /* Let's create the process: SIMIX may decide to start it right now, even before returning the flow control to us */
702   smx_actor_t actor = nullptr;
703   try {
704     actor = simgrid::kernel::actor::ActorImpl::attach(name, data, host, &props).get();
705   } catch (simgrid::HostFailureException const&) {
706     xbt_die("Could not attach");
707   }
708
709   simgrid::s4u::this_actor::yield();
710   return actor->ciface();
711 }
712
713 void sg_actor_detach()
714 {
715   simgrid::kernel::actor::ActorImpl::detach();
716 }
717
718 aid_t sg_actor_self_get_pid()
719 {
720   return simgrid::s4u::this_actor::get_pid();
721 }
722
723 aid_t sg_actor_self_get_ppid()
724 {
725   return simgrid::s4u::this_actor::get_ppid();
726 }
727
728 const char* sg_actor_self_get_name()
729 {
730   return simgrid::s4u::this_actor::get_cname();
731 }
732
733 void* sg_actor_self_data()
734 {
735   return simgrid::s4u::Actor::self()->get_data();
736 }
737
738 void sg_actor_self_data_set(void* userdata)
739 {
740   simgrid::s4u::Actor::self()->set_data(userdata);
741 }
742
743 sg_actor_t sg_actor_self()
744 {
745   return simgrid::s4u::Actor::self();
746 }
747
748 void sg_actor_self_execute(double flops) // XBT_DEPRECATED_v330
749 {
750   simgrid::s4u::this_actor::execute(flops);
751 }
752
753 void sg_actor_execute(double flops)
754 {
755   simgrid::s4u::this_actor::execute(flops);
756 }
757 void sg_actor_execute_with_priority(double flops, double priority)
758 {
759   simgrid::s4u::this_actor::exec_init(flops)->set_priority(priority)->wait();
760 }
761
762 void sg_actor_parallel_execute(int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount)
763 {
764   std::vector<simgrid::s4u::Host*> hosts(host_list, host_list + host_nb);
765   std::vector<double> flops;
766   std::vector<double> bytes;
767   if (flops_amount != nullptr)
768     flops = std::vector<double>(flops_amount, flops_amount + host_nb);
769   if (bytes_amount != nullptr)
770     bytes = std::vector<double>(bytes_amount, bytes_amount + host_nb * host_nb);
771
772   simgrid::s4u::this_actor::parallel_execute(hosts, flops, bytes);
773 }
774
775 /** @brief Take an extra reference on that actor to prevent it to be garbage-collected */
776 void sg_actor_ref(const_sg_actor_t actor)
777 {
778   intrusive_ptr_add_ref(actor);
779 }
780 /** @brief Release a reference on that actor so that it can get be garbage-collected */
781 void sg_actor_unref(const_sg_actor_t actor)
782 {
783   intrusive_ptr_release(actor);
784 }
785
786 /** @brief Return the user data of a #sg_actor_t */
787 void* sg_actor_data(const_sg_actor_t actor)
788 {
789   return actor->get_data();
790 }
791 /** @brief Set the user data of a #sg_actor_t */
792 void sg_actor_data_set(sg_actor_t actor, void* userdata)
793 {
794   actor->set_data(userdata);
795 }
796 /** @brief Add a function to the list of "on_exit" functions for the current process.
797  *  The on_exit functions are the functions executed when your process is killed.
798  *  You should use them to free the data used by your process.
799  */
800 void sg_actor_on_exit(int_f_int_pvoid_t fun, void* data)
801 {
802   simgrid::s4u::this_actor::on_exit([fun, data](bool failed) { fun(failed ? 1 /*FAILURE*/ : 0 /*SUCCESS*/, data); });
803 }
804
805 sg_exec_t sg_actor_exec_init(double computation_amount)
806 {
807   simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(computation_amount);
808   exec->add_ref();
809   return exec.get();
810 }
811
812 sg_exec_t sg_actor_parallel_exec_init(int host_nb, const sg_host_t* host_list, double* flops_amount,
813                                       double* bytes_amount)
814 {
815   std::vector<simgrid::s4u::Host*> hosts(host_list, host_list + host_nb);
816   std::vector<double> flops;
817   std::vector<double> bytes;
818   if (flops_amount != nullptr)
819     flops = std::vector<double>(flops_amount, flops_amount + host_nb);
820   if (bytes_amount != nullptr)
821     bytes = std::vector<double>(bytes_amount, bytes_amount + host_nb * host_nb);
822
823   simgrid::s4u::ExecPtr exec = simgrid::s4u::ExecPtr(new simgrid::s4u::Exec());
824   exec->set_flops_amounts(flops)->set_bytes_amounts(bytes)->set_hosts(hosts);
825   exec->add_ref();
826   return exec.get();
827 }
828
829 sg_exec_t sg_actor_exec_async(double computation_amount)
830 {
831   simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_async(computation_amount);
832   exec->add_ref();
833   return exec.get();
834 }