1 /* Copyright (c) 2010-2022. 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 /* This source code simply loads the platform. This is only useful to play
7 * with the tracing module. See the tesh file to see how to generate the
11 #include "simgrid/instr.h"
12 #include "simgrid/s4u.hpp"
15 namespace sg4 = simgrid::s4u;
17 /* The guy we will move from host to host. It move alone and then is moved by policeman back */
18 static void emigrant()
20 auto mailbox = sg4::Mailbox::by_name("master_mailbox");
22 sg4::this_actor::sleep_for(2);
24 while (true) { // I am an eternal emigrant
25 auto destination = mailbox->get_unique<std::string>();
26 if (destination->empty())
27 break; // there is no destination, die
28 sg4::this_actor::set_host(sg4::Host::by_name(*destination));
29 sg4::this_actor::sleep_for(2); // I am tired, have to sleep for 2 seconds
33 static void policeman()
35 // I am the master of emigrant actor,
36 // I tell it where it must emigrate to.
37 auto destinations = {"Tremblay", "Jupiter", "Fafard", "Ginette", "Bourassa", "Fafard", "Tremblay", "Ginette", ""};
38 auto mailbox = sg4::Mailbox::by_name("master_mailbox");
40 for (auto const& destination : destinations) {
41 mailbox->put_init(new std::string(destination), 0)->set_tracing_category("migration_order")->wait();
45 int main(int argc, char* argv[])
47 sg4::Engine e(&argc, argv);
48 xbt_assert(argc > 1, "Usage: %s platform_file\n \tExample: %s small_platform.xml\n", argv[0], argv[0]);
50 e.load_platform(argv[1]);
52 simgrid::instr::declare_tracing_category("migration_order");
54 sg4::Actor::create("emigrant", e.host_by_name("Fafard"), emigrant);
55 sg4::Actor::create("policeman", e.host_by_name("Tremblay"), policeman);