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.
Defining the skeleton of an Actor
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:
#include "s4u/actor.hpp"
void worker() {
printf("Hello s4u");
};
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.
#include "s4u/actor.hpp"
class Worker {
public:
void operator()() {
printf("Hello s4u");
}
};
Fleshing your actor
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 .
Using a deployment file
- Warning
- This is currently not working with S4U. Sorry about that.
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.
<?xml version='1.0'?>
<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
<platform version="4">
<process host="Tremblay" function="master">
<argument value="20"/>
<argument value="50000000"/>
<argument value="1000000"/>
<argument value="5"/>
</process>
<process host="Jupiter" function="worker"/> <!-- Don't provide any parameter ->>
</platform>
Simulation Agent
|
static ActorPtr | self () |
| Retrieve a reference to myself. More...
|
|
static ActorPtr | createActor (const char *name, s4u::Host *host, double killTime, std::function< void()> code) |
| Create an actor using a function. More...
|
|
static ActorPtr | createActor (const char *name, s4u::Host *host, std::function< void()> code) |
|
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, double killTime, const char *function, std::vector< std::string > args) |
|
static ActorPtr | createActor (const char *name, s4u::Host *host, const char *function, std::vector< std::string > args) |
|
static void | kill (int pid) |
|
static ActorPtr | forPid (int pid) |
|
static void | killAll () |
| Ask kindly to all actors to die. More...
|
|