From f9b9bdeda454d5340b9cdfe06fac8c8bc57f0ad5 Mon Sep 17 00:00:00 2001 From: Fred Suter Date: Fri, 28 Oct 2022 07:38:47 -0400 Subject: [PATCH] add example --- teshsuite/s4u/CMakeLists.txt | 5 +- teshsuite/s4u/io-stream/io-stream.cpp | 86 ++++++++++++++++++++++++++ teshsuite/s4u/io-stream/io-stream.tesh | 5 ++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 teshsuite/s4u/io-stream/io-stream.cpp create mode 100644 teshsuite/s4u/io-stream/io-stream.tesh diff --git a/teshsuite/s4u/CMakeLists.txt b/teshsuite/s4u/CMakeLists.txt index bc7a813c71..57b21fef88 100644 --- a/teshsuite/s4u/CMakeLists.txt +++ b/teshsuite/s4u/CMakeLists.txt @@ -11,7 +11,8 @@ foreach(x actor actor-autorestart actor-suspend monkey-masterworkers monkey-semaphore concurrent_rw dag-incomplete-simulation dependencies - host-on-off host-on-off-actors host-on-off-recv host-multicore-speed-file io-set-bw + host-on-off host-on-off-actors host-on-off-recv host-multicore-speed-file + io-set-bw io-stream basic-link-test basic-parsing-test evaluate-get-route-time evaluate-parse-time is-router storage_client_server listen_async pid trace-integration @@ -39,7 +40,7 @@ set_property(TARGET activity-lifecycle APPEND PROPERTY INCLUDE_DIRECTORIES "${IN ## Add the tests. ## Some need to be run with all factories, some don't need tesh to run foreach(x actor actor-autorestart actor-suspend activity-lifecycle comm-get-sender wait-all-for wait-any-for - cloud-interrupt-migration cloud-two-execs concurrent_rw dag-incomplete-simulation dependencies io-set-bw + cloud-interrupt-migration cloud-two-execs concurrent_rw dag-incomplete-simulation dependencies io-set-bw io-stream vm-live-migration vm-suicide) set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) ADD_TESH_FACTORIES(tesh-s4u-${x} "*" --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh) diff --git a/teshsuite/s4u/io-stream/io-stream.cpp b/teshsuite/s4u/io-stream/io-stream.cpp new file mode 100644 index 0000000000..d9a93dce75 --- /dev/null +++ b/teshsuite/s4u/io-stream/io-stream.cpp @@ -0,0 +1,86 @@ +/* Copyright (c) 2017-2022. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include + +namespace sg4 = simgrid::s4u; + +XBT_LOG_NEW_DEFAULT_CATEGORY(io_stream, "Messages specific for this simulation"); + +static void streamer(size_t size) +{ + auto* bob = sg4::Host::by_name("bob"); + auto* bob_disk = bob->get_disks().front(); + auto* alice = sg4::Host::by_name("alice"); + auto* alice_disk = alice->get_disks().front(); + double clock = sg4::Engine::get_clock(); + + XBT_INFO("[Bob -> Alice] Store and Forward (1 block)"); + bob_disk->read(size); + XBT_INFO(" Read : %.6f seconds", sg4::Engine::get_clock() - clock); + clock = sg4::Engine::get_clock(); + sg4::Comm::sendto(bob, alice, size); + XBT_INFO(" Send : %.6f seconds", sg4::Engine::get_clock() - clock); + clock = sg4::Engine::get_clock(); + alice_disk->write(size); + XBT_INFO(" Write : %.6f seconds", sg4::Engine::get_clock() - clock); + XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock()); + + XBT_INFO("[Bob -> Alice] Store and Forward (100 blocks)"); + sg4::IoPtr read = bob_disk->read_async(size/100.0); + sg4::CommPtr transfer = sg4::Comm::sendto_async(bob, alice, size/100.0); + sg4::IoPtr write = alice_disk->write_async(size/100.); + + clock = sg4::Engine::get_clock(); + + for (int i = 0; i < 99; i++){ + read->wait(); + read = bob_disk->read_async(size/100.0); + transfer->wait(); + transfer = sg4::Comm::sendto_async(bob, alice, size/100.0); + write->wait(); + write = alice_disk->write_async(size/100.); + } + + read->wait(); + transfer->wait(); + write->wait(); + XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock() - clock); + + + XBT_INFO("[Bob -> Alice] Streaming (Read bottleneck)"); + clock = sg4::Engine::get_clock(); + sg4::Io::streamto(bob, bob_disk, alice, alice_disk, size); + XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock() - clock); + + XBT_INFO("[Bob -> Alice] Streaming (Write bottleneck)"); + clock = sg4::Engine::get_clock(); + sg4::Io::streamto(alice, alice_disk, bob, bob_disk, size); + XBT_INFO(" Total : %.6f seconds", sg4::Engine::get_clock() - clock); +} + +int main(int argc, char** argv) +{ + sg4::Engine e(&argc, argv); + + /* simple platform containing 2 hosts and 2 disks */ + auto* zone = sg4::create_full_zone(""); + auto* bob = zone->create_host("bob", 1e6); + auto* alice = zone->create_host("alice", 1e6); + + sg4::LinkInRoute link(zone->create_link("link", "2MBps")->set_latency("50us")->seal()); + zone->add_route(bob->get_netpoint(), alice->get_netpoint(), nullptr, nullptr, {link}, true); + + bob->create_disk("bob_disk", 1e6, 5e5); + alice->create_disk("alice_disk", 4e6, 4e6); + + zone->seal(); + + sg4::Actor::create("streamer", bob, streamer, 4e6); + + e.run(); + + return 0; +} diff --git a/teshsuite/s4u/io-stream/io-stream.tesh b/teshsuite/s4u/io-stream/io-stream.tesh new file mode 100644 index 0000000000..f5a4caa819 --- /dev/null +++ b/teshsuite/s4u/io-stream/io-stream.tesh @@ -0,0 +1,5 @@ +#!/usr/bin/env tesh + +$ ${bindir:=.}/io-stream --cfg=host/model:sio_S22 "--log=root.fmt:[%10.6r]%e[%i:%a@%h]%e%m%n" +> [ 0.000000] [0:maestro@] Configuration change: Set 'host/model' to 'sio_S22' +> [ 0.000000] [0:maestro@] Switching to the S22 model to handle streaming I/Os. \ No newline at end of file -- 2.20.1