Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / models / ptask-subflows / ptask-subflows.cpp
1 /* Copyright (c) 2007-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 namespace sg4 = simgrid::s4u;
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(ptask_subflows_test, "Messages specific for this s4u example");
11
12 static void ptask(sg4::Host* recv, sg4::Host* sender)
13 {
14   XBT_INFO("TEST: 1 parallel task with 2 flows");
15   XBT_INFO("Parallel task sends 1.5B to other host.");
16   XBT_INFO("Same result for L07 and BMF since the ptask is alone.");
17   XBT_INFO("Should be done in 2.5 seconds: 1s latency and 1.5 second for transfer");
18
19   double start_time = sg4::Engine::get_clock();
20   sg4::Exec::init()
21       ->set_bytes_amounts(std::vector<double>({0.0, 0.0, 1.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0}))
22       ->set_hosts(std::vector<sg4::Host*>({sender, sender, recv}))
23       ->wait();
24   double end_time = sg4::Engine::get_clock();
25   XBT_INFO("Parallel task finished after %lf seconds", end_time - start_time);
26
27   XBT_INFO("TEST: Same parallel task but with a noisy communication at the side");
28   XBT_INFO("Parallel task sends 1.5B to other host.");
29   XBT_INFO("With BMF: Should be done in 3.5 seconds: 1s latency and 2 second for transfer.");
30   XBT_INFO("With L07: Should be done in 4 seconds: 1s latency and 3 second for transfer.");
31   XBT_INFO("With BMF, ptask gets 50%% more bandwidth than the noisy flow (because of the sub).");
32   start_time = sg4::Engine::get_clock();
33   auto noisy = sg4::Comm::sendto_async(sender, recv, 10);
34   sg4::Exec::init()
35       ->set_bytes_amounts(std::vector<double>({0.0, 0.0, 1.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0}))
36       ->set_hosts(std::vector<sg4::Host*>({sender, sender, recv}))
37       ->wait();
38   end_time = sg4::Engine::get_clock();
39   XBT_INFO("Parallel task finished after %lf seconds", end_time - start_time);
40   noisy->wait(); // gracefully wait the noisy flow
41 }
42
43 int main(int argc, char* argv[])
44 {
45   sg4::Engine e(&argc, argv);
46
47   auto* rootzone = sg4::create_full_zone("root");
48   auto* hostA    = rootzone->create_host("hostA", 1e9);
49   auto* hostB    = rootzone->create_host("hostB", 1e9);
50   auto* backb    = rootzone->create_link("backbone", "1")->set_latency("1s")->seal();
51   rootzone->add_route(hostA, hostB, {backb});
52   rootzone->seal();
53
54   sg4::Actor::create("ptask", hostA, ptask, hostA, hostB);
55
56   e.run();
57
58   return 0;
59 }