SimGrid
3.18
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>
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... | |
const simgrid::xbt::string & | getName () const |
Retrieves the name of that actor as a C++ string. More... | |
const char * | getCname () const |
Retrieves the name of that actor as a C string. More... | |
s4u::Host * | getHost () |
Retrieves the host on which that actor is running. More... | |
aid_t | getPid () |
Retrieves the PID of that actor. More... | |
aid_t | getPpid () |
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 () |
int | isSuspended () |
Returns true if the actor is suspended. More... | |
void | setAutoRestart (bool autorestart) |
If set to true, the actor will automatically restart when its host reboots. More... | |
void | onExit (int_f_pvoid_pvoid_t fun, void *data) |
Add a function to the list of "on_exit" functions for the current actor. More... | |
void | setKillTime (double time) |
Sets the time at which that actor should be killed. More... | |
double | getKillTime () |
Retrieves the time at which that actor will be killed (or -1 if not set) More... | |
void | migrate (Host *new_host) |
void | kill () |
Ask the actor to die. More... | |
void | join () |
Wait for the actor to finish. More... | |
void | join (double timeout) |
simix::ActorImpl * | getImpl () |
Returns the internal implementation of this actor. More... | |
std::map< std::string, std::string > * | getProperties () |
Retrieve the property value (or nullptr if not set) More... | |
const char * | getProperty (const char *key) |
Retrieve the property value (or nullptr if not set) More... | |
void | setProperty (const char *key, const char *value) |
Actor * | restart () |
![]() | |
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 | createActor (const char *name, s4u::Host *host, std::function< void()> code) |
Create an actor using a function. More... | |
static ActorPtr | createActor (const char *name, s4u::Host *host, std::function< void(std::vector< std::string > *)> code, std::vector< std::string > *args) |
template<class F , class... Args, typename = typename std::result_of<F(Args...)>::type> | |
static ActorPtr | createActor (const char *name, s4u::Host *host, F code, Args... args) |
Create an actor using code. More... | |
static ActorPtr | createActor (const char *name, s4u::Host *host, const char *function, std::vector< std::string > args) |
static void | kill (aid_t pid) |
static ActorPtr | byPid (aid_t pid) |
Retrieves the actor that have the given PID (or nullptr if not existing) More... | |
static void | killAll () |
Ask kindly to all actors to die. More... | |
static void | killAll (int resetPid) |
![]() | |
static size_t | extension_create (void(*deleter)(void *)) |
static Extension< Actor, U > | extension_create (void(*deleter)(void *)) |
static Extension< Actor, U > | extension_create () |
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 using a function.
If the actor is restarted, the actor has a fresh copy of the function.
|
inlinestatic |
|
inlinestatic |
Create an actor using code.
Using this constructor, move-only type can be used. The consequence is that we cannot copy the value and restart the actor in its initial state. In order to use auto-restart, an explicit function
must be passed instead.
|
static |
void simgrid::s4u::Actor::daemonize | ( | ) |
This actor will be automatically terminated when the last non-daemon actor finishes.
const simgrid::xbt::string & simgrid::s4u::Actor::getName | ( | ) | const |
Retrieves the name of that actor as a C++ string.
const char * simgrid::s4u::Actor::getCname | ( | ) | const |
Retrieves the name of that actor as a C string.
s4u::Host * simgrid::s4u::Actor::getHost | ( | ) |
Retrieves the host on which that actor is running.
aid_t simgrid::s4u::Actor::getPid | ( | ) |
Retrieves the PID of that actor.
actor_id_t is an alias for unsigned long
aid_t simgrid::s4u::Actor::getPpid | ( | ) |
Retrieves the PPID of that actor.
actor_id_t is an alias for unsigned 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 | ( | ) |
int simgrid::s4u::Actor::isSuspended | ( | ) |
Returns true if the actor is suspended.
void simgrid::s4u::Actor::setAutoRestart | ( | bool | autorestart | ) |
If set to true, the actor will automatically restart when its host reboots.
void simgrid::s4u::Actor::onExit | ( | int_f_pvoid_pvoid_t | 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::setKillTime | ( | double | time | ) |
Sets the time at which that actor should be killed.
double simgrid::s4u::Actor::getKillTime | ( | ) |
Retrieves the time at which that actor will be killed (or -1 if not set)
Get the kill time of an actor(or 0 if unset).
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.
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 | ) |
|
static |
Ask kindly to all actors to die.
Only the issuer will survive.
|
static |
smx_actor_t simgrid::s4u::Actor::getImpl | ( | ) |
Returns the internal implementation of this actor.
std::map< std::string, std::string > * simgrid::s4u::Actor::getProperties | ( | ) |
Retrieve the property value (or nullptr if not set)
const char * simgrid::s4u::Actor::getProperty | ( | const char * | key | ) |
Retrieve the property value (or nullptr if not set)
void simgrid::s4u::Actor::setProperty | ( | const char * | key, |
const char * | value | ||
) |
Actor * simgrid::s4u::Actor::restart | ( | ) |