Logo AND Algorithmique Numérique Distribuée

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