Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / cpp / exec-ptask-multicore-latency / s4u-exec-ptask-multicore-latency.cpp
1 /* Copyright (c) 2017-2022. 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_ptask_multicore, "Messages specific for this s4u example");
9
10 namespace sg4 = simgrid::s4u;
11
12 static void runner()
13 {
14   auto e = sg4::Engine::get_instance();
15   std::vector<double> comp(2, 1e9);
16   std::vector<double> comm(4, 0.0);
17   // Different hosts.
18   std::vector<sg4::Host*> hosts_diff = {e->host_by_name("MyHost1"), e->host_by_name("MyHost2")};
19   double start_time                  = sg4::Engine::get_clock();
20   sg4::this_actor::parallel_execute(hosts_diff, comp, comm);
21   XBT_INFO("Computed 2-core activity on two different hosts. Took %g s", e->get_clock() - start_time);
22
23   // Same host, multicore.
24   std::vector<sg4::Host*> multicore_host = {e->host_by_name("MyHost1"), e->host_by_name("MyHost1")};
25   start_time                             = sg4::Engine::get_clock();
26   sg4::this_actor::parallel_execute(multicore_host, comp, comm);
27   XBT_INFO("Computed 2-core activity on one 4-core host. Took %g s", e->get_clock() - start_time);
28
29   // Same host, using too many cores
30   std::vector<double> comp6(6, 1e9);
31   std::vector<double> comm6(36, 0.0);
32   std::vector<sg4::Host*> multicore_overload(6, e->host_by_name("MyHost1"));
33   start_time = sg4::Engine::get_clock();
34   sg4::this_actor::parallel_execute(multicore_overload, comp6, comm6);
35   XBT_INFO("Computed 6-core activity on a 4-core host. Took %g s", e->get_clock() - start_time);
36
37   // Same host, adding some communication
38   std::vector<double> comm2 = {0, 1E7, 1E7, 0};
39   start_time = sg4::Engine::get_clock();
40   sg4::this_actor::parallel_execute(multicore_host, comp, comm2);
41   XBT_INFO("Computed 2-core activity on a 4-core host with some communication. Took %g s", e->get_clock() - start_time);
42
43   // See if the multicore execution continues to work after changing pstate
44   XBT_INFO("Switching machine multicore to pstate 1.");
45   e->host_by_name("MyHost1")->set_pstate(1);
46   XBT_INFO("Switching back to pstate 0.");
47   e->host_by_name("MyHost1")->set_pstate(0);
48
49   start_time                             = sg4::Engine::get_clock();
50   sg4::this_actor::parallel_execute(multicore_host, comp, comm);
51   XBT_INFO("Computed 2-core activity on one 4-core host. Took %g s", e->get_clock() - start_time);
52
53   start_time                  = sg4::Engine::get_clock();
54   sg4::this_actor::parallel_execute(hosts_diff, comp, comm);
55   XBT_INFO("Computed 2-core activity on two different hosts. Took %g s", e->get_clock() - start_time);
56 }
57
58 int main(int argc, char* argv[])
59 {
60   sg4::Engine e(&argc, argv);
61
62   xbt_assert(argc == 2, "Usage: %s <platform file>", argv[0]);
63
64   e.load_platform(argv[1]);
65   sg4::Actor::create("test", sg4::Host::by_name("MyHost1"), runner);
66
67   e.run();
68   XBT_INFO("Simulation done.");
69   return 0;
70 }