Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sleep activities throw exception on host failure
[simgrid.git] / teshsuite / s4u / actor-migration / actor-migration.cpp
1 /* Copyright (c) 2018. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/s4u.hpp"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_migration, "Messages specific for this s4u example");
9
10 simgrid::s4u::Barrier* barrier;
11 static simgrid::s4u::ActorPtr controlled_process;
12
13 /* The Emigrant process will be moved from host to host. */
14 static void emigrant()
15 {
16   XBT_INFO("I'll look for a new job on another machine ('Boivin') where the grass is greener.");
17   simgrid::s4u::this_actor::migrate(
18       simgrid::s4u::Host::by_name("Boivin")); /* - First, move to another host by myself */
19
20   XBT_INFO("Yeah, found something to do");
21   simgrid::s4u::this_actor::execute(98095000); /* - Execute some work there */
22   simgrid::s4u::this_actor::sleep_for(2);
23   XBT_INFO("Moving back home after work");
24   simgrid::s4u::this_actor::migrate(simgrid::s4u::Host::by_name("Jacquelin")); /* - Move back to original location */
25   simgrid::s4u::this_actor::migrate(simgrid::s4u::Host::by_name("Boivin"));    /* - Go back to the other host to sleep*/
26   simgrid::s4u::this_actor::sleep_for(4);
27   controlled_process = simgrid::s4u::Actor::self(); /* - Get controlled at checkpoint */
28   barrier->wait();
29   simgrid::s4u::this_actor::suspend();
30   simgrid::s4u::Host* h = simgrid::s4u::this_actor::get_host();
31   XBT_INFO("I've been moved on this new host: %s", h->get_cname());
32   XBT_INFO("Uh, nothing to do here. Stopping now");
33 }
34
35 /* The policeman check for emigrants and move them back to 'Jacquelin' */
36 static void policeman()
37 {
38   XBT_INFO("Wait at the checkpoint."); /* - block on the mutex+condition */
39   barrier->wait();
40   controlled_process->migrate(simgrid::s4u::Host::by_name("Jacquelin")); /* - Move an emigrant to Jacquelin */
41   XBT_INFO("I moved the emigrant");
42   controlled_process->resume();
43 }
44
45 int main(int argc, char* argv[])
46 {
47   simgrid::s4u::Engine e(&argc, argv);
48   e.load_platform(argv[1]);
49
50   simgrid::s4u::Actor::create("emigrant", simgrid::s4u::Host::by_name("Jacquelin"), emigrant);
51   simgrid::s4u::Actor::create("policeman", simgrid::s4u::Host::by_name("Boivin"), policeman);
52
53   barrier = new simgrid::s4u::Barrier(2);
54   e.run();
55   XBT_INFO("Simulation time %g", e.get_clock());
56   delete barrier;
57
58   return 0;
59 }