Logo AND Algorithmique Numérique Distribuée

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