Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
15d8cb561e8e6e84bb696aac700afdcdb61c20f4
[simgrid.git] / examples / s4u / cloud-progress-monitor / s4u-cloud-progress-monitor.cpp
1 /* Copyright (c) 2014-2015, 2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "simgrid/s4u.hpp"
8 #include "simgrid/forward.h"
9 #include "simgrid/s4u/VirtualMachine.hpp"
10 #include "simgrid/s4u/forward.hpp"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
13
14 simgrid::s4u::ExecPtr activity;
15
16 static void executor()
17 {
18   const char* actor_name = simgrid::s4u::this_actor::getCname();
19   const char* host_name  = simgrid::s4u::Host::current()->getCname();
20
21   double clock_begin = simgrid::s4u::Engine::getClock();
22   XBT_INFO("%s:%s task 1 created %g", host_name, actor_name, clock_begin);
23   activity = simgrid::s4u::Actor::self()->exec_async(1e9);
24   activity->wait();
25   double clock_end = simgrid::s4u::Engine::getClock();
26
27   XBT_INFO("%s:%s task 1 executed %g", host_name, actor_name, clock_end - clock_begin);
28
29   activity = nullptr;
30
31   simgrid::s4u::this_actor::sleep_for(1);
32
33   clock_begin = simgrid::s4u::Engine::getClock();
34   XBT_INFO("%s:%s task 2 created %g", host_name, actor_name, clock_begin);
35   activity = simgrid::s4u::Actor::self()->exec_async(1e10);
36   activity->wait();
37   clock_end = simgrid::s4u::Engine::getClock();
38
39   XBT_INFO("%s:%s task 2 executed %g", host_name, actor_name, clock_end - clock_begin);
40 }
41
42 static void monitor()
43 {
44   simgrid::s4u::Host* pm0           = simgrid::s4u::Host::by_name("Fafard");
45   simgrid::s4u::VirtualMachine* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
46   vm0->start();
47
48   simgrid::s4u::Actor::createActor("compute", vm0, executor);
49
50   while (simgrid::s4u::Engine::getClock() < 100) {
51     if (activity)
52       XBT_INFO("activity remaining duration: %g", activity->getRemains());
53     simgrid::s4u::this_actor::sleep_for(1);
54   }
55
56   simgrid::s4u::this_actor::sleep_for(10000);
57   vm0->destroy();
58 }
59
60 int main(int argc, char* argv[])
61 {
62   simgrid::s4u::Engine e(&argc, argv);
63   e.loadPlatform(argv[1]); /* - Load the platform description */
64
65   simgrid::s4u::Actor::createActor("master_", simgrid::s4u::Host::by_name("Fafard"), monitor);
66
67   e.run();
68
69   XBT_INFO("Simulation time %g", e.getClock());
70
71   return 0;
72 }