Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / teshsuite / s4u / cloud-two-execs / cloud-two-execs.cpp
1 /* Copyright (c) 2014-2021. 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 msg example");
9
10 simgrid::s4u::ExecPtr exec;
11
12 static void computation_fun()
13 {
14   const char* pr_name   = simgrid::s4u::this_actor::get_cname();
15   const char* host_name = simgrid::s4u::Host::current()->get_cname();
16   double clock_sta      = simgrid::s4u::Engine::get_clock();
17
18   XBT_INFO("%s:%s Exec 1 start %g", host_name, pr_name, clock_sta);
19   exec = simgrid::s4u::this_actor::exec_async(1e9);
20   exec->wait();
21   XBT_INFO("%s:%s Exec 1 complete %g", host_name, pr_name, simgrid::s4u::Engine::get_clock() - clock_sta);
22
23   exec = nullptr;
24
25   simgrid::s4u::this_actor::sleep_for(1);
26
27   clock_sta = simgrid::s4u::Engine::get_clock();
28   XBT_INFO("%s:%s Exec 2 start %g", host_name, pr_name, clock_sta);
29   exec = simgrid::s4u::this_actor::exec_async(1e10);
30   exec->wait();
31   XBT_INFO("%s:%s Exec 2 complete %g", host_name, pr_name, simgrid::s4u::Engine::get_clock() - clock_sta);
32 }
33
34 static void master_main()
35 {
36   auto* pm0 = simgrid::s4u::Host::by_name("Fafard");
37   auto* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
38   vm0->start();
39
40   simgrid::s4u::Actor::create("compute", vm0, computation_fun);
41
42   while (simgrid::s4u::Engine::get_clock() < 100) {
43     if (exec)
44       XBT_INFO("exec remaining duration: %g", exec->get_remaining());
45     simgrid::s4u::this_actor::sleep_for(1);
46   }
47
48   simgrid::s4u::this_actor::sleep_for(10000);
49   vm0->destroy();
50 }
51
52 int main(int argc, char* argv[])
53 {
54   simgrid::s4u::Engine e(&argc, argv);
55
56   e.load_platform(argv[1]);
57
58   simgrid::s4u::Actor::create("master_", simgrid::s4u::Host::by_name("Fafard"), master_main);
59
60   e.run();
61   XBT_INFO("Bye (simulation time %g)", e.get_clock());
62
63   return 0;
64 }