From: Bruno Donassolo Date: Fri, 7 May 2021 18:50:57 +0000 (+0200) Subject: ClusterZone placeholder and kill some old code X-Git-Tag: v3.28~296 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/369ab5c3a73cf86420a0c0ad65794fb0c614d137?hp=657a66f7b1356f4d91ae3392f2cd999f0406a60c ClusterZone placeholder and kill some old code Put the old ClusterZone class as a placeholder for other "Cluster" classes. Keep the same behavior of Engine::get_filtered_netzones for wrench projects. The old ClusterZone is now BaseCluster and it's used to implement the "complex" Clusters (Torus, DragonFly and Fat-Tree). Kill old code that doesn't make sense for these netzones --- diff --git a/include/simgrid/kernel/routing/ClusterZone.hpp b/include/simgrid/kernel/routing/ClusterZone.hpp index 29b0076662..3fa1ad1272 100644 --- a/include/simgrid/kernel/routing/ClusterZone.hpp +++ b/include/simgrid/kernel/routing/ClusterZone.hpp @@ -7,6 +7,7 @@ #define SIMGRID_ROUTING_CLUSTER_HPP_ #include +#include #include @@ -14,8 +15,28 @@ namespace simgrid { namespace kernel { namespace routing { -/** @ingroup ROUTING_API - * @brief NetZone where each component is connected through a private link +/** + * @brief Placeholder for old ClusterZone class + * + * The ClusterZone is now implemented through a StarZone. + * + * Leave this class as a placeholder to avoid compatibility issues + * with codes that use the Engine::get_filtered_netzones. + * + * The old ClusterZone is now called BaseCluster and it's used ONLY as base to + * implement the complex cluster such as Torus, DragonFly and Fat-Tree + */ +class ClusterZone : public NetZoneImpl { +protected: + using NetZoneImpl::NetZoneImpl; +}; + +/** + * @brief Old ClusterZone implementation + * + * NOTE: Cannot be directly instantiated anymore. + * + * NetZone where each component is connected through a private link * * Cluster zones have a collection of private links that interconnect their components. * This is particularly well adapted to model a collection of elements interconnected @@ -64,16 +85,15 @@ namespace routing { * limiter(A)_UP, private(A)_UP, backbone * (because the private router is directly connected to the cluster core). */ - -class ClusterZone : public NetZoneImpl { +class XBT_PRIVATE ClusterBase : public ClusterZone { /* We use a map instead of a std::vector here because that's a sparse vector. Some values may not exist */ /* The pair is {link_up, link_down} */ std::unordered_map> private_links_; std::unordered_map gateways_; //!< list of gateways for leafs (if they're netzones) - resource::LinkImpl* backbone_ = nullptr; - NetPoint* router_ = nullptr; - bool has_limiter_ = false; - bool has_loopback_ = false; + resource::LinkImpl* backbone_ = nullptr; + NetPoint* router_ = nullptr; + bool has_limiter_ = false; + bool has_loopback_ = false; unsigned long num_links_per_node_ = 1; /* may be 1 (if only a private link), 2 or 3 (if limiter and loopback) */ s4u::Link::SharingPolicy link_sharing_policy_; //!< cluster links: sharing policy @@ -81,6 +101,7 @@ class ClusterZone : public NetZoneImpl { double link_lat_; //!< cluster links: latency protected: + using ClusterZone::ClusterZone; void set_num_links_per_node(unsigned long num) { num_links_per_node_ = num; } resource::LinkImpl* get_uplink_from(unsigned int position) const { return private_links_.at(position).first; } resource::LinkImpl* get_downlink_to(unsigned int position) const { return private_links_.at(position).second; } @@ -89,11 +110,6 @@ protected: double get_link_bandwidth() const { return link_bw_; } s4u::Link::SharingPolicy get_link_sharing_policy() const { return link_sharing_policy_; } -public: - explicit ClusterZone(const std::string& name); - - /** @brief Set the characteristics of links inside a Cluster zone */ - virtual void set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy); void set_loopback(); bool has_loopback() const { return has_loopback_; } void set_limiter(); @@ -111,22 +127,27 @@ public: return private_links_.find(position) != private_links_.end(); } - void get_local_route(NetPoint* src, NetPoint* dst, Route* into, double* latency) override; void get_graph(const s_xbt_graph_t* graph, std::map>* nodes, - std::map>* edges) override; - - void create_links(int id, int rank); + std::map>* edges) override + { + /* the old and generic implementation of get_graph doesn't make sense for complex clusters */ + THROW_UNIMPLEMENTED; + }; unsigned int node_pos(int id) const { return id * num_links_per_node_; } unsigned int node_pos_with_loopback(int id) const { return node_pos(id) + (has_loopback_ ? 1 : 0); } - unsigned int node_pos_with_loopback_limiter(int id) const - { - return node_pos_with_loopback(id) + (has_limiter_ ? 1 : 0); - } + +public: /** Fill the leaf retriving netpoint from a user's callback */ void fill_leaf_from_cb(unsigned int position, const std::vector& dimensions, const s4u::ClusterCallbacks& set_callbacks, NetPoint** node_netpoint, s4u::Link** lb_link, s4u::Link** limiter_link); + /** @brief Set the characteristics of links inside a Cluster zone */ + virtual void set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy); + unsigned int node_pos_with_loopback_limiter(int id) const + { + return node_pos_with_loopback(id) + (has_limiter_ ? 1 : 0); + } }; } // namespace routing } // namespace kernel diff --git a/include/simgrid/kernel/routing/DragonflyZone.hpp b/include/simgrid/kernel/routing/DragonflyZone.hpp index 70c6e6299e..5e3b0a1491 100644 --- a/include/simgrid/kernel/routing/DragonflyZone.hpp +++ b/include/simgrid/kernel/routing/DragonflyZone.hpp @@ -62,7 +62,7 @@ public: * is also not realistic, as blue level can use more links than a single * Aries can handle, thus it should use several routers. */ -class XBT_PUBLIC DragonflyZone : public ClusterZone { +class XBT_PUBLIC DragonflyZone : public ClusterBase { public: struct Coords { unsigned group; diff --git a/include/simgrid/kernel/routing/FatTreeZone.hpp b/include/simgrid/kernel/routing/FatTreeZone.hpp index 43cb55b7d2..75f83730f6 100644 --- a/include/simgrid/kernel/routing/FatTreeZone.hpp +++ b/include/simgrid/kernel/routing/FatTreeZone.hpp @@ -102,7 +102,7 @@ public: * * Routing is made using a destination-mod-k scheme. */ -class XBT_PRIVATE FatTreeZone : public ClusterZone { +class XBT_PRIVATE FatTreeZone : public ClusterBase { /** @brief Generate the fat tree * * Once all processing nodes have been added, this will make sure the fat @@ -131,7 +131,7 @@ class XBT_PRIVATE FatTreeZone : public ClusterZone { void do_seal() override; public: - using ClusterZone::ClusterZone; + explicit FatTreeZone(const std::string& name) : ClusterBase(name){}; FatTreeZone(const FatTreeZone&) = delete; FatTreeZone& operator=(const FatTreeZone&) = delete; void get_local_route(NetPoint* src, NetPoint* dst, Route* into, double* latency) override; diff --git a/include/simgrid/kernel/routing/StarZone.hpp b/include/simgrid/kernel/routing/StarZone.hpp index b441706249..0c2f093c96 100644 --- a/include/simgrid/kernel/routing/StarZone.hpp +++ b/include/simgrid/kernel/routing/StarZone.hpp @@ -6,7 +6,7 @@ #ifndef SIMGRID_KERNEL_ROUTING_STARZONE_HPP_ #define SIMGRID_KERNEL_ROUTING_STARZONE_HPP_ -#include +#include #include #include @@ -60,8 +60,7 @@ namespace routing { * In this case, a communication from A to B goes through the links: l0, backbone, l1. * Note that the backbone only appears once in the link list. */ - -class StarZone : public NetZoneImpl { +class StarZone : public ClusterZone { // implements the old ClusterZone public: explicit StarZone(const std::string& name); diff --git a/include/simgrid/kernel/routing/TorusZone.hpp b/include/simgrid/kernel/routing/TorusZone.hpp index d657e845ca..329a031e9c 100644 --- a/include/simgrid/kernel/routing/TorusZone.hpp +++ b/include/simgrid/kernel/routing/TorusZone.hpp @@ -19,11 +19,11 @@ namespace routing { * */ -class XBT_PRIVATE TorusZone : public ClusterZone { +class XBT_PRIVATE TorusZone : public ClusterBase { std::vector dimensions_; public: - using ClusterZone::ClusterZone; + explicit TorusZone(const std::string& name) : ClusterBase(name){}; void create_torus_links(int id, int rank, unsigned int position); void get_local_route(NetPoint* src, NetPoint* dst, Route* into, double* latency) override; void set_topology(const std::vector& dimensions); diff --git a/src/kernel/routing/ClusterZone.cpp b/src/kernel/routing/ClusterZone.cpp index 6d332615b0..5b3027866b 100644 --- a/src/kernel/routing/ClusterZone.cpp +++ b/src/kernel/routing/ClusterZone.cpp @@ -16,9 +16,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf" namespace simgrid { namespace kernel { namespace routing { -ClusterZone::ClusterZone(const std::string& name) : NetZoneImpl(name) {} -void ClusterZone::set_loopback() +void ClusterBase::set_loopback() { if (not has_loopback_) { num_links_per_node_++; @@ -26,7 +25,7 @@ void ClusterZone::set_loopback() } } -void ClusterZone::set_limiter() +void ClusterBase::set_limiter() { if (not has_limiter_) { num_links_per_node_++; @@ -34,143 +33,26 @@ void ClusterZone::set_limiter() } } -void ClusterZone::set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy) +void ClusterBase::set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy) { link_sharing_policy_ = sharing_policy; link_bw_ = bw; link_lat_ = lat; } -void ClusterZone::add_private_link_at(unsigned int position, std::pair link) +void ClusterBase::add_private_link_at(unsigned int position, std::pair link) { private_links_.insert({position, link}); } -void ClusterZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route, double* lat) +void ClusterBase::set_gateway(unsigned int position, NetPoint* gateway) { - XBT_VERB("cluster getLocalRoute from '%s'[%u] to '%s'[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id()); - xbt_assert(not private_links_.empty(), - "Cluster routing: no links attached to the source node - did you use host_link tag?"); - - if ((src->id() == dst->id()) && has_loopback_) { - if (src->is_router()) { - XBT_WARN("Routing from a cluster private router to itself is meaningless"); - } else { - std::pair info = private_links_.at(node_pos(src->id())); - route->link_list_.push_back(info.first); - if (lat) - *lat += info.first->get_latency(); - } - return; - } - - if (not src->is_router()) { // No private link for the private router - if (has_limiter_) { // limiter for sender - std::pair info = private_links_.at(node_pos_with_loopback(src->id())); - route->link_list_.push_back(info.first); - } - - std::pair info = - private_links_.at(node_pos_with_loopback_limiter(src->id())); - if (info.first) { // link up - route->link_list_.push_back(info.first); - if (lat) - *lat += info.first->get_latency(); - } - } - - if (backbone_) { - route->link_list_.push_back(backbone_); - if (lat) - *lat += backbone_->get_latency(); - } - - if (not dst->is_router()) { // No specific link for router - std::pair info = - private_links_.at(node_pos_with_loopback_limiter(dst->id())); - - if (info.second) { // link down - route->link_list_.push_back(info.second); - if (lat) - *lat += info.second->get_latency(); - } - if (has_limiter_) { // limiter for receiver - info = private_links_.at(node_pos_with_loopback(dst->id())); - route->link_list_.push_back(info.first); - } - } -} - -void ClusterZone::get_graph(const s_xbt_graph_t* graph, std::map>* nodes, - std::map>* edges) -{ - xbt_assert(router_, - "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph."); - - /* create the router */ - xbt_node_t routerNode = new_xbt_graph_node(graph, router_->get_cname(), nodes); - - xbt_node_t backboneNode = nullptr; - if (backbone_) { - backboneNode = new_xbt_graph_node(graph, backbone_->get_cname(), nodes); - new_xbt_graph_edge(graph, routerNode, backboneNode, edges); - } - - for (auto const& src : get_vertices()) { - if (not src->is_router()) { - xbt_node_t previous = new_xbt_graph_node(graph, src->get_cname(), nodes); - - std::pair info = private_links_.at(src->id()); - - if (info.first) { // link up - xbt_node_t current = new_xbt_graph_node(graph, info.first->get_cname(), nodes); - new_xbt_graph_edge(graph, previous, current, edges); - - if (backbone_) { - new_xbt_graph_edge(graph, current, backboneNode, edges); - } else { - new_xbt_graph_edge(graph, current, routerNode, edges); - } - } - - if (info.second) { // link down - xbt_node_t current = new_xbt_graph_node(graph, info.second->get_cname(), nodes); - new_xbt_graph_edge(graph, previous, current, edges); - - if (backbone_) { - new_xbt_graph_edge(graph, current, backboneNode, edges); - } else { - new_xbt_graph_edge(graph, current, routerNode, edges); - } - } - } - } -} - -void ClusterZone::create_links(int id, int rank) -{ - std::string link_id = get_name() + "_link_" + std::to_string(id); - - const s4u::Link* linkUp; - const s4u::Link* linkDown; - if (link_sharing_policy_ == simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX) { - linkUp = create_link(link_id + "_UP", std::vector{link_bw_})->set_latency(link_lat_)->seal(); - linkDown = create_link(link_id + "_DOWN", std::vector{link_bw_})->set_latency(link_lat_)->seal(); - } else { - linkUp = create_link(link_id, std::vector{link_bw_})->set_latency(link_lat_)->seal(); - linkDown = linkUp; - } - private_links_.insert({node_pos_with_loopback_limiter(rank), {linkUp->get_impl(), linkDown->get_impl()}}); -} - -void ClusterZone::set_gateway(unsigned int position, NetPoint* gateway) -{ - xbt_assert(not gateway || not gateway->is_netzone(), "ClusterZone: gateway cannot be another netzone %s", + xbt_assert(not gateway || not gateway->is_netzone(), "ClusterBase: gateway cannot be another netzone %s", gateway->get_cname()); gateways_[position] = gateway; } -NetPoint* ClusterZone::get_gateway(unsigned int position) +NetPoint* ClusterBase::get_gateway(unsigned int position) { NetPoint* res = nullptr; auto it = gateways_.find(position); @@ -180,7 +62,7 @@ NetPoint* ClusterZone::get_gateway(unsigned int position) return res; } -void ClusterZone::fill_leaf_from_cb(unsigned int position, const std::vector& dimensions, +void ClusterBase::fill_leaf_from_cb(unsigned int position, const std::vector& dimensions, const s4u::ClusterCallbacks& set_callbacks, NetPoint** node_netpoint, s4u::Link** lb_link, s4u::Link** limiter_link) { diff --git a/src/kernel/routing/DragonflyZone.cpp b/src/kernel/routing/DragonflyZone.cpp index aae4d8a87f..47df578e8b 100644 --- a/src/kernel/routing/DragonflyZone.cpp +++ b/src/kernel/routing/DragonflyZone.cpp @@ -18,7 +18,7 @@ namespace simgrid { namespace kernel { namespace routing { -DragonflyZone::DragonflyZone(const std::string& name) : ClusterZone(name) {} +DragonflyZone::DragonflyZone(const std::string& name) : ClusterBase(name) {} DragonflyZone::Coords DragonflyZone::rankId_to_coords(int rankId) const { @@ -44,7 +44,7 @@ void DragonflyZone::rankId_to_coords(int rankId, unsigned int coords[4]) const / void DragonflyZone::set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy) { - ClusterZone::set_link_characteristics(bw, lat, sharing_policy); + ClusterBase::set_link_characteristics(bw, lat, sharing_policy); if (sharing_policy == s4u::Link::SharingPolicy::SPLITDUPLEX) num_links_per_link_ = 2; } diff --git a/src/kernel/routing/StarZone.cpp b/src/kernel/routing/StarZone.cpp index b87c24831b..655332758e 100644 --- a/src/kernel/routing/StarZone.cpp +++ b/src/kernel/routing/StarZone.cpp @@ -17,7 +17,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_star, surf, "Routing part of surf"); namespace simgrid { namespace kernel { namespace routing { -StarZone::StarZone(const std::string& name) : NetZoneImpl(name) {} +StarZone::StarZone(const std::string& name) : ClusterZone(name) {} void StarZone::add_links_to_route(const std::vector& links, Route* route, double* latency, std::unordered_set& added_links) const diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index e62ee466b9..8c30f38eae 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -4,7 +4,6 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/Exception.hpp" -#include "simgrid/kernel/routing/ClusterZone.hpp" #include "simgrid/kernel/routing/DijkstraZone.hpp" #include "simgrid/kernel/routing/DragonflyZone.hpp" #include "simgrid/kernel/routing/EmptyZone.hpp" @@ -249,7 +248,7 @@ static void sg_platf_new_cluster_hierarchical(const simgrid::kernel::routing::Cl /*************************************************************************************************/ /** @brief Create regular Cluster */ -static void sg_platf_new_cluster_flat2(simgrid::kernel::routing::ClusterCreationArgs* cluster) +static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationArgs* cluster) { auto* zone = simgrid::s4u::create_star_zone(cluster->id); simgrid::s4u::NetZone const* parent = routing_get_current() ? routing_get_current()->get_iface() : nullptr; @@ -343,6 +342,19 @@ static void sg_platf_new_cluster_flat2(simgrid::kernel::routing::ClusterCreation simgrid::kernel::routing::on_cluster_creation(*cluster); } +void sg_platf_new_tag_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster) +{ + switch (cluster->topology) { + case simgrid::kernel::routing::ClusterTopology::TORUS: + case simgrid::kernel::routing::ClusterTopology::DRAGONFLY: + case simgrid::kernel::routing::ClusterTopology::FAT_TREE: + sg_platf_new_cluster_hierarchical(cluster); + break; + default: + sg_platf_new_cluster_flat(cluster); + break; + } +} /*************************************************************************************************/ /** @brief Set the links for internal node inside a Cluster(Star) */ static void sg_platf_cluster_set_hostlink(simgrid::kernel::routing::StarZone* zone, @@ -415,124 +427,8 @@ void sg_platf_zone_cluster_populate(simgrid::kernel::routing::ClusterZoneCreatio sg_platf_new_cabinet(zone, &cabinet, backbone); } } -/*************************************************************************************************/ - -static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationArgs* cluster) -{ - using simgrid::kernel::routing::ClusterZone; - - int rankId = 0; - - // What an inventive way of initializing the NetZone that I have as ancestor :-( - simgrid::kernel::routing::ZoneCreationArgs zone; - zone.id = cluster->id; - zone.routing = "Cluster"; - sg_platf_new_Zone_begin(&zone); - auto* current_zone = static_cast(routing_get_current()); - for (auto const& elm : cluster->properties) - current_zone->get_iface()->set_property(elm.first, elm.second); - - if (cluster->loopback_bw > 0 || cluster->loopback_lat > 0) { - current_zone->set_loopback(); - } - - if (cluster->limiter_link > 0) { - current_zone->set_limiter(); - } - - for (int const& i : cluster->radicals) { - std::string host_id = std::string(cluster->prefix) + std::to_string(i) + cluster->suffix; - - XBT_DEBUG("", host_id.c_str(), cluster->speeds.front()); - current_zone->create_host(host_id, cluster->speeds) - ->set_core_count(cluster->core_amount) - ->set_properties(cluster->properties) - ->seal(); - - XBT_DEBUG(""); - - std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(i); - XBT_DEBUG("", link_id.c_str(), cluster->bw, cluster->lat); - - // All links are saved in a matrix; - // every row describes a single node; every node may have multiple links. - // the first column may store a link from x to x if p_has_loopback is set - // the second column may store a limiter link if p_has_limiter is set - // other columns are to store one or more link for the node - - // add a loopback link - simgrid::kernel::resource::LinkImpl* loopback = nullptr; - if (cluster->loopback_bw > 0 || cluster->loopback_lat > 0) { - std::string loopback_name = link_id + "_loopback"; - XBT_DEBUG("", loopback_name.c_str(), cluster->loopback_bw); - - loopback = current_zone->create_link(loopback_name, std::vector{cluster->loopback_bw}) - ->set_sharing_policy(simgrid::s4u::Link::SharingPolicy::FATPIPE) - ->set_latency(cluster->loopback_lat) - ->seal() - ->get_impl(); - - current_zone->add_private_link_at(current_zone->node_pos(rankId), {loopback, loopback}); - } - - // add a limiter link (shared link to account for maximal bandwidth of the node) - simgrid::kernel::resource::LinkImpl* limiter = nullptr; - if (cluster->limiter_link > 0) { - std::string limiter_name = std::string(link_id) + "_limiter"; - XBT_DEBUG("", limiter_name.c_str(), cluster->limiter_link); - - limiter = current_zone->create_link(limiter_name, std::vector{cluster->limiter_link})->seal()->get_impl(); - - current_zone->add_private_link_at(current_zone->node_pos_with_loopback(rankId), {limiter, limiter}); - } - - current_zone->set_link_characteristics(cluster->bw, cluster->lat, cluster->sharing_policy); - // call the cluster function that adds the others links - current_zone->create_links(i, rankId); - rankId++; - } - - // Add a router. - XBT_DEBUG(" "); - XBT_DEBUG("", cluster->router_id.c_str()); - if (cluster->router_id.empty()) - cluster->router_id = std::string(cluster->prefix) + cluster->id + "_router" + cluster->suffix; - current_zone->set_router(current_zone->create_router(cluster->router_id)); - - // Make the backbone - if ((cluster->bb_bw > 0) || (cluster->bb_lat > 0)) { - std::string bb_name = std::string(cluster->id) + "_backbone"; - XBT_DEBUG(" ", bb_name.c_str(), cluster->bb_bw, - cluster->bb_lat); - - auto* backbone = current_zone->create_link(bb_name, std::vector{cluster->bb_bw}) - ->set_sharing_policy(cluster->bb_sharing_policy) - ->set_latency(cluster->bb_lat) - ->seal() - ->get_impl(); - current_zone->set_backbone(backbone); - } - - XBT_DEBUG(""); - sg_platf_new_Zone_seal(); - simgrid::kernel::routing::on_cluster_creation(*cluster); -} -void sg_platf_new_tag_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster) -{ - switch (cluster->topology) { - case simgrid::kernel::routing::ClusterTopology::TORUS: - case simgrid::kernel::routing::ClusterTopology::DRAGONFLY: - case simgrid::kernel::routing::ClusterTopology::FAT_TREE: - sg_platf_new_cluster_hierarchical(cluster); - break; - default: - sg_platf_new_cluster_flat2(cluster); - break; - } -} /*************************************************************************************************/ - void sg_platf_new_route(simgrid::kernel::routing::RouteCreationArgs* route) { routing_get_current()->add_route(route->src, route->dst, route->gw_src, route->gw_dst, route->link_list,