Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2af13c3825f7c4a79fff88f4fd5792466e9222b6
[simgrid.git] / examples / s4u / exec-monitor / s4u-exec-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::Actor::createActor("compute", simgrid::s4u::Host::by_name("Fafard"), executor);
45
46   while (simgrid::s4u::Engine::getClock() < 100) {
47     if (activity)
48       XBT_INFO("activity remaining duration: %g", activity->getRemains());
49     simgrid::s4u::this_actor::sleep_for(1);
50   }
51
52   simgrid::s4u::this_actor::sleep_for(10000);
53 }
54
55 int main(int argc, char* argv[])
56 {
57   simgrid::s4u::Engine e(&argc, argv);
58   e.loadPlatform(argv[1]); /* - Load the platform description */
59
60   simgrid::s4u::Actor::createActor("master_", simgrid::s4u::Host::by_name("Fafard"), monitor);
61
62   e.run();
63
64   XBT_INFO("Simulation time %g", e.getClock());
65
66   return 0;
67 }