-foreach (example actor-migration app-masterworker app-token-ring io launching mutex actions-comm actions-storage)
+foreach (example actions-comm actions-storage actor-create actor-kill actor-migration actor-suspend
+ app-masterworker app-token-ring io mutex )
add_executable (s4u_${example} ${example}/s4u_${example}.cpp)
target_link_libraries(s4u_${example} simgrid)
set_target_properties(s4u_${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example})
set(examples_src ${examples_src} PARENT_SCOPE)
set(tesh_files ${tesh_files} PARENT_SCOPE)
-set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/launching/deployment.xml
- ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u_actions-comm_split_d.xml
+set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u_actions-comm_split_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u_actions-comm_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/actions-storage/s4u_actions-storage_d.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/s4u_actor-create_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/s4u_app-masterworker_d.xml PARENT_SCOPE)
set(txt_files ${txt_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u_actions-comm_split_p0.txt
${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u_actions-comm_split_p1.txt
${CMAKE_CURRENT_SOURCE_DIR}/actions-storage/s4u_actions-storage.txt
${CMAKE_CURRENT_SOURCE_DIR}/README.doc PARENT_SCOPE)
-foreach(example actor-migration app-masterworker app-token-ring io launching mutex actions-comm actions-storage)
+foreach(example actions-comm actions-storage actor-create actor-kill actor-migration actor-suspend
+ app-masterworker app-token-ring io mutex )
ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/${example} s4u_${example}.tesh)
endforeach()
@section s4u_ex_actors Acting on Actors
+ - <b>Creating actors</b>.
+ @ref examples/s4u/actor-create/s4u_actor-create.cpp \n
+ Most actors are started from the deployment XML file, but they exist other methods.
+
+ - <b>Suspend and Resume actors</b>.
+ @ref examples/s4u/actor-suspend/actor-suspend.cpp \n
+ Actors can be suspended and resumed during their executions
+ thanks to the @ref suspend and @ref resume methods.
+
+ - <b>Kill actors</b>.
+ @ref examples/s4u/actor-kill/actor-kill.cpp \n
+ Actors can forcefully stop other actors with the @ref kill method.
+
- <b>Migrating Actors</b>.
@ref examples/s4u/actor-migration/s4u_actor-migration.cpp \n
Actors can move or be moved from a host to another with the @ref migrate method.
/**
@example examples/s4u/actions-comm/s4u_actions-comm.cpp
@example examples/s4u/actions-storage/s4u_actions-storage.cpp
+@example examples/s4u/actor-create/s4u_actor-create.cpp
+@example examples/s4u/actor-kill/actor-kill.cpp
@example examples/s4u/actor-migration/s4u_actor-migration.cpp
+@example examples/s4u/actor-suspend/s4u_actor-suspend.cpp
@example examples/s4u/app-token-ring/s4u_app-token-ring.cpp
@example examples/s4u/app-master-worker/s4u_app-master-worker.cpp
@example examples/s4u/launching/deployment.xml
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-
/* This example shows how to declare and start your actors.
*
- * The first step is to declare the code of your actors (what they do exactly
- * does not matter to this example) and then you ask SimGrid to start your
- * actors. There is three ways of doing so:
+ * The first step is to declare the code of your actors (what they do exactly does not matter to this example) and then
+ * you ask SimGrid to start your actors. There is three ways of doing so:
* - Directly, by instantiating your actor as paramter to Actor::create();
* - By first registering your actors before instantiating it;
* - Through the deployment file.
*
- * This example shows all these solutions, even if you obviously should use
- * only one of these solutions to start your actors. The most advised solution
- * is to use a deployment file, as it creates a clear separation between your
- * application and the settings to test it. This is a better scientific
- * methodology. Actually, starting an actor with Actor::create() is mostly
- * useful to start an actor from another actor.
- *
+ * This example shows all these solutions, even if you obviously should use only one of these solutions to start your
+ * actors. The most advised solution is to use a deployment file, as it creates a clear separation between your
+ * application and the settings to test it. This is a better scientific methodology. Actually, starting an actor with
+ * Actor::create() is mostly useful to start an actor from another actor.
*/
#include <simgrid/s4u.hpp>
// This declares a logging channel so that XBT_INFO can be used later
-XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_launching_test, "The logging channel used in this example");
-
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_create, "The logging channel used in this example");
/* Declares a first class of actors which sends a message to the mailbox 'mb42'.
* The sent message is what was passed as parameter on creation (or 'GaBuZoMeu' by default)
class Sender {
public:
std::string msg = "GaBuZoMeu";
- explicit Sender() {
- /* Constructor used when no parameter is passed to the actor */
+ explicit Sender(){
+ /* Constructor used when no parameter is passed to the actor */
};
- explicit Sender(std::vector<std::string> args) {
+ explicit Sender(std::vector<std::string> args)
+ {
/* This constructor is used when we pass parameters to the actor */
if (args.size() > 0)
msg = args[0];
}
- void operator()() {
+ void operator()()
+ {
XBT_INFO("Hello s4u, I have something to send");
simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("mb42");
}
};
-
/* Declares a second class of actor which receive two messages on the mailbox which
* name is passed as parameter ('thingy' by default, ie the wrong one).
*
simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("thingy");
explicit Receiver() = default;
- explicit Receiver(std::vector<std::string> args) {
+ explicit Receiver(std::vector<std::string> args)
+ {
/* This constructor is used when we pass parameters to the actor */
/* as with argc/argv, args[0] is the actor's name, so the first parameter is args[1] */
if (args.size() > 1)
mailbox = simgrid::s4u::Mailbox::byName(args[1]);
}
- void operator()() {
+ void operator()()
+ {
XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->name());
- char *msg1 = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
- char *msg2 = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
- XBT_INFO("I received '%s' and '%s'",msg1,msg2);
+ char* msg1 = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
+ char* msg2 = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
+ XBT_INFO("I received '%s' and '%s'", msg1, msg2);
XBT_INFO("I'm done. See you.");
}
};
-
/* Here comes the main function of your program */
-int main(int argc, char **argv) {
+int main(int argc, char** argv)
+{
/* When your program starts, you have to first start a new simulation engine, as follows */
- simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
+ simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
/* Then you should load a platform file, describing your simulated platform */
e->loadPlatform("../../platforms/small_platform.xml");
/* The second way is to first register your function, and then retrieve it */
e->registerFunction<Sender>("sender"); // The sender is passed as a template parameter here
- std::vector<std::string> args; // Here we declare the parameter that the actor will get
- args.push_back("GloubiBoulga"); // Add a parameter to the set (we could have done it in the first approach too)
+ std::vector<std::string> args; // Here we declare the parameter that the actor will get
+ args.push_back("GloubiBoulga"); // Add a parameter to the set (we could have done it in the first approach too)
simgrid::s4u::Actor::createActor("sender2", simgrid::s4u::Host::by_name("Jupiter"), "sender", args);
/* The third way to start your actors is to use a deployment file. */
- e->registerFunction<Receiver>("receiver"); // You first have to register the actor as with the second approach
- e->loadDeployment("deployment.xml"); // And then, you load the deployment file
+ e->registerFunction<Receiver>("receiver"); // You first have to register the actor as with the second approach
+ e->loadDeployment("s4u_actor-create_d.xml"); // And then, you load the deployment file
/* Once every actors are started in the engine, the simulation can start */
e->run();
#! ./tesh
-$ $SG_TEST_EXENV ${bindir:=.}/s4u_launching
+$ $SG_TEST_EXENV ${bindir:=.}/s4u_actor-create
> [Tremblay:sender1:(0) 0.000000] [s4u_launching_test/INFO] Hello s4u, I have something to send
> [Jupiter:sender2:(0) 0.000000] [s4u_launching_test/INFO] Hello s4u, I have something to send
> [Fafard:receiver:(0) 0.000000] [s4u_launching_test/INFO] Hello s4u, I'm ready to get any message you'd want on mb42
--- /dev/null
+/* Copyright (c) 2017 The SimGrid Team. All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <simgrid/s4u.hpp>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_kill, "Messages specific for this s4u example");
+
+static void victim()
+{
+ XBT_INFO("Hello!");
+ XBT_INFO("Suspending myself");
+ simgrid::s4u::this_actor::suspend(); /* - Start by suspending itself */
+ XBT_INFO("OK, OK. Let's work"); /* - Then is resumed and start to execute a task */
+ simgrid::s4u::this_actor::execute(1e9);
+ XBT_INFO("Bye!"); /* - But will never reach the end of it */
+}
+
+static void killer()
+{
+ XBT_INFO("Hello!"); /* - First start a victim process */
+ simgrid::s4u::ActorPtr poor_victim =
+ simgrid::s4u::Actor::createActor("victim", simgrid::s4u::Host::by_name("Fafard"), victim);
+ simgrid::s4u::this_actor::sleep_for(10); /* - Wait for 10 seconds */
+
+ XBT_INFO("Resume process"); /* - Resume it from its suspended state */
+ poor_victim->resume();
+
+ XBT_INFO("Kill process"); /* - and then kill it */
+ poor_victim->kill();
+
+ XBT_INFO("OK, goodbye now. I commit a suicide.");
+ simgrid::s4u::this_actor::kill();
+
+ XBT_INFO("This line will never get displayed: I'm already dead since the previous line.");
+}
+
+int main(int argc, char* argv[])
+{
+ simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
+ xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
+
+ e->loadPlatform(argv[1]); /* - Load the platform description */
+ /* - Create and deploy killer process, that will create the victim process */
+ simgrid::s4u::Actor::createActor("killer", simgrid::s4u::Host::by_name("Tremblay"), killer);
+
+ e->run(); /* - Run the simulation */
+
+ XBT_INFO("Simulation time %g", e->getClock());
+ return 0;
+}
--- /dev/null
+#! ./tesh
+
+$ $SG_TEST_EXENV ${bindir:=.}/s4u_actor-kill ${srcdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [ 0.000000] (killer@Tremblay) Hello!
+> [ 0.000000] (victim@Fafard) Hello!
+> [ 0.000000] (victim@Fafard) Suspending myself
+> [ 10.000000] (killer@Tremblay) Resume process
+> [ 10.000000] (killer@Tremblay) Kill process
+> [ 10.000000] (killer@Tremblay) OK, goodbye now. I commit a suicide.
+> [ 10.000000] (maestro@) Simulation time 10
--- /dev/null
+/* Copyright (c) 2017. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <simgrid/s4u.hpp>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_suspend, "Messages specific for this s4u example");
+
+/* The Lazy guy only wants to sleep, but can be awaken by the dream_master process. */
+static void lazy_guy()
+{
+ XBT_INFO("Nobody's watching me ? Let's go to sleep.");
+ simgrid::s4u::this_actor::suspend(); /* - Start by suspending itself */
+ XBT_INFO("Uuuh ? Did somebody call me ?");
+
+ XBT_INFO("Going to sleep..."); /* - Then repetitively go to sleep, but got awaken */
+ simgrid::s4u::this_actor::sleep_for(10);
+ XBT_INFO("Mmm... waking up.");
+
+ XBT_INFO("Going to sleep one more time (for 10 sec)...");
+ simgrid::s4u::this_actor::sleep_for(10);
+ XBT_INFO("Waking up once for all!");
+
+ XBT_INFO("Ok, let's do some work, then (for 10 sec on Boivin).");
+ simgrid::s4u::this_actor::execute(980.95e6);
+
+ XBT_INFO("Mmmh, I'm done now. Goodbye.");
+}
+
+/* The Dream master: */
+static void dream_master()
+{
+ XBT_INFO("Let's create a lazy guy."); /* - Create a lazy_guy process */
+ simgrid::s4u::ActorPtr lazy = simgrid::s4u::Actor::createActor("Lazy", simgrid::s4u::this_actor::host(), lazy_guy);
+ XBT_INFO("Let's wait a little bit...");
+ simgrid::s4u::this_actor::sleep_for(10); /* - Wait for 10 seconds */
+ XBT_INFO("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!");
+ lazy->resume(); /* - Then wake up the lazy_guy */
+
+ simgrid::s4u::this_actor::sleep_for(5); /* Repeat two times: */
+ XBT_INFO("Suspend the lazy guy while he's sleeping...");
+ lazy->suspend(); /* - Suspend the lazy_guy while he's asleep */
+ XBT_INFO("Let him finish his siesta.");
+ simgrid::s4u::this_actor::sleep_for(10); /* - Wait for 10 seconds */
+ XBT_INFO("Wake up, lazy guy!");
+ lazy->resume(); /* - Then wake up the lazy_guy again */
+
+ simgrid::s4u::this_actor::sleep_for(5);
+ XBT_INFO("Suspend again the lazy guy while he's sleeping...");
+ lazy->suspend();
+ XBT_INFO("This time, don't let him finish his siesta.");
+ simgrid::s4u::this_actor::sleep_for(2);
+ XBT_INFO("Wake up, lazy guy!");
+ lazy->resume();
+
+ simgrid::s4u::this_actor::sleep_for(5);
+ XBT_INFO("Give a 2 seconds break to the lazy guy while he's working...");
+ lazy->suspend();
+ simgrid::s4u::this_actor::sleep_for(2);
+ XBT_INFO("Back to work, lazy guy!");
+ lazy->resume();
+
+ XBT_INFO("OK, I'm done here.");
+}
+
+int main(int argc, char* argv[])
+{
+ simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
+ xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
+
+ e->loadPlatform(argv[1]); /* - Load the platform description */
+ std::vector<simgrid::s4u::Host*> list;
+ e->hostList(&list);
+ simgrid::s4u::Actor::createActor("dream_master", list.front(), dream_master);
+
+ e->run(); /* - Run the simulation */
+
+ return 0;
+}
--- /dev/null
+#! ./tesh
+
+p Testing the suspend/resume feature of MSG
+
+! output sort 19
+$ $SG_TEST_EXENV ${bindir:=.}/s4u_actor-suspend ${srcdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [ 0.000000] (dream_master@Boivin) Let's create a lazy guy.
+> [ 0.000000] (Lazy@Boivin) Nobody's watching me ? Let's go to sleep.
+> [ 0.000000] (dream_master@Boivin) Let's wait a little bit...
+> [ 10.000000] (dream_master@Boivin) Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!
+> [ 10.000000] (Lazy@Boivin) Uuuh ? Did somebody call me ?
+> [ 10.000000] (Lazy@Boivin) Going to sleep...
+> [ 15.000000] (dream_master@Boivin) Suspend the lazy guy while he's sleeping...
+> [ 15.000000] (dream_master@Boivin) Let him finish his siesta.
+> [ 25.000000] (dream_master@Boivin) Wake up, lazy guy!
+> [ 25.000000] (Lazy@Boivin) Mmm... waking up.
+> [ 25.000000] (Lazy@Boivin) Going to sleep one more time (for 10 sec)...
+> [ 30.000000] (dream_master@Boivin) Suspend again the lazy guy while he's sleeping...
+> [ 30.000000] (dream_master@Boivin) This time, don't let him finish his siesta.
+> [ 32.000000] (dream_master@Boivin) Wake up, lazy guy!
+> [ 35.000000] (Lazy@Boivin) Waking up once for all!
+> [ 35.000000] (Lazy@Boivin) Ok, let's do some work, then (for 10 sec on Boivin).
+> [ 37.000000] (dream_master@Boivin) Give a 2 seconds break to the lazy guy while he's working...
+> [ 39.000000] (dream_master@Boivin) Back to work, lazy guy!
+> [ 39.000000] (dream_master@Boivin) OK, I'm done here.
+> [ 47.000000] (Lazy@Boivin) Mmmh, I'm done now. Goodbye.
/** @brief Resume the actor. */
XBT_PUBLIC(void) resume();
+ /** @brief kill the actor. */
+ XBT_PUBLIC(void) kill();
+
/** @brief Migrate the actor to a new host. */
XBT_PUBLIC(void) migrate(Host* new_host);
};
simcall_process_resume(SIMIX_process_self());
}
+void kill()
+{
+ simcall_process_kill(SIMIX_process_self());
+}
+
void migrate(Host* new_host)
{
simcall_process_set_host(SIMIX_process_self(), new_host);
maxminSystem_->solve_fun = specificSolveFun;
}
-
-NetworkCm02Model::~NetworkCm02Model() {}
-
LinkImpl* NetworkCm02Model::createLink(const char* name, double bandwidth, double latency,
e_surf_link_sharing_policy_t policy)
{
public:
NetworkCm02Model();
explicit NetworkCm02Model(void (*solve_fun)(lmm_system_t self));
- virtual ~NetworkCm02Model();
+ virtual ~NetworkCm02Model() = default;
LinkImpl* createLink(const char* name, double bandwidth, double latency,
e_surf_link_sharing_policy_t policy) override;
void updateActionsStateLazy(double now, double delta) override;
{
maxminSystem_ = sys;
}
-CpuL07Model::~CpuL07Model() = default;
NetworkL07Model::NetworkL07Model(HostL07Model *hmodel, lmm_system_t sys)
: NetworkModel()
maxminSystem_ = sys;
loopback_ = createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE);
}
-NetworkL07Model::~NetworkL07Model() = default;
-
double HostL07Model::nextOccuringEvent(double now)
{
double latency = 0.0;
this->hostList_->reserve(host_nb);
- for (int i = 0; i<host_nb; i++)
+ for (int i = 0; i < host_nb; i++) {
this->hostList_->push_back(host_list[i]);
+ if (flops_amount[i] > 0)
+ nb_used_host++;
+ }
/* Compute the number of affected resources... */
if(bytes_amount != nullptr) {
nb_link = affected_links.size();
}
- for (int i = 0; i < host_nb; i++)
- if (flops_amount[i] > 0)
- nb_used_host++;
-
XBT_DEBUG("Creating a parallel task (%p) with %d hosts and %d unique links.", this, host_nb, nb_link);
this->latency_ = latency;
class CpuL07Model : public CpuModel {
public:
CpuL07Model(HostL07Model *hmodel,lmm_system_t sys);
- ~CpuL07Model();
+ ~CpuL07Model() = default;
Cpu *createCpu(simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core) override;
HostL07Model *hostModel_;
class NetworkL07Model : public NetworkModel {
public:
NetworkL07Model(HostL07Model *hmodel, lmm_system_t sys);
- ~NetworkL07Model();
+ ~NetworkL07Model() = default;
LinkImpl* createLink(const char* name, double bandwidth, double latency,
e_surf_link_sharing_policy_t policy) override;