Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Sonar variety
[simgrid.git] / src / kernel / routing / DragonflyZone.cpp
index beb0ebf..2df80e7 100644 (file)
@@ -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;
 }
@@ -151,18 +151,26 @@ void DragonflyZone::build_upper_levels(const s4u::ClusterCallbacks& set_callback
 void DragonflyZone::generate_routers(const s4u::ClusterCallbacks& set_callbacks)
 {
   int id = 0;
+  /* get limiter for this router */
+  auto get_limiter = [this, &id, &set_callbacks](unsigned int i, unsigned int j,
+                                                 unsigned int k) -> resource::LinkImpl* {
+    kernel::resource::LinkImpl* limiter = nullptr;
+    if (set_callbacks.limiter) {
+      id--;
+      const auto* s4u_link =
+          set_callbacks.limiter(get_iface(), {i, j, k, std::numeric_limits<unsigned int>::max()}, id);
+      if (s4u_link) {
+        limiter = s4u_link->get_impl();
+      }
+    }
+    return limiter;
+  };
+
   routers_.reserve(num_groups_ * num_chassis_per_group_ * num_blades_per_chassis_);
   for (unsigned int i = 0; i < num_groups_; i++) {
     for (unsigned int j = 0; j < num_chassis_per_group_; j++) {
       for (unsigned int k = 0; k < num_blades_per_chassis_; k++) {
-        resource::LinkImpl* limiter = nullptr;
-        if (set_callbacks.limiter) {
-          auto* s4u_link =
-              set_callbacks.limiter(get_iface(), {i, j, k, std::numeric_limits<unsigned int>::max()}, --id);
-          if (s4u_link)
-            limiter = s4u_link->get_impl();
-        }
-        routers_.emplace_back(i, j, k, limiter);
+        routers_.emplace_back(i, j, k, get_limiter(i, j, k));
       }
     }
   }
@@ -273,7 +281,7 @@ void DragonflyZone::generate_links()
   }
 }
 
-void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route, double* latency)
+void DragonflyZone::get_local_route(const NetPoint* src, const NetPoint* dst, Route* route, double* latency)
 {
   // Minimal routing version.
   // TODO : non-minimal random one, and adaptive ?
@@ -287,9 +295,7 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route,
   if ((src->id() == dst->id()) && has_loopback()) {
     resource::LinkImpl* uplink = get_uplink_from(node_pos(src->id()));
 
-    route->link_list_.push_back(uplink);
-    if (latency)
-      *latency += uplink->get_latency();
+    add_link_latency(route->link_list_, uplink, latency);
     return;
   }
 
@@ -311,9 +317,7 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route,
   }
 
   // node->router local link
-  route->link_list_.push_back(myRouter->my_nodes_[myCoords.node * num_links_per_link_]);
-  if (latency)
-    *latency += myRouter->my_nodes_[myCoords.node * num_links_per_link_]->get_latency();
+  add_link_latency(route->link_list_, myRouter->my_nodes_[myCoords.node * num_links_per_link_], latency);
 
   if (targetRouter != myRouter) {
     // are we on a different group ?
@@ -323,9 +327,7 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route,
         if (currentRouter->limiter_)
           route->link_list_.push_back(currentRouter->limiter_);
         // go to the nth router in our chassis
-        route->link_list_.push_back(currentRouter->green_links_[targetCoords.group]);
-        if (latency)
-          *latency += currentRouter->green_links_[targetCoords.group]->get_latency();
+        add_link_latency(route->link_list_, currentRouter->green_links_[targetCoords.group], latency);
         currentRouter = &routers_[myCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) +
                                   myCoords.chassis * num_blades_per_chassis_ + targetCoords.group];
       }
@@ -334,19 +336,15 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route,
         // go to the first chassis of our group
         if (currentRouter->limiter_)
           route->link_list_.push_back(currentRouter->limiter_);
-        route->link_list_.push_back(currentRouter->black_links_[0]);
-        if (latency)
-          *latency += currentRouter->black_links_[0]->get_latency();
+        add_link_latency(route->link_list_, currentRouter->black_links_[0], latency);
         currentRouter =
             &routers_[myCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) + targetCoords.group];
       }
 
       // go to destination group - the only optical hop
-      route->link_list_.push_back(currentRouter->blue_link_);
+      add_link_latency(route->link_list_, currentRouter->blue_link_, latency);
       if (currentRouter->limiter_)
         route->link_list_.push_back(currentRouter->limiter_);
-      if (latency)
-        *latency += currentRouter->blue_link_->get_latency();
       currentRouter =
           &routers_[targetCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) + myCoords.group];
     }
@@ -355,9 +353,7 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route,
     if (targetRouter->blade_ != currentRouter->blade_) {
       if (currentRouter->limiter_)
         route->link_list_.push_back(currentRouter->limiter_);
-      route->link_list_.push_back(currentRouter->green_links_[targetCoords.blade]);
-      if (latency)
-        *latency += currentRouter->green_links_[targetCoords.blade]->get_latency();
+      add_link_latency(route->link_list_, currentRouter->green_links_[targetCoords.blade], latency);
       currentRouter =
           &routers_[targetCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) + targetCoords.blade];
     }
@@ -366,21 +362,15 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route,
     if (targetRouter->chassis_ != currentRouter->chassis_) {
       if (currentRouter->limiter_)
         route->link_list_.push_back(currentRouter->limiter_);
-      route->link_list_.push_back(currentRouter->black_links_[targetCoords.chassis]);
-      if (latency)
-        *latency += currentRouter->black_links_[targetCoords.chassis]->get_latency();
+      add_link_latency(route->link_list_, currentRouter->black_links_[targetCoords.chassis], latency);
     }
   }
 
   // router->node local link
   if (targetRouter->limiter_)
     route->link_list_.push_back(targetRouter->limiter_);
-  route->link_list_.push_back(
-      targetRouter->my_nodes_[targetCoords.node * num_links_per_link_ + num_links_per_link_ - 1]);
-
-  if (latency)
-    *latency +=
-        targetRouter->my_nodes_[targetCoords.node * num_links_per_link_ + num_links_per_link_ - 1]->get_latency();
+  add_link_latency(route->link_list_,
+                   targetRouter->my_nodes_[targetCoords.node * num_links_per_link_ + num_links_per_link_ - 1], latency);
 
   if (has_limiter()) { // limiter for receiver
     route->link_list_.push_back(get_downlink_to(node_pos_with_loopback(dst->id())));