Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / cpp / exec-remote / s4u-exec-remote.cpp
1 /* Copyright (c) 2007-2022. 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_test, "Messages specific for this s4u example");
9
10 static void wizard()
11 {
12   const simgrid::s4u::Host* fafard = simgrid::s4u::Host::by_name("Fafard");
13   simgrid::s4u::Host* ginette = simgrid::s4u::Host::by_name("Ginette");
14   simgrid::s4u::Host* boivin  = simgrid::s4u::Host::by_name("Boivin");
15
16   XBT_INFO("I'm a wizard! I can run an activity on the Ginette host from the Fafard one! Look!");
17   simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(48.492e6);
18   exec->set_host(ginette);
19   exec->start();
20   XBT_INFO("It started. Running 48.492Mf takes exactly one second on Ginette (but not on Fafard).");
21
22   simgrid::s4u::this_actor::sleep_for(0.1);
23   XBT_INFO("Loads in flops/s: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", boivin->get_load(), fafard->get_load(),
24            ginette->get_load());
25
26   exec->wait();
27
28   XBT_INFO("Done!");
29   XBT_INFO("And now, harder. Start a remote activity on Ginette and move it to Boivin after 0.5 sec");
30   exec = simgrid::s4u::this_actor::exec_init(73293500)->set_host(ginette);
31   exec->start();
32
33   simgrid::s4u::this_actor::sleep_for(0.5);
34   XBT_INFO("Loads before the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", boivin->get_load(), fafard->get_load(),
35            ginette->get_load());
36
37   exec->set_host(boivin);
38
39   simgrid::s4u::this_actor::sleep_for(0.1);
40   XBT_INFO("Loads after the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", boivin->get_load(), fafard->get_load(),
41            ginette->get_load());
42
43   exec->wait();
44   XBT_INFO("Done!");
45
46   XBT_INFO("And now, even harder. Start a remote activity on Ginette and turn off the host after 0.5 sec");
47   exec = simgrid::s4u::this_actor::exec_init(48.492e6)->set_host(ginette);
48   exec->start();
49
50   simgrid::s4u::this_actor::sleep_for(0.5);
51   ginette->turn_off();
52   try {
53     exec->wait();
54   } catch (const simgrid::HostFailureException&) {
55     XBT_INFO("Execution failed on %s", ginette->get_cname());
56   }
57   XBT_INFO("Done!");
58 }
59
60 int main(int argc, char* argv[])
61 {
62   simgrid::s4u::Engine e(&argc, argv);
63   e.load_platform(argv[1]);
64   simgrid::s4u::Actor::create("test", e.host_by_name("Fafard"), wizard);
65
66   e.run();
67
68   return 0;
69 }