X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/cff982bd049d26d7acbd0e23324e0de051b06d0d..dd05fd45abf2bfb43fe1d423527512ee295d9a7a:/src/kernel/routing/TorusZone.cpp diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index ac9177edc5..5c9a239052 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2014-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2014-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. */ @@ -18,10 +18,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster_torus, surf_route_cluster, "T namespace simgrid { namespace kernel { namespace routing { -TorusZone::TorusZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel) - : ClusterZone(father, name, netmodel) -{ -} void TorusZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int rank, unsigned int position) { @@ -29,7 +25,6 @@ void TorusZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int int dim_product = 1; // Needed to calculate the next neighbor_id for (unsigned int j = 0; j < dimensions_.size(); j++) { - LinkCreationArgs link; int current_dimension = dimensions_[j]; // which dimension are we currently in? // we need to iterate over all dimensions and create all links there // The other node the link connects @@ -39,29 +34,24 @@ void TorusZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int // name of neighbor is not right for non contiguous cluster radicals (as id != rank in this case) std::string link_id = std::string(cluster->id) + "_link_from_" + std::to_string(id) + "_to_" + std::to_string(neighbor_rank_id); - link.id = link_id; - link.bandwidths.push_back(cluster->bw); - link.latency = cluster->lat; - link.policy = cluster->sharing_policy; - sg_platf_new_link(&link); - resource::LinkImpl* linkUp; - resource::LinkImpl* linkDown; - if (link.policy == s4u::Link::SharingPolicy::SPLITDUPLEX) { - linkUp = s4u::Link::by_name(link_id + "_UP")->get_impl(); - linkDown = s4u::Link::by_name(link_id + "_DOWN")->get_impl(); + const s4u::Link* linkup; + const s4u::Link* linkdown; + if (cluster->sharing_policy == s4u::Link::SharingPolicy::SPLITDUPLEX) { + linkup = create_link(link_id + "_UP", std::vector{cluster->bw})->set_latency(cluster->lat)->seal(); + linkdown = create_link(link_id + "_DOWN", std::vector{cluster->bw})->set_latency(cluster->lat)->seal(); + } else { - linkUp = s4u::Link::by_name(link_id)->get_impl(); - linkDown = linkUp; + linkup = create_link(link_id, std::vector{cluster->bw})->set_latency(cluster->lat)->seal(); + linkdown = linkup; } /* * Add the link to its appropriate position. * Note that position rankId*(xbt_dynar_length(dimensions)+has_loopback?+has_limiter?) * holds the link "rankId->rankId" */ - private_links_.insert({position + j, {linkUp, linkDown}}); + add_private_link_at(position + j, {linkup->get_impl(), linkdown->get_impl()}); dim_product *= current_dimension; } - rank++; } void TorusZone::parse_specific_arguments(ClusterCreationArgs* cluster) @@ -77,7 +67,7 @@ void TorusZone::parse_specific_arguments(ClusterCreationArgs* cluster) for (auto const& group : dimensions) dimensions_.push_back(surf_parse_get_int(group)); - num_links_per_node_ = dimensions_.size(); + set_num_links_per_node(dimensions_.size()); } } @@ -88,12 +78,12 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* if (dst->is_router() || src->is_router()) return; - if (src->id() == dst->id() && has_loopback_) { - std::pair info = private_links_.at(src->id() * num_links_per_node_); + if (src->id() == dst->id() && has_loopback()) { + resource::LinkImpl* uplink = get_uplink_from(node_pos(src->id())); - route->link_list.push_back(info.first); + route->link_list.push_back(uplink); if (lat) - *lat += info.first->get_latency(); + *lat += uplink->get_latency(); return; } @@ -135,17 +125,17 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* if ((current_node / dim_product) % cur_dim != (dst->id() / dim_product) % cur_dim) { if ((targetCoords[j] > myCoords[j] && targetCoords[j] <= myCoords[j] + cur_dim / 2) // Is the target node on the right, without the wrap-around? - || (myCoords[j] > cur_dim / 2 && - (myCoords[j] + cur_dim / 2) % cur_dim >= - targetCoords[j])) { // Or do we need to use the wrap around to reach it? + || + (myCoords[j] > cur_dim / 2 && (myCoords[j] + cur_dim / 2) % cur_dim >= + targetCoords[j])) { // Or do we need to use the wrap around to reach it? if ((current_node / dim_product) % cur_dim == cur_dim - 1) next_node = (current_node + dim_product - dim_product * cur_dim); else next_node = (current_node + dim_product); // HERE: We use *CURRENT* node for calculation (as opposed to next_node) - nodeOffset = current_node * (num_links_per_node_); - linkOffset = nodeOffset + (has_loopback_ ? 1 : 0) + (has_limiter_ ? 1 : 0) + j; + nodeOffset = node_pos(current_node); + linkOffset = node_pos_with_loopback_limiter(current_node) + j; use_lnk_up = true; assert(linkOffset >= 0); } else { // Route to the left @@ -155,8 +145,8 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* next_node = (current_node - dim_product); // HERE: We use *next* node for calculation (as opposed to current_node!) - nodeOffset = next_node * (num_links_per_node_); - linkOffset = nodeOffset + j + (has_loopback_ ? 1 : 0) + (has_limiter_ ? 1 : 0); + nodeOffset = node_pos(next_node); + linkOffset = node_pos_with_loopback_limiter(next_node) + j; use_lnk_up = false; assert(linkOffset >= 0); @@ -169,15 +159,15 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* dim_product *= cur_dim; } - std::pair info; - - if (has_limiter_) { // limiter for sender - info = private_links_.at(nodeOffset + (has_loopback_ ? 1 : 0)); - route->link_list.push_back(info.first); + if (has_limiter()) { // limiter for sender + route->link_list.push_back(get_uplink_from(node_pos_with_loopback(nodeOffset))); } - info = private_links_.at(linkOffset); - resource::LinkImpl* lnk = use_lnk_up ? info.first : info.second; + resource::LinkImpl* lnk; + if (use_lnk_up) + lnk = get_uplink_from(linkOffset); + else + lnk = get_downlink_to(linkOffset); route->link_list.push_back(lnk); if (lat) @@ -188,4 +178,12 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* } } // namespace routing } // namespace kernel + +namespace s4u { +NetZone* create_torus_zone(const std::string& name) +{ + return (new kernel::routing::TorusZone(name))->get_iface(); +} +} // namespace s4u + } // namespace simgrid