From 76cc94266507b7f7e29f95d3c65e2370cbd40142 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 11 Dec 2016 20:56:41 +0100 Subject: [PATCH] use std::pair instead of s_surf_parsing_link_up_down_t for Cluster private links --- src/kernel/routing/AsCluster.cpp | 41 +++++++++++------------ src/kernel/routing/AsCluster.hpp | 3 +- src/kernel/routing/AsClusterDragonfly.cpp | 18 +++++----- src/kernel/routing/AsClusterTorus.cpp | 20 +++++------ src/kernel/routing/AsVivaldi.cpp | 18 +++++----- src/surf/sg_platf.cpp | 12 +++---- 6 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/kernel/routing/AsCluster.cpp b/src/kernel/routing/AsCluster.cpp index 095b80cc16..95805fc2f8 100644 --- a/src/kernel/routing/AsCluster.cpp +++ b/src/kernel/routing/AsCluster.cpp @@ -28,24 +28,24 @@ void AsCluster::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg_t if (! src->isRouter()) { // No specific link for router if((src->id() == dst->id()) && hasLoopback_ ){ - s_surf_parsing_link_up_down_t info = privateLinks_.at(src->id() * linkCountPerNode_); - route->link_list->push_back(info.linkUp); + std::pair info = privateLinks_.at(src->id() * linkCountPerNode_); + route->link_list->push_back(info.first); if (lat) - *lat += info.linkUp->latency(); + *lat += info.first->latency(); return; } if (hasLimiter_){ // limiter for sender - s_surf_parsing_link_up_down_t info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0)); - route->link_list->push_back(info.linkUp); + std::pair info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0)); + route->link_list->push_back(info.first); } - s_surf_parsing_link_up_down_t info = + std::pair info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0)); - if (info.linkUp) { // link up - route->link_list->push_back(info.linkUp); + if (info.first) { // link up + route->link_list->push_back(info.first); if (lat) - *lat += info.linkUp->latency(); + *lat += info.first->latency(); } } @@ -57,16 +57,16 @@ void AsCluster::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg_t } if (! dst->isRouter()) { // No specific link for router - s_surf_parsing_link_up_down_t info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_); + std::pair info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_); - if (info.linkDown) { // link down - route->link_list->push_back(info.linkDown); + if (info.second) { // link down + route->link_list->push_back(info.second); if (lat) - *lat += info.linkDown->latency(); + *lat += info.second->latency(); } if (hasLimiter_){ // limiter for receiver info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_); - route->link_list->push_back(info.linkUp); + route->link_list->push_back(info.first); } } } @@ -74,7 +74,7 @@ void AsCluster::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg_t void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) { xbt_node_t current, previous, backboneNode = nullptr; - s_surf_parsing_link_up_down_t info; + std::pair info; xbt_assert(router_,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph."); @@ -94,8 +94,8 @@ void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) info = privateLinks_.at(src->id()); - if (info.linkUp) { // link up - const char *link_name = static_cast(info.linkUp)->getName(); + if (info.first) { // link up + const char* link_name = static_cast(info.first)->getName(); current = new_xbt_graph_node(graph, link_name, nodes); new_xbt_graph_edge(graph, previous, current, edges); @@ -106,9 +106,8 @@ void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) } } - if (info.linkDown) { // link down - const char *link_name = static_cast( - info.linkDown)->getName(); + if (info.second) { // link down + const char* link_name = static_cast(info.second)->getName(); current = new_xbt_graph_node(graph, link_name, nodes); new_xbt_graph_edge(graph, previous, current, edges); @@ -145,7 +144,7 @@ void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, info.linkUp = Link::byName(link_id); info.linkDown = info.linkUp; } - privateLinks_.insert({position, info}); + privateLinks_.insert({position, {info.linkUp, info.linkDown}}); xbt_free(link_id); } diff --git a/src/kernel/routing/AsCluster.hpp b/src/kernel/routing/AsCluster.hpp index 9dd3d090e0..14d07c8d3f 100644 --- a/src/kernel/routing/AsCluster.hpp +++ b/src/kernel/routing/AsCluster.hpp @@ -25,7 +25,8 @@ public: virtual void parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) {} /* We use a map instead of a std::vector here because that's a sparse vector. Some values may not exist */ - std::unordered_map privateLinks_; + /* The pair is {linkUp, linkDown} */ + std::unordered_map> privateLinks_; Link* backbone_ = nullptr; void *loopback_ = nullptr; diff --git a/src/kernel/routing/AsClusterDragonfly.cpp b/src/kernel/routing/AsClusterDragonfly.cpp index abe03acbc9..355c17d35e 100644 --- a/src/kernel/routing/AsClusterDragonfly.cpp +++ b/src/kernel/routing/AsClusterDragonfly.cpp @@ -249,12 +249,12 @@ void AsClusterDragonfly::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_rout dst->id()); if ((src->id() == dst->id()) && hasLoopback_) { - s_surf_parsing_link_up_down_t info = privateLinks_.at(src->id() * linkCountPerNode_); + std::pair info = privateLinks_.at(src->id() * linkCountPerNode_); - route->link_list->push_back(info.linkUp); - if (latency) - *latency += info.linkUp->latency(); - return; + route->link_list->push_back(info.first); + if (latency) + *latency += info.first->latency(); + return; } unsigned int *myCoords = rankId_to_coords(src->id()); @@ -272,8 +272,8 @@ void AsClusterDragonfly::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_rout *latency += myRouter->myNodes_[myCoords[3] * numLinksperLink_]->latency(); if (hasLimiter_) { // limiter for sender - s_surf_parsing_link_up_down_t info = privateLinks_.at(src->id() * linkCountPerNode_ + hasLoopback_); - route->link_list->push_back(info.linkUp); + std::pair info = privateLinks_.at(src->id() * linkCountPerNode_ + hasLoopback_); + route->link_list->push_back(info.first); } if(targetRouter!=myRouter){ @@ -323,8 +323,8 @@ void AsClusterDragonfly::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_rout } if (hasLimiter_) { // limiter for receiver - s_surf_parsing_link_up_down_t info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_); - route->link_list->push_back(info.linkUp); + std::pair info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_); + route->link_list->push_back(info.first); } //router->node local link diff --git a/src/kernel/routing/AsClusterTorus.cpp b/src/kernel/routing/AsClusterTorus.cpp index 8690cdc72b..d3477eb13b 100644 --- a/src/kernel/routing/AsClusterTorus.cpp +++ b/src/kernel/routing/AsClusterTorus.cpp @@ -80,7 +80,7 @@ namespace simgrid { * note that position rankId*(xbt_dynar_length(dimensions)+has_loopback?+has_limiter?) * holds the link "rankId->rankId" */ - privateLinks_.insert({position + j, info}); + privateLinks_.insert({position + j, {info.linkUp, info.linkDown}}); dim_product *= current_dimension; xbt_free(link_id); } @@ -121,11 +121,11 @@ namespace simgrid { return; if (src->id() == dst->id() && hasLoopback_) { - s_surf_parsing_link_up_down_t info = privateLinks_.at(src->id() * linkCountPerNode_); + std::pair info = privateLinks_.at(src->id() * linkCountPerNode_); - route->link_list->push_back(info.linkUp); + route->link_list->push_back(info.first); if (lat) - *lat += info.linkUp->latency(); + *lat += info.first->latency(); return; } @@ -199,23 +199,23 @@ namespace simgrid { dim_product *= cur_dim; } - s_surf_parsing_link_up_down_t info; + std::pair info; if (hasLimiter_) { // limiter for sender info = privateLinks_.at(nodeOffset + hasLoopback_); - route->link_list->push_back(info.linkUp); + route->link_list->push_back(info.first); } info = privateLinks_.at(linkOffset); if (use_lnk_up == false) { - route->link_list->push_back(info.linkDown); + route->link_list->push_back(info.second); if (lat) - *lat += info.linkDown->latency(); + *lat += info.second->latency(); } else { - route->link_list->push_back(info.linkUp); + route->link_list->push_back(info.first); if (lat) - *lat += info.linkUp->latency(); + *lat += info.first->latency(); } current_node = next_node; next_node = 0; diff --git a/src/kernel/routing/AsVivaldi.cpp b/src/kernel/routing/AsVivaldi.cpp index a7ff1f689a..8988735681 100644 --- a/src/kernel/routing/AsVivaldi.cpp +++ b/src/kernel/routing/AsVivaldi.cpp @@ -68,7 +68,7 @@ void AsVivaldi::setPeerLink(NetCard* netcard, double bw_in, double bw_out, doubl char* link_down = bprintf("link_%s_DOWN", netcard->cname()); info.linkUp = surf_network_model->createLink(link_up, bw_out, latency, SURF_LINK_SHARED); info.linkDown = surf_network_model->createLink(link_down, bw_in, latency, SURF_LINK_SHARED); - privateLinks_.insert({netcard->id(), info}); + privateLinks_.insert({netcard->id(), {info.linkUp, info.linkDown}}); free(link_up); free(link_down); @@ -89,19 +89,19 @@ void AsVivaldi::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg_t /* Retrieve the private links */ if (privateLinks_.find(src->id()) != privateLinks_.end()) { - s_surf_parsing_link_up_down_t info = privateLinks_.at(src->id()); - if (info.linkUp) { - route->link_list->push_back(info.linkUp); + std::pair info = privateLinks_.at(src->id()); + if (info.first) { + route->link_list->push_back(info.first); if (lat) - *lat += info.linkUp->latency(); + *lat += info.first->latency(); } } if (privateLinks_.find(dst->id()) != privateLinks_.end()) { - s_surf_parsing_link_up_down_t info = privateLinks_.at(dst->id()); - if (info.linkDown) { - route->link_list->push_back(info.linkDown); + std::pair info = privateLinks_.at(dst->id()); + if (info.second) { + route->link_list->push_back(info.second); if (lat) - *lat += info.linkDown->latency(); + *lat += info.second->latency(); } } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index a6627a2738..35b2debb58 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -261,7 +261,8 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) free(tmp_link); auto as_cluster = static_cast(current_as); - as_cluster->privateLinks_.insert({rankId*as_cluster->linkCountPerNode_, info_loop}); + as_cluster->privateLinks_.insert( + {rankId * as_cluster->linkCountPerNode_, {info_loop.linkUp, info_loop.linkDown}}); } //add a limiter link (shared link to account for maximal bandwidth of the node) @@ -278,7 +279,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) info_lim.linkUp = info_lim.linkDown = Link::byName(tmp_link); free(tmp_link); current_as->privateLinks_.insert( - {rankId * current_as->linkCountPerNode_ + current_as->hasLoopback_ , info_lim}); + {rankId * current_as->linkCountPerNode_ + current_as->hasLoopback_, {info_lim.linkUp, info_lim.linkDown}}); } //call the cluster function that adds the others links @@ -570,14 +571,13 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) void sg_platf_new_peer(sg_platf_peer_cbarg_t peer) { - using simgrid::kernel::routing::AsVivaldi; - - AsVivaldi* as = dynamic_cast(current_routing); + simgrid::kernel::routing::AsVivaldi* as = dynamic_cast(current_routing); xbt_assert(as, " tag can only be used in Vivaldi ASes"); std::vector speedPerPstate; speedPerPstate.push_back(peer->speed); simgrid::s4u::Host* host = as->createHost(peer->id, &speedPerPstate, 1); + as->setPeerLink(host->pimpl_netcard, peer->bw_in, peer->bw_out, peer->lat, peer->coord); simgrid::s4u::Host::onCreation(*host); @@ -760,5 +760,5 @@ void sg_platf_new_hostlink(sg_platf_host_link_cbarg_t hostlink) surf_parse_error("Host_link for '%s' is already defined!",hostlink->id); XBT_DEBUG("Push Host_link for host '%s' to position %d", netcard->name().c_str(), netcard->id()); - as_cluster->privateLinks_.insert({netcard->id(), link_up_down}); + as_cluster->privateLinks_.insert({netcard->id(), {link_up_down.linkUp, link_up_down.linkDown}}); } -- 2.20.1