From 05eead638cfd02a6d5a218939e226eb1700fd8a5 Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Thu, 15 Apr 2021 14:42:50 +0200 Subject: [PATCH] Change C++ platform example Remove small_platform.cpp. Add a more programmatic platform using the StarZone. --- MANIFEST.in | 2 +- .../cpp/actor-create/s4u-actor-create.cpp | 14 +- .../cpp/actor-create/s4u-actor-create.tesh | 14 +- .../app-token-ring/s4u-app-token-ring.tesh | 16 +++ examples/platforms/CMakeLists.txt | 2 +- examples/platforms/routing_cluster.cpp | 87 ++++++++++++ examples/platforms/small_platform.cpp | 134 ------------------ tools/cmake/DefinePackages.cmake | 2 +- 8 files changed, 113 insertions(+), 158 deletions(-) create mode 100644 examples/platforms/routing_cluster.cpp delete mode 100644 examples/platforms/small_platform.cpp diff --git a/MANIFEST.in b/MANIFEST.in index 0963f6a420..609b4a722a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1920,11 +1920,11 @@ include examples/platforms/profiles/trace_A_failure.txt include examples/platforms/profiles/trace_B.txt include examples/platforms/prop.xml include examples/platforms/ptask_L07.xml +include examples/platforms/routing_cluster.cpp include examples/platforms/routing_cluster.lua include examples/platforms/routing_cluster.xml include examples/platforms/routing_none.xml include examples/platforms/simulacrum_7_hosts.xml -include examples/platforms/small_platform.cpp include examples/platforms/small_platform.lua include examples/platforms/small_platform.xml include examples/platforms/small_platform_constant.xml diff --git a/examples/cpp/actor-create/s4u-actor-create.cpp b/examples/cpp/actor-create/s4u-actor-create.cpp index 3373d82a03..1875ae36ef 100644 --- a/examples/cpp/actor-create/s4u-actor-create.cpp +++ b/examples/cpp/actor-create/s4u-actor-create.cpp @@ -45,9 +45,9 @@ static void receiver(const std::string& mailbox_name) static void forwarder(int argc, char** argv) { xbt_assert(argc >= 3, "Actor forwarder requires 2 parameters, but got only %d", argc - 1); - sg4::Mailbox* in = sg4::Mailbox::by_name(argv[1]); - sg4::Mailbox* out = sg4::Mailbox::by_name(argv[2]); - auto* msg = in->get(); + sg4::Mailbox* in = sg4::Mailbox::by_name(argv[1]); + sg4::Mailbox* out = sg4::Mailbox::by_name(argv[2]); + auto* msg = in->get(); XBT_INFO("Forward '%s'.", msg->c_str()); out->put(msg, msg->size()); } @@ -60,11 +60,9 @@ static void forwarder(int argc, char** argv) class Sender { public: std::string mbox = "mb42"; - std::string msg = "GaBuZoMeu"; + std::string msg = "GaBuZoMeu"; explicit Sender() = default; /* Sending the default message */ - explicit Sender(const std::string& arg) : msg(arg) - { /* Sending the specified message */ - } + explicit Sender(const std::string& arg) : msg(arg) { /* Sending the specified message */} explicit Sender(std::vector args) { /* This constructor is used when we start the actor from the deployment file */ @@ -92,7 +90,7 @@ int main(int argc, char** argv) sg4::Engine e(&argc, argv); /* Then you should load a platform file, describing your simulated platform */ - e.load_platform(argv[1]); + e.load_platform("../../platforms/small_platform.xml"); /* And now you have to ask SimGrid to actually start your actors. * diff --git a/examples/cpp/actor-create/s4u-actor-create.tesh b/examples/cpp/actor-create/s4u-actor-create.tesh index 4849e12d0e..994a3f95d2 100644 --- a/examples/cpp/actor-create/s4u-actor-create.tesh +++ b/examples/cpp/actor-create/s4u-actor-create.tesh @@ -1,18 +1,6 @@ #!/usr/bin/env tesh -$ ${bindir:=.}/s4u-actor-create ../../platforms/small_platform.xml -> [Tremblay:sender1:(2) 0.000000] [s4u_actor_create/INFO] Hello s4u, I have something to send -> [Jupiter:sender2:(3) 0.000000] [s4u_actor_create/INFO] Hello s4u, I have something to send -> [Fafard:sender:(4) 0.000000] [s4u_actor_create/INFO] Hello s4u, I have something to send -> [Fafard:receiver:(1) 0.000000] [s4u_actor_create/INFO] Hello s4u, I'm ready to get any message you'd want on mb42 -> [Fafard:sender:(4) 0.016392] [s4u_actor_create/INFO] I'm done. See you. -> [Ginette:forwarder:(5) 0.016392] [s4u_actor_create/INFO] Forward 'PopPop!'. -> [Tremblay:sender1:(2) 0.025709] [s4u_actor_create/INFO] I'm done. See you. -> [Jupiter:sender2:(3) 0.070434] [s4u_actor_create/INFO] I'm done. See you. -> [Fafard:receiver:(1) 0.086825] [s4u_actor_create/INFO] I received 'GaBuZoMeu', 'GloubiBoulga' and 'PopPop!' -> [Fafard:receiver:(1) 0.086825] [s4u_actor_create/INFO] I'm done. See you. - -$ ${bindir:=.}/s4u-actor-create ${libdir:=.}/libsmall_platform.so +$ ${bindir:=.}/s4u-actor-create > [Tremblay:sender1:(2) 0.000000] [s4u_actor_create/INFO] Hello s4u, I have something to send > [Jupiter:sender2:(3) 0.000000] [s4u_actor_create/INFO] Hello s4u, I have something to send > [Fafard:sender:(4) 0.000000] [s4u_actor_create/INFO] Hello s4u, I have something to send diff --git a/examples/cpp/app-token-ring/s4u-app-token-ring.tesh b/examples/cpp/app-token-ring/s4u-app-token-ring.tesh index 76fb5f8e46..56d7535da2 100644 --- a/examples/cpp/app-token-ring/s4u-app-token-ring.tesh +++ b/examples/cpp/app-token-ring/s4u-app-token-ring.tesh @@ -16,6 +16,22 @@ $ ${bindir:=.}/s4u-app-token-ring ${platfdir}/routing_cluster.xml "--log=root.fm > [ 0.131796] (0@host1) Host "0" received "Token" > [ 0.131796] (maestro@) Simulation time 0.131796 +$ ${bindir:=.}/s4u-app-token-ring ${libdir}/librouting_cluster.so "--log=root.fmt:[%10.6r]%e(%a@%h)%e%m%n" +> [ 0.000000] (maestro@) Number of hosts '6' +> [ 0.000000] (0@host1) Host "0" send 'Token' to Host "1" +> [ 0.017354] (1@host2) Host "1" received "Token" +> [ 0.017354] (1@host2) Host "1" send 'Token' to Host "2" +> [ 0.035121] (2@host3) Host "2" received "Token" +> [ 0.035121] (2@host3) Host "2" send 'Token' to Host "3" +> [ 0.065898] (3@host4) Host "3" received "Token" +> [ 0.065898] (3@host4) Host "3" send 'Token' to Host "4" +> [ 0.083252] (4@host5) Host "4" received "Token" +> [ 0.083252] (4@host5) Host "4" send 'Token' to Host "5" +> [ 0.101019] (5@host6) Host "5" received "Token" +> [ 0.101019] (5@host6) Host "5" send 'Token' to Host "0" +> [ 0.131796] (0@host1) Host "0" received "Token" +> [ 0.131796] (maestro@) Simulation time 0.131796 + $ ${bindir:=.}/s4u-app-token-ring ${platfdir}/two_peers.xml "--log=root.fmt:[%12.6r]%e(%a@%h)%e%m%n" > [ 0.000000] (maestro@) Number of hosts '2' > [ 0.000000] (0@100030591) Host "0" send 'Token' to Host "1" diff --git a/examples/platforms/CMakeLists.txt b/examples/platforms/CMakeLists.txt index ab567db16d..70bb080001 100644 --- a/examples/platforms/CMakeLists.txt +++ b/examples/platforms/CMakeLists.txt @@ -1,6 +1,6 @@ add_custom_target(platf_cpp COMMENT "C++ platform description") add_dependencies(tests platf_cpp) -foreach (platf small_platform) +foreach (platf routing_cluster) add_library (${platf} SHARED ${platf}.cpp) target_link_libraries(${platf} simgrid) add_dependencies(platf_cpp ${platf}) diff --git a/examples/platforms/routing_cluster.cpp b/examples/platforms/routing_cluster.cpp new file mode 100644 index 0000000000..364d76ed1f --- /dev/null +++ b/examples/platforms/routing_cluster.cpp @@ -0,0 +1,87 @@ +/* Copyright (c) 2006-2021. 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; + +/** + * @brief Create a new cluster netzone inside the root netzone + * + * This function creates the cluster, adding the hosts and links properly. + * + * @param root Root netzone + * @param cluster_suffix ID of the cluster being created + * @param host List of hostname inside the cluster + * @param single_link_host Hostname of "special" node + */ +static void create_cluster(sg4::NetZone* root, const std::string& cluster_suffix, const std::vector& hosts, + const std::string& single_link_host) +{ + auto* cluster = sg4::create_star_zone("cluster" + cluster_suffix); + cluster->set_parent(root); + + /* create the backbone link */ + sg4::Link* l_bb = + cluster->create_link("backbone" + cluster_suffix, std::vector{2.25e9})->set_latency(5e-4)->seal(); + + /* create all hosts and connect them to outside world */ + for (const auto& hostname : hosts) { + /* create host */ + sg4::Host* host = cluster->create_host(hostname, std::vector{1e9}); + /* create UP link */ + sg4::Link* l_up = cluster->create_link(hostname + "_up", std::vector{1.25e8})->set_latency(0.0001)->seal(); + /* create DOWN link, if needed */ + sg4::Link* l_down = l_up; + if (hostname != single_link_host) { + l_down = cluster->create_link(hostname + "_down", std::vector{1.25e8})->set_latency(0.0001)->seal(); + } + + /* add link UP and backbone for communications from the host */ + cluster->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, std::vector{l_up, l_bb}, false); + /* add backbone and link DOWN for communications to the host */ + cluster->add_route(nullptr, host->get_netpoint(), nullptr, nullptr, std::vector{l_bb, l_down}, false); + } + + /* create router */ + cluster->create_router("router" + cluster_suffix); + + cluster->seal(); +} + +/** @brief Programmatic version of routing_cluster.xml */ +extern "C" void load_platform(const sg4::Engine& e); +void load_platform(const sg4::Engine& e) +{ + /** + * + * Target platform: 2 simular but irregular clusters. + * Nodes use full-duplex links to connect to the backbone, except one node that uses a single + * shared link. + + * router1 - - - - - - link1-2 - - - - - - router2 + * __________________________ _________________________ + * | | | | + * | backbone1 | | backbone2 | + * |________________________| |________________________| + * / / | \ \ / / | \ \ + *l1_up / / l1_down | l3 l2_up\ \ l2_down l4_up / / l4_down | l6 l5_up\ \ l5_down + * / / | \ \ / / | \ \ + * host1 host3 host2 host4 host6 host5 + */ + + auto* root = sg4::create_full_zone("AS0"); + + /* create left cluster */ + create_cluster(root, "1", {"host1", "host2", "host3"}, "host3"); + /* create right cluster */ + create_cluster(root, "2", {"host4", "host5", "host6"}, "host6"); + + /* connect both cluster through their respective routers */ + sg4::Link* link = root->create_link("link1-2", std::vector{2.25e9})->set_latency(5e-4)->seal(); + root->add_route(e.netpoint_by_name_or_null("cluster1"), e.netpoint_by_name_or_null("cluster2"), + e.netpoint_by_name_or_null("router1"), e.netpoint_by_name_or_null("router2"), {link}); + + root->seal(); +} \ No newline at end of file diff --git a/examples/platforms/small_platform.cpp b/examples/platforms/small_platform.cpp deleted file mode 100644 index 5496ea42ee..0000000000 --- a/examples/platforms/small_platform.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* Copyright (c) 2006-2021. 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; - -/** - * @brief Create the hosts in the platform - * - * @param zone Zone to insert the hosts - */ -static void create_sp_hosts(sg4::NetZone* zone) -{ - zone->create_host("Tremblay", {"98.095Mf"})->seal(); - zone->create_host("Jupiter", {"76.296Mf"})->seal(); - zone->create_host("Fafard", {"76.296Mf"})->seal(); - zone->create_host("Ginette", {"48.492Mf"})->seal(); - zone->create_host("Bourassa", {"48.492Mf"})->seal(); - zone->create_host("Jacquelin", {"137.333Mf"})->seal(); - zone->create_host("Boivin", {"98.095Mf"})->seal(); -} - -/** - * @brief Create the links in the platform - * - * They'll be used later in the routes. - * - * @param zone Netzone - */ -static void create_sp_links(sg4::NetZone* zone) -{ - zone->create_link("6", {"41.279125MBps"})->set_latency("59.904us")->seal(); - zone->create_link("3", {"34.285625MBps"})->set_latency("514.433us")->seal(); - zone->create_link("7", {"11.618875MBps"})->set_latency("189.98us")->seal(); - zone->create_link("9", {"7.20975MBps"})->set_latency("1.461517ms")->seal(); - zone->create_link("2", {"118.6825MBps"})->set_latency("136.931us")->seal(); - zone->create_link("8", {"8.158MBps"})->set_latency("270.544us")->seal(); - zone->create_link("1", {"34.285625MBps"})->set_latency("514.433us")->seal(); - zone->create_link("4", {"10.099625MBps"})->set_latency("479.78us")->seal(); - zone->create_link("0", {"41.279125MBps"})->set_latency("59.904us")->seal(); - zone->create_link("5", {"27.94625MBps"})->set_latency("278.066us")->seal(); - zone->create_link("145", {"2.583375MBps"})->set_latency("410.463us")->seal(); - zone->create_link("10", {"34.285625MBps"})->set_latency("514.433us")->seal(); - zone->create_link("11", {"118.6825MBps"})->set_latency("136.931us")->seal(); - zone->create_link("16", {"34.285625MBps"})->set_latency("514.433us")->seal(); - zone->create_link("17", {"118.6825MBps"})->set_latency("136.931us")->seal(); - zone->create_link("44", {"10.314625MBps"})->set_latency("6.932556ms")->seal(); - zone->create_link("47", {"10.314625MBps"})->set_latency("6.932556ms")->seal(); - zone->create_link("54", {"15.376875MBps"})->set_latency("35.083019ms")->seal(); - zone->create_link("56", {"21.41475MBps"})->set_latency("29.5890617ms")->seal(); - zone->create_link("59", {"11.845375MBps"})->set_latency("370.788us")->seal(); - zone->create_link("78", {"27.94625MBps"})->set_latency("278.066us")->seal(); - zone->create_link("79", {"8.42725MBps"})->set_latency("156.056us")->seal(); - zone->create_link("80", {"15.376875MBps"})->set_latency("35.083019ms")->seal(); - - /* single FATPIPE links for loopback */ - zone->create_link("loopback", {"498MBps"}) - ->set_latency("15us") - ->set_sharing_policy(sg4::Link::SharingPolicy::FATPIPE) - ->seal(); -} - -/** - * @brief Auxiliary function to create a single route - * - * It translates the parameters from string to proper API - * @param e S4U Engine - * @param src Source hostname - * @param dst Destination hostname - * @param links List of links to use in this route - */ -static void create_single_route(const sg4::Engine& e, std::string const& src, std::string const& dst, - std::vector const& links) -{ - std::vector link_list; - for (auto& link : links) { - link_list.push_back(e.link_by_name(link)); - } - sg4::NetZone* zone = e.get_netzone_root(); - zone->add_route(e.netpoint_by_name(src), e.netpoint_by_name(dst), nullptr, nullptr, link_list); -} - -/** @brief Creates the routes in the platform */ -static void create_sp_routes(const sg4::Engine& e) -{ - auto nodes = std::vector{"Tremblay", "Jupiter", "Fafard", "Ginette", "Bourassa"}; - for (const auto& name : nodes) { - create_single_route(e, name, name, {"loopback"}); - } - create_single_route(e, "Tremblay", "Jupiter", {"9"}); - create_single_route(e, "Tremblay", "Fafard", {"4", "3", "2", "0", "1", "8"}); - create_single_route(e, "Tremblay", "Ginette", {"4", "3", "5"}); - create_single_route(e, "Tremblay", "Bourassa", {"4", "3", "2", "0", "1", "6", "7"}); - create_single_route(e, "Jupiter", "Fafard", {"9", "4", "3", "2", "0", "1", "8"}); - create_single_route(e, "Jupiter", "Bourassa", {"9", "4", "3", "2", "0", "1", "6", "7"}); - create_single_route(e, "Fafard", "Ginette", {"8", "1", "0", "2", "5"}); - create_single_route(e, "Jupiter", "Jacquelin", {"145"}); - create_single_route(e, "Jupiter", "Boivin", {"47"}); - create_single_route(e, "Jupiter", "Ginette", {"9", "4", "3", "5"}); - create_single_route(e, "Fafard", "Bourassa", {"8", "6", "7"}); - create_single_route(e, "Ginette", "Bourassa", {"5", "2", "0", "1", "6", "7"}); - create_single_route(e, "Ginette", "Jacquelin", {"145"}); - create_single_route(e, "Ginette", "Boivin", {"47"}); - create_single_route(e, "Bourassa", "Jacquelin", {"145"}); - create_single_route(e, "Bourassa", "Boivin", {"47"}); - create_single_route(e, "Jacquelin", "Boivin", {"145", "59", "56", "54", "17", "16", "10", "11", "44", "47"}); - create_single_route(e, "Jacquelin", "Fafard", {"145", "59", "56", "54", "17", "16", "10", "6", "9", "79", "78"}); - create_single_route(e, "Jacquelin", "Tremblay", {"145", "59", "56", "54", "2", "3"}); - create_single_route(e, "Boivin", "Tremblay", {"47", "44", "11", "10", "16", "0", "3"}); - create_single_route(e, "Boivin", "Fafard", {"47", "44", "11", "6", "9", "79", "78", "80"}); -} - -/** - * @brief Programmatic version of small_platform.xml - * - * Possible not the best example since we need to describe each component manually, - * but it illustrates the new API - */ -extern "C" void load_platform(const sg4::Engine& e); -void load_platform(const sg4::Engine& e) -{ - auto* root_zone = sg4::create_full_zone("zone0"); - - /* create hosts */ - create_sp_hosts(root_zone); - /* create links */ - create_sp_links(root_zone); - /* create routes */ - create_sp_routes(e); - /* finally seal the root zone */ - root_zone->seal(); -} \ No newline at end of file diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 7785ac51f3..9675b039a9 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -1162,13 +1162,13 @@ set(PLATFORMS_EXAMPLES examples/platforms/prop.xml examples/platforms/routing_cluster.xml examples/platforms/routing_cluster.lua + examples/platforms/routing_cluster.cpp examples/platforms/routing_none.xml examples/platforms/simulacrum_7_hosts.xml examples/platforms/storage/content/small_content.txt examples/platforms/storage/content/storage_content.txt examples/platforms/small_platform.xml examples/platforms/small_platform.lua - examples/platforms/small_platform.cpp examples/platforms/small_platform_constant.xml examples/platforms/small_platform_failures.xml examples/platforms/small_platform_fatpipe.xml -- 2.20.1