Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
vector::back() is good enough + assert for scan_build.
[simgrid.git] / src / kernel / routing / TorusZone.cpp
index 793e9a6..b7c7001 100644 (file)
@@ -7,7 +7,6 @@
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "src/surf/network_interface.hpp"
-#include "src/surf/xml/platf_private.hpp"
 
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/split.hpp>
@@ -21,7 +20,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-void TorusZone::create_links(int id, int rank, unsigned int position)
+void TorusZone::create_torus_links(int id, int rank, unsigned int position)
 {
   /* Create all links that exist in the torus. Each rank creates @a dimensions-1 links */
   int dim_product = 1; // Needed to calculate the next neighbor_id
@@ -37,12 +36,16 @@ void TorusZone::create_links(int id, int rank, unsigned int position)
     std::string link_id = get_name() + "_link_from_" + std::to_string(id) + "_to_" + std::to_string(neighbor_rank_id);
     const s4u::Link* linkup;
     const s4u::Link* linkdown;
-    if (link_sharing_policy_ == s4u::Link::SharingPolicy::SPLITDUPLEX) {
-      linkup   = create_link(link_id + "_UP", std::vector<double>{link_bw_})->set_latency(link_lat_)->seal();
-      linkdown = create_link(link_id + "_DOWN", std::vector<double>{link_bw_})->set_latency(link_lat_)->seal();
+    if (get_link_sharing_policy() == s4u::Link::SharingPolicy::SPLITDUPLEX) {
+      linkup = create_link(link_id + "_UP", std::vector<double>{get_link_bandwidth()})
+                   ->set_latency(get_link_latency())
+                   ->seal();
+      linkdown = create_link(link_id + "_DOWN", std::vector<double>{get_link_bandwidth()})
+                     ->set_latency(get_link_latency())
+                     ->seal();
 
     } else {
-      linkup   = create_link(link_id, std::vector<double>{link_bw_})->set_latency(link_lat_)->seal();
+      linkup = create_link(link_id, std::vector<double>{get_link_bandwidth()})->set_latency(get_link_latency())->seal();
       linkdown = linkup;
     }
     /*
@@ -66,18 +69,12 @@ std::vector<unsigned int> TorusZone::parse_topo_parameters(const std::string& to
      * Parse attribute dimensions="dim1,dim2,dim3,...,dimN" and save them into a vector.
      * Additionally, we need to know how many ranks we have in total
      */
-    std::transform(begin(dimensions_str), end(dimensions_str), std::back_inserter(dimensions), surf_parse_get_int);
+    std::transform(begin(dimensions_str), end(dimensions_str), std::back_inserter(dimensions),
+                   [](const std::string& s) { return std::stoi(s); });
   }
   return dimensions;
 }
 
-void TorusZone::set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy)
-{
-  link_sharing_policy_ = sharing_policy;
-  link_bw_             = bw;
-  link_lat_            = lat;
-}
-
 void TorusZone::set_topology(const std::vector<unsigned int>& dimensions)
 {
   xbt_assert(not dimensions.empty(), "Torus dimensions cannot be empty");
@@ -85,7 +82,7 @@ void TorusZone::set_topology(const std::vector<unsigned int>& dimensions)
   set_num_links_per_node(dimensions_.size());
 }
 
-void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* route, double* lat)
+void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route, double* lat)
 {
   XBT_VERB("torus getLocalRoute from '%s'[%u] to '%s'[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
 
@@ -95,7 +92,7 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
   if (src->id() == dst->id() && has_loopback()) {
     resource::LinkImpl* uplink = get_uplink_from(node_pos(src->id()));
 
-    route->link_list.push_back(uplink);
+    route->link_list_.push_back(uplink);
     if (lat)
       *lat += uplink->get_latency();
     return;
@@ -110,11 +107,11 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
    * Arrays that hold the coordinates of the current node and the target; comparing the values at the i-th position of
    * both arrays, we can easily assess whether we need to route into this dimension or not.
    */
-  const unsigned int dsize = dimensions_.size();
+  const unsigned long dsize = dimensions_.size();
   std::vector<unsigned int> myCoords(dsize);
   std::vector<unsigned int> targetCoords(dsize);
   unsigned int dim_size_product = 1;
-  for (unsigned i = 0; i < dsize; i++) {
+  for (unsigned long i = 0; i < dsize; i++) {
     unsigned cur_dim_size = dimensions_[i];
     myCoords[i]           = (src->id() / dim_size_product) % cur_dim_size;
     targetCoords[i]       = (dst->id() / dim_size_product) % cur_dim_size;
@@ -171,7 +168,7 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
     }
 
     if (has_limiter()) { // limiter for sender
-      route->link_list.push_back(get_uplink_from(node_pos_with_loopback(current_node)));
+      route->link_list_.push_back(get_uplink_from(node_pos_with_loopback(current_node)));
     }
 
     resource::LinkImpl* lnk;
@@ -180,15 +177,18 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
     else
       lnk = get_downlink_to(linkOffset);
 
-    route->link_list.push_back(lnk);
+    route->link_list_.push_back(lnk);
     if (lat)
       *lat += lnk->get_latency();
 
     current_node = next_node;
   }
+  if (has_limiter()) { // limiter for receiver/destination
+    route->link_list_.push_back(get_downlink_to(node_pos_with_loopback(dst->id())));
+  }
   // set gateways (if any)
-  route->gw_src = get_gateway(src->id());
-  route->gw_dst = get_gateway(dst->id());
+  route->gw_src_ = get_gateway(src->id());
+  route->gw_dst_ = get_gateway(dst->id());
 }
 
 } // namespace routing
@@ -223,7 +223,7 @@ NetZone* create_torus_zone(const std::string& name, const NetZone* parent, const
     Link* loopback;
     zone->fill_leaf_from_cb(i, dimensions, set_callbacks, &netpoint, &loopback, &limiter);
 
-    zone->create_links(netpoint->id(), i, zone->node_pos_with_loopback_limiter(netpoint->id()));
+    zone->create_torus_links(netpoint->id(), i, zone->node_pos_with_loopback_limiter(netpoint->id()));
   }
 
   return zone->get_iface();