1 /* Copyright (c) 2017-2022. 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(io_stream, "Messages specific for this simulation");
12 static void streamer(size_t size)
14 auto* bob = sg4::Host::by_name("bob");
15 auto* bob_disk = bob->get_disks().front();
16 auto* alice = sg4::Host::by_name("alice");
17 auto* alice_disk = alice->get_disks().front();
18 double clock = sg4::Engine::get_clock();
20 XBT_INFO("[Bob -> Alice] Store and Forward (1 block)");
22 XBT_INFO(" Read : %.6f seconds", sg4::Engine::get_clock() - clock);
23 clock = sg4::Engine::get_clock();
24 sg4::Comm::sendto(bob, alice, size);
25 XBT_INFO(" Send : %.6f seconds", sg4::Engine::get_clock() - clock);
26 clock = sg4::Engine::get_clock();
27 alice_disk->write(size);
28 XBT_INFO(" Write : %.6f seconds", sg4::Engine::get_clock() - clock);
29 XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock());
31 XBT_INFO("[Bob -> Alice] Store and Forward (100 blocks)");
32 sg4::IoPtr read = bob_disk->read_async(size/100.0);
33 sg4::CommPtr transfer = sg4::Comm::sendto_async(bob, alice, size/100.0);
34 sg4::IoPtr write = alice_disk->write_async(size/100.);
36 clock = sg4::Engine::get_clock();
38 for (int i = 0; i < 99; i++){
40 read = bob_disk->read_async(size/100.0);
42 transfer = sg4::Comm::sendto_async(bob, alice, size/100.0);
44 write = alice_disk->write_async(size/100.);
50 XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock() - clock);
52 XBT_INFO("[Bob -> Alice] Streaming (Read bottleneck)");
53 clock = sg4::Engine::get_clock();
54 sg4::Io::streamto(bob, bob_disk, alice, alice_disk, size);
55 XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock() - clock);
57 XBT_INFO("[Bob -> Alice] Streaming (Write bottleneck)");
58 clock = sg4::Engine::get_clock();
59 sg4::Io::streamto(alice, alice_disk, bob, bob_disk, size);
60 XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock() - clock);
62 XBT_INFO("Start two 10-second background traffic between Bob and Alice");
63 sg4::CommPtr bt1 = sg4::Comm::sendto_async(bob, alice, 2e7);
64 sg4::CommPtr bt2 = sg4::Comm::sendto_async(bob, alice, 2e7);
65 XBT_INFO("[Bob -> Alice] Streaming (Transfer bottleneck)");
66 clock = sg4::Engine::get_clock();
67 sg4::Io::streamto(bob, bob_disk, alice, alice_disk, size);
68 XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock() - clock);
72 XBT_INFO("[Bob -> Alice] Streaming \"from disk to memory\" (no write)");
73 clock = sg4::Engine::get_clock();
74 sg4::Io::streamto(bob, bob_disk, alice, nullptr, size);
75 XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock() - clock);
77 XBT_INFO("[Bob -> Alice] Streaming \"from memory to disk\" (no read)");
78 clock = sg4::Engine::get_clock();
79 sg4::Io::streamto(bob, nullptr, alice, alice_disk, size);
80 XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock() - clock);
82 XBT_INFO("[Bob -> Bob] Disk to disk (no transfer)");
83 clock = sg4::Engine::get_clock();
84 sg4::Io::streamto(bob, bob_disk, bob, bob_disk, size);
85 XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock() - clock);
89 int main(int argc, char** argv)
91 sg4::Engine e(&argc, argv);
93 /* simple platform containing 2 hosts and 2 disks */
94 auto* zone = sg4::create_full_zone("");
95 auto* bob = zone->create_host("bob", 1e6);
96 auto* alice = zone->create_host("alice", 1e6);
98 sg4::LinkInRoute link(zone->create_link("link", "2MBps")->set_latency("50us")->seal());
99 zone->add_route(bob->get_netpoint(), alice->get_netpoint(), nullptr, nullptr, {link}, true);
101 bob->create_disk("bob_disk", 1e6, 5e5);
102 alice->create_disk("alice_disk", 4e6, 4e6);
106 sg4::Actor::create("streamer", bob, streamer, 4e6);