X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/fcb729916269f63a4c9d031d5be35aff3774e769..b58b0ba2f6b92efa234677e19dd998346113504d:/examples/cpp/io-degradation/s4u-io-degradation.cpp diff --git a/examples/cpp/io-degradation/s4u-io-degradation.cpp b/examples/cpp/io-degradation/s4u-io-degradation.cpp index 834872a748..9ab897a285 100644 --- a/examples/cpp/io-degradation/s4u-io-degradation.cpp +++ b/examples/cpp/io-degradation/s4u-io-degradation.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2017-2023. 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. */ @@ -16,12 +16,11 @@ #include -namespace sg4 = simgrid::s4u; - XBT_LOG_NEW_DEFAULT_CATEGORY(disk_test, "Messages specific for this simulation"); +namespace sg4 = simgrid::s4u; /** @brief Calculates the bandwidth for disk doing async operations */ -static void estimate_bw(sg4::Disk* disk, int n_flows, bool read) +static void estimate_bw(const sg4::Disk* disk, int n_flows, bool read) { unsigned long long size = 100000; double cur_time = sg4::Engine::get_clock(); @@ -36,11 +35,11 @@ static void estimate_bw(sg4::Disk* disk, int n_flows, bool read) activities.push_back(act); } - for (auto& act : activities) + for (const auto& act : activities) act->wait(); double elapsed_time = sg4::Engine::get_clock() - cur_time; - double estimated_bw = size * n_flows / elapsed_time; + double estimated_bw = static_cast(size * n_flows) / elapsed_time; XBT_INFO("Disk: %s, concurrent %s: %d, estimated bandwidth: %lf", disk->get_cname(), read ? "read" : "write", n_flows, estimated_bw); } @@ -49,7 +48,7 @@ static void host() { /* - Estimating bw for each disk and considering concurrent flows */ for (int n = 1; n < 15; n += 2) { - for (auto* disk : sg4::Host::current()->get_disks()) { + for (const auto* disk : sg4::Host::current()->get_disks()) { estimate_bw(disk, n, true); estimate_bw(disk, n, false); } @@ -89,13 +88,9 @@ static double ssd_dynamic_sharing(const sg4::Disk* /*disk*/, const std::string& {15, 239.}}}}; const auto& data = SSD_SPEED.at(op); + const auto value = data.find(n); /* no special bandwidth for this disk sharing N flows, just returns maximal capacity */ - if (data.find(n) != data.end()) - capacity = data.at(n); - - // XBT_INFO("Disk %s, %s operation between %d flows, capacity %lf", disk->get_cname(), op.c_str(), n, capacity); - - return capacity; + return value == data.end() ? capacity : value->second; } /** @@ -107,12 +102,9 @@ static double ssd_dynamic_sharing(const sg4::Disk* /*disk*/, const std::string& * @param capacity Resource current capacity in SimGrid * @param n Number of activities sharing this resource */ -static double sata_dynamic_sharing(const sg4::Disk* /*disk*/, double capacity, int n) +static double sata_dynamic_sharing(const sg4::Disk* /*disk*/, double /*capacity*/, int n) { - capacity = 68.3 - 1.7 * n; - // XBT_INFO("Disk %s, read operation between %d flows, capacity %lf", disk->get_cname(), n, capacity); - - return capacity; + return 68.3 - 1.7 * n; } /** @brief Creates an SSD disk, setting the appropriate callback for non-linear resource sharing */ @@ -148,10 +140,10 @@ int main(int argc, char** argv) create_sata_disk(bob, "Griffon (SATA II)"); zone->seal(); - simgrid::s4u::Actor::create("", bob, host); + sg4::Actor::create("", bob, host); e.run(); - XBT_INFO("Simulated time: %g", simgrid::s4u::Engine::get_clock()); + XBT_INFO("Simulated time: %g", sg4::Engine::get_clock()); return 0; }