Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplify
[simgrid.git] / examples / cpp / exec-ptask-multicore / s4u-exec-ptask-multicore.cpp
1 /* Copyright (c) 2017-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_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("MyHost2"), e->host_by_name("MyHost3")};
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, monocore.
24   std::vector<sg4::Host*> monocore_hosts = {e->host_by_name("MyHost2"), e->host_by_name("MyHost2")};
25   start_time                             = sg4::Engine::get_clock();
26   sg4::this_actor::parallel_execute(monocore_hosts, comp, comm);
27   XBT_INFO("Computed 2-core activity one 1-core host. Took %g s", e->get_clock() - start_time);
28
29   // Same host, multicore.
30   std::vector<sg4::Host*> multicore_host = {e->host_by_name("MyHost1"), e->host_by_name("MyHost1")};
31   start_time                             = sg4::Engine::get_clock();
32   sg4::this_actor::parallel_execute(multicore_host, comp, comm);
33   XBT_INFO("Computed 2-core activity on one 2-core host. Took %g s", e->get_clock() - start_time);
34
35   // Same host, using too many cores
36   std::vector<double> comp6(6, 1e9);
37   std::vector<double> comm6(36, 0.0);
38   std::vector<sg4::Host*> multicore_overload(6, e->host_by_name("MyHost1"));
39   start_time = sg4::Engine::get_clock();
40   sg4::this_actor::parallel_execute(multicore_overload, comp6, comm6);
41   XBT_INFO("Computed 6-core activity of a 4-core host. Took %g s", e->get_clock() - start_time);
42 }
43
44 int main(int argc, char* argv[])
45 {
46   sg4::Engine e(&argc, argv);
47
48   xbt_assert(argc == 2, "Usage: %s <platform file>", argv[0]);
49
50   e.load_platform(argv[1]);
51   sg4::Actor::create("test", sg4::Host::by_name("MyHost1"), runner);
52
53   e.run();
54   XBT_INFO("Simulation done.");
55   return 0;
56 }