1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved. */
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. */
6 #include <simgrid/s4u.hpp>
8 namespace sg4 = simgrid::s4u;
10 XBT_LOG_NEW_DEFAULT_CATEGORY(ptask_subflows_test, "Messages specific for this s4u example");
12 static void ptask(sg4::Host* recv, sg4::Host* sender)
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");
19 double start_time = sg4::Engine::get_clock();
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}))
24 double end_time = sg4::Engine::get_clock();
25 XBT_INFO("Parallel task finished after %lf seconds", end_time - start_time);
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);
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}))
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
43 int main(int argc, char* argv[])
45 sg4::Engine e(&argc, argv);
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 sg4::LinkInRoute link(rootzone->create_link("backbone", "1")->set_latency("1s")->seal());
51 rootzone->add_route(hostA->get_netpoint(), hostB->get_netpoint(), nullptr, nullptr, {link}, true);
54 sg4::Actor::create("ptask", hostA, ptask, hostA, hostB);