From: Arnaud Giersch Date: Thu, 5 Oct 2017 07:55:48 +0000 (+0200) Subject: Factorize code. X-Git-Tag: v3_17~13 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1957cbeaedc9d28cea7839684d82ac8454cc8bef?hp=8ce2c767b3688a843e90e06e124e9bd8b56ecf38 Factorize code. --- diff --git a/src/kernel/routing/ClusterZone.cpp b/src/kernel/routing/ClusterZone.cpp index 5ee8eb375a..2bd66e5359 100644 --- a/src/kernel/routing/ClusterZone.cpp +++ b/src/kernel/routing/ClusterZone.cpp @@ -29,7 +29,7 @@ void ClusterZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cba if ((src->id() == dst->id()) && hasLoopback_) { xbt_assert(not src->isRouter(), "Routing from a cluster private router to itself is meaningless"); - std::pair info = privateLinks_.at(src->id() * linkCountPerNode_); + std::pair info = privateLinks_.at(nodePosition(src->id())); route->link_list->push_back(info.first); if (lat) *lat += info.first->latency(); @@ -38,13 +38,11 @@ void ClusterZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cba if (not src->isRouter()) { // No private link for the private router if (hasLimiter_) { // limiter for sender - std::pair info = - privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0)); + std::pair info = privateLinks_.at(nodePositionWithLoopback(src->id())); route->link_list->push_back(info.first); } - std::pair info = - privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0)); + std::pair info = privateLinks_.at(nodePositionWithLimiter(src->id())); if (info.first) { // link up route->link_list->push_back(info.first); if (lat) @@ -60,15 +58,14 @@ void ClusterZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cba if (not dst->isRouter()) { // No specific link for router - std::pair info = - privateLinks_.at(dst->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0)); + std::pair info = privateLinks_.at(nodePositionWithLimiter(dst->id())); if (info.second) { // link down route->link_list->push_back(info.second); if (lat) *lat += info.second->latency(); } if (hasLimiter_) { // limiter for receiver - info = privateLinks_.at(dst->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0)); + info = privateLinks_.at(nodePositionWithLoopback(dst->id())); route->link_list->push_back(info.first); } } diff --git a/src/kernel/routing/ClusterZone.hpp b/src/kernel/routing/ClusterZone.hpp index 9fe165366d..d5523ba1ba 100644 --- a/src/kernel/routing/ClusterZone.hpp +++ b/src/kernel/routing/ClusterZone.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2016. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2013-2017. 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. */ @@ -82,6 +82,10 @@ public: /* The pair is {linkUp, linkDown} */ std::unordered_map> privateLinks_; + int nodePosition(int id) { return id * linkCountPerNode_; } + int nodePositionWithLoopback(int id) { return nodePosition(id) + (hasLoopback_ ? 1 : 0); } + int nodePositionWithLimiter(int id) { return nodePositionWithLoopback(id) + (hasLimiter_ ? 1 : 0); } + surf::LinkImpl* backbone_ = nullptr; void* loopback_ = nullptr; NetPoint* router_ = nullptr; diff --git a/src/kernel/routing/DragonflyZone.cpp b/src/kernel/routing/DragonflyZone.cpp index 7dde15fa42..790b3d10b6 100644 --- a/src/kernel/routing/DragonflyZone.cpp +++ b/src/kernel/routing/DragonflyZone.cpp @@ -290,7 +290,7 @@ void DragonflyZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_c dst->id()); if ((src->id() == dst->id()) && hasLoopback_) { - std::pair info = privateLinks_.at(src->id() * linkCountPerNode_); + std::pair info = privateLinks_.at(nodePosition(src->id())); route->link_list->push_back(info.first); if (latency) @@ -318,8 +318,7 @@ void DragonflyZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_c *latency += myRouter->myNodes_[myCoords[3] * numLinksperLink_]->latency(); if (hasLimiter_) { // limiter for sender - std::pair info = - privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0)); + std::pair info = privateLinks_.at(nodePositionWithLoopback(src->id())); route->link_list->push_back(info.first); } @@ -369,8 +368,7 @@ void DragonflyZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_c } if (hasLimiter_) { // limiter for receiver - std::pair info = - privateLinks_.at(dst->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0)); + std::pair info = privateLinks_.at(nodePositionWithLoopback(dst->id())); route->link_list->push_back(info.first); } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index b4afbd5711..354ba1c6c6 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -236,7 +236,7 @@ void sg_platf_new_cluster(ClusterCreationArgs* cluster) linkDown = simgrid::surf::LinkImpl::byName(tmp_link); auto as_cluster = static_cast(current_as); - as_cluster->privateLinks_.insert({rankId * as_cluster->linkCountPerNode_, {linkUp, linkDown}}); + as_cluster->privateLinks_.insert({as_cluster->nodePosition(rankId), {linkUp, linkDown}}); } //add a limiter link (shared link to account for maximal bandwidth of the node) @@ -254,17 +254,14 @@ void sg_platf_new_cluster(ClusterCreationArgs* cluster) sg_platf_new_link(&link); linkDown = simgrid::surf::LinkImpl::byName(tmp_link); linkUp = linkDown; - current_as->privateLinks_.insert( - {rankId * current_as->linkCountPerNode_ + (current_as->hasLoopback_ ? 1 : 0), {linkUp, linkDown}}); + current_as->privateLinks_.insert({current_as->nodePositionWithLoopback(rankId), {linkUp, linkDown}}); } //call the cluster function that adds the others links if (cluster->topology == SURF_CLUSTER_FAT_TREE) { static_cast(current_as)->addProcessingNode(i); } else { - current_as->create_links_for_node(cluster, i, rankId, rankId * current_as->linkCountPerNode_ + - (current_as->hasLoopback_ ? 1 : 0) + - (current_as->hasLimiter_ ? 1 : 0)); + current_as->create_links_for_node(cluster, i, rankId, current_as->nodePositionWithLimiter(rankId)); } rankId++; }