1 /* Copyright (c) 2006-2021. 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/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"
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_actor, s4u, "S4U actors");
26 template class xbt::Extendable<s4u::Actor>;
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;
36 xbt::signal<void(Actor const&)> s4u::Actor::on_migration_start; // XBT_ATTRIB_DEPRECATED_v329
37 xbt::signal<void(Actor const&)> s4u::Actor::on_migration_end; // XBT_ATTRIB_DEPRECATED_v329
39 xbt::signal<void(Actor const&, Host const& previous_location)> s4u::Actor::on_host_change;
40 xbt::signal<void(Actor const&)> s4u::Actor::on_termination;
41 xbt::signal<void(Actor const&)> s4u::Actor::on_destruction;
43 // ***** Actor creation *****
46 const kernel::context::Context* self_context = kernel::context::Context::self();
47 if (self_context == nullptr)
50 return self_context->get_actor()->get_ciface();
53 ActorPtr Actor::init(const std::string& name, s4u::Host* host)
55 const kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
56 kernel::actor::ActorImpl* actor =
57 kernel::actor::simcall([self, &name, host] { return self->init(name, host).get(); });
58 return actor->get_iface();
61 /** Set a non-default stack size for this context (in Kb)
63 * This must be done before starting the actor, and it won't work with the thread factory. */
64 ActorPtr Actor::set_stacksize(unsigned stacksize)
66 pimpl_->set_stacksize(stacksize * 1024);
70 ActorPtr Actor::start(const std::function<void()>& code)
72 simgrid::kernel::actor::simcall([this, &code] { pimpl_->start(code); });
76 ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::function<void()>& code)
78 const kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
79 kernel::actor::ActorImpl* actor =
80 kernel::actor::simcall([self, &name, host, &code] { return self->init(name, host)->start(code); });
82 return actor->get_iface();
85 ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::string& function,
86 std::vector<std::string> args)
88 const simgrid::kernel::actor::ActorCodeFactory& factory =
89 simgrid::kernel::EngineImpl::get_instance()->get_function(function);
90 return create(name, host, factory(std::move(args)));
93 void intrusive_ptr_add_ref(const Actor* actor)
95 intrusive_ptr_add_ref(actor->pimpl_);
97 void intrusive_ptr_release(const Actor* actor)
99 intrusive_ptr_release(actor->pimpl_);
101 int Actor::get_refcount() const
103 return pimpl_->get_refcount();
106 // ***** Actor methods *****
108 void Actor::join() const
113 void Actor::join(double timeout) const
115 kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
116 const kernel::actor::ActorImpl* target = pimpl_;
117 kernel::actor::simcall_blocking([issuer, target, timeout] {
118 if (target->finished_) {
119 // The joined process is already finished, just wake up the issuer right away
120 issuer->simcall_answer();
122 kernel::activity::ActivityImplPtr sync = issuer->join(target, timeout);
123 sync->register_simcall(&issuer->simcall_);
128 void Actor::set_auto_restart(bool autorestart)
130 kernel::actor::simcall([this, autorestart]() {
131 xbt_assert(autorestart && not pimpl_->has_to_auto_restart()); // FIXME: handle all cases
132 pimpl_->set_auto_restart(autorestart);
134 auto* arg = new kernel::actor::ProcessArg(pimpl_->get_host(), pimpl_);
135 XBT_DEBUG("Adding %s to the actors_at_boot_ list of Host %s", arg->name.c_str(), arg->host->get_cname());
136 pimpl_->get_host()->get_impl()->add_actor_at_boot(arg);
140 void Actor::on_exit(const std::function<void(bool /*failed*/)>& fun) const
142 kernel::actor::simcall([this, &fun] { pimpl_->on_exit->emplace_back(fun); });
145 void Actor::set_host(Host* new_host)
147 if (s4u::Actor::on_migration_start.get_slot_count() > 0) { // XBT_ATTRIB_DEPRECATED_v329
148 static bool already_warned = false;
149 if (not already_warned) {
150 XBT_INFO("Please use s4u::Actor::on_host_change instead of s4u::Actor::on_migration_start. This will be removed "
152 already_warned = true;
154 s4u::Actor::on_migration_start(*this);
157 const s4u::Host* previous_location = get_host();
159 kernel::actor::simcall([this, new_host]() {
160 for (auto const& activity : pimpl_->activities_) {
161 // FIXME: implement the migration of other kinds of activities
162 if (auto exec = boost::dynamic_pointer_cast<kernel::activity::ExecImpl>(activity))
163 exec->migrate(new_host);
165 this->pimpl_->set_host(new_host);
168 if (s4u::Actor::on_migration_end.get_slot_count() > 0) { // XBT_ATTRIB_DEPRECATED_v329
169 static bool already_warned = false;
170 if (not already_warned) {
171 XBT_INFO("Please use s4u::Actor::on_host_change instead of s4u::Actor::on_migration_end. This will be removed in "
173 already_warned = true;
175 s4u::Actor::on_migration_end(*this);
178 s4u::Actor::on_host_change(*this, *previous_location);
181 s4u::Host* Actor::get_host() const
183 return this->pimpl_->get_host();
186 void Actor::daemonize()
188 kernel::actor::simcall([this]() { pimpl_->daemonize(); });
191 bool Actor::is_daemon() const
193 return this->pimpl_->is_daemon();
196 const simgrid::xbt::string& Actor::get_name() const
198 return this->pimpl_->get_name();
201 const char* Actor::get_cname() const
203 return this->pimpl_->get_cname();
206 aid_t Actor::get_pid() const
208 return this->pimpl_->get_pid();
211 aid_t Actor::get_ppid() const
213 return this->pimpl_->get_ppid();
216 void Actor::suspend()
218 kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
219 kernel::actor::ActorImpl* target = pimpl_;
220 s4u::Actor::on_suspend(*this);
221 kernel::actor::simcall_blocking([issuer, target]() {
223 if (target != issuer) {
224 /* If we are suspending ourselves, then just do not finish the simcall now */
225 issuer->simcall_answer();
232 kernel::actor::simcall([this] { pimpl_->resume(); });
233 s4u::Actor::on_resume(*this);
236 bool Actor::is_suspended() const
238 return pimpl_->is_suspended();
241 void Actor::set_kill_time(double kill_time)
243 kernel::actor::simcall([this, kill_time] { pimpl_->set_kill_time(kill_time); });
246 /** @brief Get the kill time of an actor(or 0 if unset). */
247 double Actor::get_kill_time() const
249 return pimpl_->get_kill_time();
254 const kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
255 kernel::actor::simcall([this, self] { self->kill(pimpl_); });
258 // ***** Static functions *****
260 ActorPtr Actor::by_pid(aid_t pid)
262 kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_pid(pid);
263 if (actor != nullptr)
264 return actor->get_iface();
269 void Actor::kill_all()
271 const kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
272 kernel::actor::simcall([self] { self->kill_all(); });
275 const std::unordered_map<std::string, std::string>* Actor::get_properties() const
277 return pimpl_->get_properties();
280 /** Retrieve the property value (or nullptr if not set) */
281 const char* Actor::get_property(const std::string& key) const
283 return pimpl_->get_property(key);
286 void Actor::set_property(const std::string& key, const std::string& value)
288 kernel::actor::simcall([this, &key, &value] { pimpl_->set_property(key, value); });
291 Actor* Actor::restart()
293 return kernel::actor::simcall([this]() { return pimpl_->restart(); });
296 // ***** this_actor *****
298 namespace this_actor {
300 /** Returns true if run from the kernel mode, and false if run from a real actor
302 * Everything that is run out of any actor (simulation setup before the engine is run,
303 * computing the model evolutions as a result to the actors' action, etc) is run in
304 * kernel mode, just as in any operating systems.
306 * In SimGrid, the actor in charge of doing the stuff in kernel mode is called Maestro,
307 * because it is the one scheduling when the others should move or wait.
311 return SIMIX_is_maestro();
314 void sleep_for(double duration)
316 xbt_assert(std::isfinite(duration), "duration is not finite!");
319 kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
320 Actor::on_sleep(*issuer->get_ciface());
322 kernel::actor::simcall_blocking([issuer, duration]() {
323 if (MC_is_active() || MC_record_replay_is_active()) {
324 MC_process_clock_add(issuer, duration);
325 issuer->simcall_answer();
328 kernel::activity::ActivityImplPtr sync = issuer->sleep(duration);
329 sync->register_simcall(&issuer->simcall_);
332 Actor::on_wake_up(*issuer->get_ciface());
338 kernel::actor::simcall([] { /* do nothing*/ });
341 XBT_PUBLIC void sleep_until(double wakeup_time)
343 double now = SIMIX_get_clock();
344 if (wakeup_time > now)
345 sleep_for(wakeup_time - now);
348 void execute(double flops)
350 execute(flops, 1.0 /* priority */);
353 void execute(double flops, double priority)
355 exec_init(flops)->set_priority(priority)->vetoable_start()->wait();
358 void parallel_execute(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
359 const std::vector<double>& bytes_amounts)
361 exec_init(hosts, flops_amounts, bytes_amounts)->wait();
364 void parallel_execute(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
365 const std::vector<double>& bytes_amounts, double timeout) // XBT_ATTRIB_DEPRECATED_v329
367 exec_init(hosts, flops_amounts, bytes_amounts)->wait_for(timeout);
370 ExecPtr exec_init(double flops_amount)
372 return Exec::init()->set_flops_amount(flops_amount)->set_host(get_host());
375 ExecPtr exec_init(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
376 const std::vector<double>& bytes_amounts)
378 xbt_assert(hosts.size() > 0, "Your parallel executions must span over at least one host.");
379 xbt_assert(hosts.size() == flops_amounts.size() || flops_amounts.empty(),
380 "Host count (%zu) does not match flops_amount count (%zu).", hosts.size(), flops_amounts.size());
381 xbt_assert(hosts.size() * hosts.size() == bytes_amounts.size() || bytes_amounts.empty(),
382 "bytes_amounts must be a matrix of size host_count * host_count (%zu*%zu), but it's of size %zu.",
383 hosts.size(), hosts.size(), bytes_amounts.size());
384 /* Check that we are not mixing VMs and PMs in the parallel task */
385 bool is_a_vm = (nullptr != dynamic_cast<VirtualMachine*>(hosts.front()));
386 xbt_assert(std::all_of(hosts.begin(), hosts.end(),
387 [is_a_vm](s4u::Host* elm) {
388 bool tmp_is_a_vm = (nullptr != dynamic_cast<VirtualMachine*>(elm));
389 return is_a_vm == tmp_is_a_vm;
391 "parallel_execute: mixing VMs and PMs is not supported (yet).");
392 /* checking for infinite values */
393 xbt_assert(std::all_of(flops_amounts.begin(), flops_amounts.end(), [](double elm) { return std::isfinite(elm); }),
394 "flops_amounts comprises infinite values!");
395 xbt_assert(std::all_of(bytes_amounts.begin(), bytes_amounts.end(), [](double elm) { return std::isfinite(elm); }),
396 "flops_amounts comprises infinite values!");
398 return Exec::init()->set_flops_amounts(flops_amounts)->set_bytes_amounts(bytes_amounts)->set_hosts(hosts);
401 ExecPtr exec_async(double flops)
403 ExecPtr res = exec_init(flops);
404 res->vetoable_start();
410 return simgrid::kernel::actor::ActorImpl::self()->get_pid();
415 return simgrid::kernel::actor::ActorImpl::self()->get_ppid();
418 std::string get_name()
420 return simgrid::kernel::actor::ActorImpl::self()->get_name();
423 const char* get_cname()
425 return simgrid::kernel::actor::ActorImpl::self()->get_cname();
430 return simgrid::kernel::actor::ActorImpl::self()->get_host();
435 kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self();
436 s4u::Actor::on_suspend(*self->get_ciface());
437 kernel::actor::simcall_blocking([self] { self->suspend(); });
442 kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self();
443 simgrid::kernel::actor::simcall([self] { self->exit(); });
446 void on_exit(const std::function<void(bool)>& fun)
448 simgrid::kernel::actor::ActorImpl::self()->get_iface()->on_exit(fun);
451 /** @brief Moves the current actor to another host
453 * @see simgrid::s4u::Actor::migrate() for more information
455 void set_host(Host* new_host)
457 simgrid::kernel::actor::ActorImpl::self()->get_iface()->set_host(new_host);
459 void migrate(Host* new_host) // XBT_ATTRIB_DEPRECATED_v329
464 } // namespace this_actor
466 } // namespace simgrid
468 /* **************************** Public C interface *************************** */
469 size_t sg_actor_count()
471 return simgrid::s4u::Engine::get_instance()->get_actor_count();
474 sg_actor_t* sg_actor_list()
476 const simgrid::s4u::Engine* e = simgrid::s4u::Engine::get_instance();
477 size_t actor_count = e->get_actor_count();
478 xbt_assert(actor_count > 0, "There is no actor!");
479 std::vector<simgrid::s4u::ActorPtr> actors = e->get_all_actors();
481 sg_actor_t* res = xbt_new(sg_actor_t, actors.size());
482 for (size_t i = 0; i < actor_count; i++)
483 res[i] = actors[i].get();
487 sg_actor_t sg_actor_init(const char* name, sg_host_t host)
489 return simgrid::s4u::Actor::init(name, host).get();
492 void sg_actor_start_(sg_actor_t actor, xbt_main_func_t code, int argc, const char* const* argv)
494 simgrid::kernel::actor::ActorCode function;
496 function = simgrid::xbt::wrap_main(code, argc, argv);
497 actor->start(function);
500 sg_actor_t sg_actor_create_(const char* name, sg_host_t host, xbt_main_func_t code, int argc, const char* const* argv)
502 simgrid::kernel::actor::ActorCode function = simgrid::xbt::wrap_main(code, argc, argv);
503 return simgrid::s4u::Actor::init(name, host)->start(function).get();
506 void sg_actor_set_stacksize(sg_actor_t actor, unsigned size)
508 actor->set_stacksize(size);
513 simgrid::s4u::this_actor::exit();
517 * @brief Returns the process ID of @a actor.
519 * This function checks whether @a actor is a valid pointer and return its PID (or 0 in case of problem).
522 aid_t sg_actor_get_pid(const_sg_actor_t actor)
524 /* Do not raise an exception here: this function is called by the logs
525 * and the exceptions, so it would be called back again and again */
526 if (actor == nullptr || actor->get_impl() == nullptr)
528 return actor->get_pid();
532 * @brief Returns the process ID of the parent of @a actor.
534 * This function checks whether @a actor is a valid pointer and return its parent's PID.
535 * Returns -1 if the actor has not been created by any other actor.
537 aid_t sg_actor_get_ppid(const_sg_actor_t actor)
539 return actor->get_ppid();
543 * @brief Return a #sg_actor_t given its PID.
545 * 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.
546 * If none is found, @c nullptr is returned.
547 Note that the PID are unique in the whole simulation, not only on a given host.
549 sg_actor_t sg_actor_by_pid(aid_t pid)
551 return simgrid::s4u::Actor::by_pid(pid).get();
554 aid_t sg_actor_get_PID(const_sg_actor_t actor) // XBT_ATTRIB_DEPRECATED_v331
556 return sg_actor_get_pid(actor);
559 aid_t sg_actor_get_PPID(const_sg_actor_t actor) // XBT_ATTRIB_DEPRECATED_v331
561 return sg_actor_get_ppid(actor);
564 sg_actor_t sg_actor_by_PID(aid_t pid) // XBT_ATTRIB_DEPRECATED_v331
566 return sg_actor_by_pid(pid);
569 /** @brief Return the name of an actor. */
570 const char* sg_actor_get_name(const_sg_actor_t actor)
572 return actor->get_cname();
575 sg_host_t sg_actor_get_host(const_sg_actor_t actor)
577 return actor->get_host();
581 * @brief Returns the value of a given actor property
583 * @param actor an actor
584 * @param name a property name
585 * @return value of a property (or nullptr if the property is not set)
587 const char* sg_actor_get_property_value(const_sg_actor_t actor, const char* name)
589 return actor->get_property(name);
593 * @brief Return the list of properties
595 * This function returns all the parameters associated with an actor
597 xbt_dict_t sg_actor_get_properties(const_sg_actor_t actor)
599 xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
600 xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
601 const std::unordered_map<std::string, std::string>* props = actor->get_properties();
602 if (props == nullptr)
604 for (auto const& kv : *props) {
605 xbt_dict_set(as_dict, kv.first.c_str(), xbt_strdup(kv.second.c_str()));
611 * @brief Suspend the actor.
613 * This function suspends the actor by suspending the task on which it was waiting for the completion.
615 void sg_actor_suspend(sg_actor_t actor)
617 xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
622 * @brief Resume a suspended actor.
624 * This function resumes a suspended actor by resuming the task on which it was waiting for the completion.
626 void sg_actor_resume(sg_actor_t actor)
628 xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
633 * @brief Returns true if the actor is suspended .
635 * This checks whether an actor is suspended or not by inspecting the task on which it was waiting for the completion.
637 int sg_actor_is_suspended(const_sg_actor_t actor)
639 return actor->is_suspended();
642 /** @brief Restarts an actor from the beginning. */
643 sg_actor_t sg_actor_restart(sg_actor_t actor)
645 return actor->restart();
649 * @brief Sets the "auto-restart" flag of the actor.
650 * If the flag is set to 1, the actor will be automatically restarted when its host comes back up.
652 void sg_actor_set_auto_restart(sg_actor_t actor, int auto_restart)
654 actor->set_auto_restart(auto_restart);
657 /** @brief This actor will be terminated automatically when the last non-daemon actor finishes */
658 void sg_actor_daemonize(sg_actor_t actor)
663 /** Returns whether or not this actor has been daemonized or not */
664 int sg_actor_is_daemon(const_sg_actor_t actor)
666 return actor->is_daemon();
670 * @brief Migrates an actor to another location.
672 * This function changes the value of the #sg_host_t on which @a actor is running.
674 void sg_actor_set_host(sg_actor_t actor, sg_host_t host)
676 actor->set_host(host);
678 void sg_actor_migrate(sg_actor_t process, sg_host_t host) // XBT_ATTRIB_DEPRECATED_v329
680 process->set_host(host);
684 * @brief Wait for the completion of a #sg_actor_t.
686 * @param actor the actor to wait for
687 * @param timeout wait until the actor is over, or the timeout expires
689 void sg_actor_join(const_sg_actor_t actor, double timeout)
691 actor->join(timeout);
694 void sg_actor_kill(sg_actor_t actor)
699 void sg_actor_kill_all()
701 simgrid::s4u::Actor::kill_all();
705 * @brief Set the kill time of an actor.
707 * @param actor an actor
708 * @param kill_time the time when the actor is killed.
710 void sg_actor_set_kill_time(sg_actor_t actor, double kill_time)
712 actor->set_kill_time(kill_time);
715 /** Yield the current actor; let the other actors execute first */
716 void sg_actor_yield()
718 simgrid::s4u::this_actor::yield();
721 void sg_actor_sleep_for(double duration)
723 simgrid::s4u::this_actor::sleep_for(duration);
726 void sg_actor_sleep_until(double wakeup_time)
728 simgrid::s4u::this_actor::sleep_until(wakeup_time);
731 sg_actor_t sg_actor_attach(const char* name, void* data, sg_host_t host, xbt_dict_t properties)
733 xbt_assert(host != nullptr, "Invalid parameters: host and code params must not be nullptr");
734 std::unordered_map<std::string, std::string> props;
735 xbt_dict_cursor_t cursor = nullptr;
738 xbt_dict_foreach (properties, cursor, key, value)
740 xbt_dict_free(&properties);
742 /* Let's create the process: SIMIX may decide to start it right now, even before returning the flow control to us */
743 smx_actor_t actor = nullptr;
745 actor = simgrid::kernel::actor::ActorImpl::attach(name, data, host).get();
746 actor->set_properties(props);
747 } catch (simgrid::HostFailureException const&) {
748 xbt_die("Could not attach");
751 simgrid::s4u::this_actor::yield();
752 return actor->get_ciface();
755 void sg_actor_detach()
757 simgrid::kernel::actor::ActorImpl::detach();
760 aid_t sg_actor_self_get_pid()
762 return simgrid::s4u::this_actor::get_pid();
765 aid_t sg_actor_self_get_ppid()
767 return simgrid::s4u::this_actor::get_ppid();
770 const char* sg_actor_self_get_name()
772 return simgrid::s4u::this_actor::get_cname();
775 void* sg_actor_self_get_data()
777 return simgrid::s4u::Actor::self()->get_data();
780 void sg_actor_self_set_data(void* userdata)
782 simgrid::s4u::Actor::self()->set_data(userdata);
785 void* sg_actor_self_data() // XBT_ATTRIB_DEPRECATED_v330
787 return sg_actor_self_get_data();
790 void sg_actor_self_data_set(void* userdata) // XBT_ATTRIB_DEPRECATED_v330
792 sg_actor_self_set_data(userdata);
795 sg_actor_t sg_actor_self()
797 return simgrid::s4u::Actor::self();
800 void sg_actor_self_execute(double flops) // XBT_ATTRIB_DEPRECATED_v330
802 simgrid::s4u::this_actor::execute(flops);
805 void sg_actor_execute(double flops)
807 simgrid::s4u::this_actor::execute(flops);
809 void sg_actor_execute_with_priority(double flops, double priority)
811 simgrid::s4u::this_actor::exec_init(flops)->set_priority(priority)->wait();
814 void sg_actor_parallel_execute(int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount)
816 std::vector<simgrid::s4u::Host*> hosts(host_list, host_list + host_nb);
817 std::vector<double> flops;
818 std::vector<double> bytes;
819 if (flops_amount != nullptr)
820 flops = std::vector<double>(flops_amount, flops_amount + host_nb);
821 if (bytes_amount != nullptr)
822 bytes = std::vector<double>(bytes_amount, bytes_amount + host_nb * host_nb);
824 simgrid::s4u::this_actor::parallel_execute(hosts, flops, bytes);
827 /** @brief Take an extra reference on that actor to prevent it to be garbage-collected */
828 void sg_actor_ref(const_sg_actor_t actor)
830 intrusive_ptr_add_ref(actor);
832 /** @brief Release a reference on that actor so that it can get be garbage-collected */
833 void sg_actor_unref(const_sg_actor_t actor)
835 intrusive_ptr_release(actor);
838 /** @brief Return the user data of a #sg_actor_t */
839 void* sg_actor_get_data(const_sg_actor_t actor)
841 return actor->get_data();
844 /** @brief Set the user data of a #sg_actor_t */
845 void sg_actor_set_data(sg_actor_t actor, void* userdata)
847 actor->set_data(userdata);
850 void* sg_actor_data(const_sg_actor_t actor) // XBT_ATTRIB_DEPRECATED_v330
852 return sg_actor_get_data(actor);
855 void sg_actor_data_set(sg_actor_t actor, void* userdata) // XBT_ATTRIB_DEPRECATED_v330
857 sg_actor_set_data(actor, userdata);
860 /** @brief Add a function to the list of "on_exit" functions for the current process.
861 * The on_exit functions are the functions executed when your process is killed.
862 * You should use them to free the data used by your process.
864 void sg_actor_on_exit(void_f_int_pvoid_t fun, void* data)
866 simgrid::s4u::this_actor::on_exit([fun, data](bool failed) { fun(failed ? 1 /*FAILURE*/ : 0 /*SUCCESS*/, data); });
869 sg_exec_t sg_actor_exec_init(double computation_amount)
871 simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(computation_amount);
876 sg_exec_t sg_actor_parallel_exec_init(int host_nb, const sg_host_t* host_list, double* flops_amount,
877 double* bytes_amount)
879 std::vector<simgrid::s4u::Host*> hosts(host_list, host_list + host_nb);
880 std::vector<double> flops;
881 std::vector<double> bytes;
882 if (flops_amount != nullptr)
883 flops = std::vector<double>(flops_amount, flops_amount + host_nb);
884 if (bytes_amount != nullptr)
885 bytes = std::vector<double>(bytes_amount, bytes_amount + host_nb * host_nb);
887 simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(hosts, flops, bytes);
892 sg_exec_t sg_actor_exec_async(double computation_amount)
894 simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_async(computation_amount);