SimGrid
3.21
Versatile Simulation of Distributed Systems
|
An actor is an independent stream of execution in your distributed application.
You can think of an actor as a process in your distributed application, or as a thread in a multithreaded program. This is the only component in SimGrid that actually does something on its own, executing its own code. A resource will not get used if you don't schedule activities on them. This is the code of Actors that create and schedule these activities.
An actor is located on a (simulated) host, but it can interact with the whole simulated platform.
The s4u::Actor API is strongly inspired from the C++11 threads. The documentation of this standard may help to understand the philosophy of the S4U Actors.
As in the C++11 standard, you can declare the code of your actor either as a pure function or as an object. It is very simple with functions:
But some people prefer to encapsulate their actors in classes and objects to save the actor state in a cleanly dedicated location. The syntax is slightly more complicated, but not much.
The body of your actor can use the functions of the simgrid::s4u::this_actor namespace to interact with the world. This namespace contains the methods to start new activities (executions, communications, etc), and to get informations about the currently running thread (its location, etc).
Please refer to the full API .
The best practice is to use an external deployment file as follows, because it makes it easier to test your application in differing settings. Load this file with s4u::Engine::loadDeployment() before the simulation starts. Refer to the Deploy the simulation section for more information.
Simulation Agent
#include <Actor.hpp>
Inherits simgrid::xbt::Extendable< Actor >.
Public Member Functions | |
Actor (Actor const &)=delete | |
Actor & | operator= (Actor const &)=delete |
void | daemonize () |
This actor will be automatically terminated when the last non-daemon actor finishes. More... | |
bool | is_daemon () const |
Returns whether or not this actor has been daemonized or not. More... | |
const simgrid::xbt::string & | get_name () const |
Retrieves the name of that actor as a C++ string. More... | |
const char * | get_cname () const |
Retrieves the name of that actor as a C string. More... | |
s4u::Host * | get_host () |
Retrieves the host on which that actor is running. More... | |
aid_t | get_pid () const |
Retrieves the PID of that actor. More... | |
aid_t | get_ppid () const |
Retrieves the PPID of that actor. More... | |
void | suspend () |
Suspend an actor by suspending the task on which it was waiting for the completion. More... | |
void | resume () |
Resume a suspended actor by resuming the task on which it was waiting for the completion. More... | |
void | yield () |
bool | is_suspended () |
Returns true if the actor is suspended. More... | |
void | set_auto_restart (bool autorestart) |
If set to true, the actor will automatically restart when its host reboots. More... | |
void | on_exit (std::function< void(int, void *)> fun, void *data) |
Add a function to the list of "on_exit" functions for the current actor. More... | |
void | set_kill_time (double time) |
Sets the time at which that actor should be killed. More... | |
double | get_kill_time () |
Retrieves the time at which that actor will be killed (or -1 if not set) More... | |
void | migrate (Host *new_host) |
Moves the actor to another host. More... | |
void | kill () |
Ask the actor to die. More... | |
void | join () |
Wait for the actor to finish. More... | |
void | join (double timeout) |
Actor * | restart () |
kernel::actor::ActorImpl * | get_impl () |
Returns the internal implementation of this actor. More... | |
std::unordered_map< std::string, std::string > * | get_properties () |
Retrieve the property value (or nullptr if not set) More... | |
const char * | get_property (std::string key) |
void | set_property (std::string key, std::string value) |
![]() | |
Extendable () | |
~Extendable () | |
void * | extension (std::size_t rank) |
U * | extension (Extension< Actor, U > rank) |
U * | extension () |
void | extension_set (std::size_t rank, void *value, bool use_dtor=true) |
void | extension_set (Extension< Actor, U > rank, U *value, bool use_dtor=true) |
void | extension_set (U *p) |
Static Public Member Functions | |
static ActorPtr | self () |
Retrieve a reference to myself. More... | |
static ActorPtr | create (std::string name, s4u::Host *host, std::function< void()> code) |
Create an actor from a std::function<void()> More... | |
template<class F > | |
static ActorPtr | create (std::string name, s4u::Host *host, F code) |
Create an actor from a std::function. More... | |
template<class F , class... Args, typename = typename std::result_of<F(Args...)>::type> | |
static ActorPtr | create (std::string name, s4u::Host *host, F code, Args... args) |
Create an actor using a callable thing and its arguments. More... | |
static ActorPtr | create (std::string name, s4u::Host *host, std::string function, std::vector< std::string > args) |
static void | kill (aid_t pid) |
Kill an actor from its ID. More... | |
static ActorPtr | by_pid (aid_t pid) |
Retrieves the actor that have the given PID (or nullptr if not existing) More... | |
static void | kill_all () |
Ask kindly to all actors to die. More... | |
![]() | |
static size_t | extension_create (void(*deleter)(void *)) |
static Extension< Actor, U > | extension_create (void(*deleter)(void *)) |
static Extension< Actor, U > | extension_create () |
Static Public Attributes | |
static simgrid::xbt::signal< void(simgrid::s4u::ActorPtr)> | on_creation |
Signal to others that a new actor has been created. More... | |
static simgrid::xbt::signal< void(simgrid::s4u::ActorPtr)> | on_suspend |
Signal to others that an actor has been suspended. More... | |
static simgrid::xbt::signal< void(simgrid::s4u::ActorPtr)> | on_resume |
Signal to others that an actor has been resumed. More... | |
static simgrid::xbt::signal< void(simgrid::s4u::ActorPtr)> | on_sleep |
Signal to others that an actor is sleeping. More... | |
static simgrid::xbt::signal< void(simgrid::s4u::ActorPtr)> | on_wake_up |
Signal to others that an actor wakes up for a sleep. More... | |
static simgrid::xbt::signal< void(simgrid::s4u::ActorPtr)> | on_migration_start |
Signal to others that an actor is going to migrated to another host. More... | |
static simgrid::xbt::signal< void(simgrid::s4u::ActorPtr)> | on_migration_end |
Signal to others that an actor is has been migrated to another host. More... | |
static simgrid::xbt::signal< void(simgrid::s4u::ActorPtr)> | on_destruction |
Signal indicating that an actor is about to disappear. More... | |
Friends | |
void | intrusive_ptr_add_ref (Actor *actor) |
void | intrusive_ptr_release (Actor *actor) |
|
delete |
|
static |
Retrieve a reference to myself.
|
static |
Create an actor from a std::function<void()>
If the actor is restarted, the actor has a fresh copy of the function.
|
inlinestatic |
Create an actor from a std::function.
If the actor is restarted, the actor has a fresh copy of the function.
|
inlinestatic |
Create an actor using a callable thing and its arguments.
Note that the arguments will be copied, so move-only parameters are forbidden
|
static |
void simgrid::s4u::Actor::daemonize | ( | ) |
This actor will be automatically terminated when the last non-daemon actor finishes.
bool simgrid::s4u::Actor::is_daemon | ( | ) | const |
Returns whether or not this actor has been daemonized or not.
const simgrid::xbt::string& simgrid::s4u::Actor::get_name | ( | ) | const |
Retrieves the name of that actor as a C++ string.
const char* simgrid::s4u::Actor::get_cname | ( | ) | const |
Retrieves the name of that actor as a C string.
s4u::Host* simgrid::s4u::Actor::get_host | ( | ) |
Retrieves the host on which that actor is running.
aid_t simgrid::s4u::Actor::get_pid | ( | ) | const |
Retrieves the PID of that actor.
aid_t is an alias for long
aid_t simgrid::s4u::Actor::get_ppid | ( | ) | const |
Retrieves the PPID of that actor.
aid_t is an alias for long
void simgrid::s4u::Actor::suspend | ( | ) |
Suspend an actor by suspending the task on which it was waiting for the completion.
void simgrid::s4u::Actor::resume | ( | ) |
Resume a suspended actor by resuming the task on which it was waiting for the completion.
void simgrid::s4u::Actor::yield | ( | ) |
bool simgrid::s4u::Actor::is_suspended | ( | ) |
Returns true if the actor is suspended.
void simgrid::s4u::Actor::set_auto_restart | ( | bool | autorestart | ) |
If set to true, the actor will automatically restart when its host reboots.
void simgrid::s4u::Actor::on_exit | ( | std::function< void(int, void *)> | fun, |
void * | data | ||
) |
Add a function to the list of "on_exit" functions for the current actor.
The on_exit functions are the functions executed when your actor is killed. You should use them to free the data used by your actor.
void simgrid::s4u::Actor::set_kill_time | ( | double | time | ) |
Sets the time at which that actor should be killed.
double simgrid::s4u::Actor::get_kill_time | ( | ) |
Retrieves the time at which that actor will be killed (or -1 if not set)
void simgrid::s4u::Actor::migrate | ( | Host * | new_host | ) |
Moves the actor to another host.
If the actor is currently blocked on an execution activity, the activity is also migrated to the new host. If it's blocked on another kind of activity, an error is raised as the mandated code is not written yet. Please report that bug if you need it.
Asynchronous activities started by the actor are not migrated automatically, so you have to take care of this yourself (only you knows which ones should be migrated).
void simgrid::s4u::Actor::kill | ( | ) |
Ask the actor to die.
Any blocking activity will be canceled, and it will be rescheduled to free its memory. Being killed is not something that actors can defer or avoid.
SimGrid still have sometimes issues when you kill actors that are currently communicating and such. Still. Please report any bug that you may encounter with a minimal working example.
|
static |
Kill an actor from its ID.
|
static |
Retrieves the actor that have the given PID (or nullptr if not existing)
void simgrid::s4u::Actor::join | ( | ) |
Wait for the actor to finish.
This blocks the calling actor until the actor on which we call join() is terminated
void simgrid::s4u::Actor::join | ( | double | timeout | ) |
Actor* simgrid::s4u::Actor::restart | ( | ) |
|
static |
Ask kindly to all actors to die.
Only the issuer will survive.
kernel::actor::ActorImpl* simgrid::s4u::Actor::get_impl | ( | ) |
Returns the internal implementation of this actor.
std::unordered_map<std::string, std::string>* simgrid::s4u::Actor::get_properties | ( | ) |
Retrieve the property value (or nullptr if not set)
const char* simgrid::s4u::Actor::get_property | ( | std::string | key | ) |
void simgrid::s4u::Actor::set_property | ( | std::string | key, |
std::string | value | ||
) |
|
friend |
|
friend |
|
static |
Signal to others that a new actor has been created.
|
static |
Signal to others that an actor has been suspended.
|
static |
Signal to others that an actor has been resumed.
|
static |
Signal to others that an actor is sleeping.
|
static |
Signal to others that an actor wakes up for a sleep.
|
static |
Signal to others that an actor is going to migrated to another host.
|
static |
Signal to others that an actor is has been migrated to another host.
|
static |
Signal indicating that an actor is about to disappear.
This signal is fired for any dying actor, which is mostly useful when designing plugins and extensions. If you want to register to the termination of a given actor, use this_actor::on_exit() instead.