1 /* Copyright (c) 2018-2019. The SimGrid Team. All rights reserved. */
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. */
6 #include "simgrid/s4u.hpp"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_migration, "Messages specific for this s4u example");
10 simgrid::s4u::Barrier* barrier;
11 static simgrid::s4u::ActorPtr controlled_process;
13 /* The Emigrant process will be moved from host to host. */
14 static void emigrant()
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 */
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 */
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");
35 /* The policeman check for emigrants and move them back to 'Jacquelin' */
36 static void policeman()
38 XBT_INFO("Wait at the checkpoint."); /* - block on the mutex+condition */
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();
45 int main(int argc, char* argv[])
47 simgrid::s4u::Engine e(&argc, argv);
48 e.load_platform(argv[1]);
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);
53 barrier = new simgrid::s4u::Barrier(2);
55 XBT_INFO("Simulation time %g", e.get_clock());