Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factorize code.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 5 Oct 2017 07:55:48 +0000 (09:55 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 5 Oct 2017 07:55:48 +0000 (09:55 +0200)
src/kernel/routing/ClusterZone.cpp
src/kernel/routing/ClusterZone.hpp
src/kernel/routing/DragonflyZone.cpp
src/surf/sg_platf.cpp

index 5ee8eb3..2bd66e5 100644 (file)
@@ -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<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id() * linkCountPerNode_);
+    std::pair<surf::LinkImpl*, surf::LinkImpl*> 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<surf::LinkImpl*, surf::LinkImpl*> info =
-          privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
+      std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(nodePositionWithLoopback(src->id()));
       route->link_list->push_back(info.first);
     }
 
-    std::pair<surf::LinkImpl*, surf::LinkImpl*> info =
-        privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0));
+    std::pair<surf::LinkImpl*, surf::LinkImpl*> 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<surf::LinkImpl*, surf::LinkImpl*> info =
-        privateLinks_.at(dst->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0));
+    std::pair<surf::LinkImpl*, surf::LinkImpl*> 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);
     }
   }
index 9fe1653..d5523ba 100644 (file)
@@ -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<unsigned int, std::pair<surf::LinkImpl*, surf::LinkImpl*>> 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;
index 7dde15f..790b3d1 100644 (file)
@@ -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<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id() * linkCountPerNode_);
+    std::pair<surf::LinkImpl*, surf::LinkImpl*> 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<surf::LinkImpl*, surf::LinkImpl*> info =
-        privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
+    std::pair<surf::LinkImpl*, surf::LinkImpl*> 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<surf::LinkImpl*, surf::LinkImpl*> info =
-        privateLinks_.at(dst->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
+    std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(nodePositionWithLoopback(dst->id()));
     route->link_list->push_back(info.first);
   }
 
index b4afbd5..354ba1c 100644 (file)
@@ -236,7 +236,7 @@ void sg_platf_new_cluster(ClusterCreationArgs* cluster)
       linkDown = simgrid::surf::LinkImpl::byName(tmp_link);
 
       auto as_cluster = static_cast<ClusterZone*>(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<FatTreeZone*>(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++;
   }