Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8e147951be20e36a524a63a23147612b0af20f3d
[simgrid.git] / examples / s4u / exec-remote / s4u-exec-remote.cpp
1 /* Copyright (c) 2007-2017. 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 #include "simgrid/forward.h"
8 #include "simgrid/s4u/forward.hpp"
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
11
12 static void wizard()
13 {
14   simgrid::s4u::Host* fafard  = simgrid::s4u::Host::by_name("Fafard");
15   simgrid::s4u::Host* ginette = simgrid::s4u::Host::by_name("Ginette");
16   simgrid::s4u::Host* boivin  = simgrid::s4u::Host::by_name("Boivin");
17
18   XBT_INFO("I'm a wizard! I can run a task on the Fafard host from the Ginette one! Look!");
19   simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(48.492e6);
20   exec->setHost(ginette);
21   exec->start();
22   XBT_INFO("It started. Running 48.492Mf takes exactly one second on Ginette (but not on Fafard).");
23
24   simgrid::s4u::this_actor::sleep_for(0.1);
25   XBT_INFO("Loads in flops/s: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f",
26       boivin->getLoad(), fafard->getLoad(), ginette->getLoad());
27
28   exec->wait();
29
30   XBT_INFO("Done!");
31   XBT_INFO("And now, harder. Start a remote task on Ginette and move it to Boivin after 0.5 sec");
32   exec = simgrid::s4u::this_actor::exec_init(73293500)->setHost(ginette);
33   exec->start();
34
35   simgrid::s4u::this_actor::sleep_for(0.5);
36   XBT_INFO("Loads before the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f",
37       boivin->getLoad(), fafard->getLoad(), ginette->getLoad());
38
39   exec->setHost(boivin);
40
41   simgrid::s4u::this_actor::sleep_for(0.1);
42   XBT_INFO("Loads after the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f",
43       boivin->getLoad(), fafard->getLoad(), ginette->getLoad());
44
45   exec->wait();
46   XBT_INFO("Done!");
47 }
48
49 int main(int argc, char* argv[])
50 {
51   simgrid::s4u::Engine e(&argc, argv);
52   e.loadPlatform(argv[1]);
53   simgrid::s4u::Actor::createActor("test", simgrid::s4u::Host::by_name("Fafard"), wizard);
54
55   e.run();
56
57   return 0;
58 }