Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the amount of dynars created by getOneLinkRoutes()
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Nov 2016 23:02:38 +0000 (00:02 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Nov 2016 23:02:38 +0000 (00:02 +0100)
src/kernel/routing/AsImpl.cpp
src/kernel/routing/AsImpl.hpp
src/kernel/routing/AsRoutedGraph.cpp
src/kernel/routing/AsRoutedGraph.hpp
src/kernel/routing/AsVivaldi.hpp
src/surf/surf_routing.cpp

index 3bd9c9e..33688ac 100644 (file)
@@ -41,9 +41,8 @@ namespace simgrid {
     return res;
   }
 
     return res;
   }
 
-  xbt_dynar_t AsImpl::getOneLinkRoutes()
+  void AsImpl::getOneLinkRoutes(xbt_dynar_t accumulator)
   {
   {
-    return nullptr;
   }
 
   /** @brief Get the common ancestor and its first children in each line leading to src and dst
   }
 
   /** @brief Get the common ancestor and its first children in each line leading to src and dst
index 8530695..dd3b26d 100644 (file)
@@ -59,7 +59,7 @@ public:
    */
   virtual void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency)=0;
   /** @brief retrieves the list of all routes of size 1 (of type src x dst x Link) */
    */
   virtual void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency)=0;
   /** @brief retrieves the list of all routes of size 1 (of type src x dst x Link) */
-  virtual xbt_dynar_t getOneLinkRoutes();
+  virtual void getOneLinkRoutes(xbt_dynar_t accumulator);
   /* returns whether we found a bypass path */
   bool getBypassRoute(routing::NetCard * src, routing::NetCard * dst,
                       /* OUT */ std::vector<surf::Link*> * links, double* latency);
   /* returns whether we found a bypass path */
   bool getBypassRoute(routing::NetCard * src, routing::NetCard * dst,
                       /* OUT */ std::vector<surf::Link*> * links, double* latency);
index a574eca..b45087f 100644 (file)
@@ -81,34 +81,32 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
 namespace kernel {
 namespace routing {
 
-  xbt_dynar_t AsRoutedGraph::getOneLinkRoutes()
-  {
-    xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
-    sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
-    route->link_list = new std::vector<Link*>();
-
-    int table_size = static_cast<int>(vertices_.size());
-    for(int src=0; src < table_size; src++) {
-      for(int dst=0; dst< table_size; dst++) {
-        route->link_list->clear();
-        NetCard *src_elm = vertices_.at(src);
-        NetCard *dst_elm = vertices_.at(dst);
-        this->getRouteAndLatency(src_elm, dst_elm,route, nullptr);
-
-        if (route->link_list->size() == 1) {
-          Link *link = route->link_list->at(0);
-          Onelink *onelink;
-          if (hierarchy_ == RoutingMode::base)
-            onelink = new Onelink(link, src_elm, dst_elm);
-          else if (hierarchy_ == RoutingMode::recursive)
-            onelink = new Onelink(link, route->gw_src, route->gw_dst);
-          else
-            onelink = new Onelink(link, nullptr, nullptr);
-          xbt_dynar_push(ret, &onelink);
-        }
+void AsRoutedGraph::getOneLinkRoutes(xbt_dynar_t accumulator)
+{
+  sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
+  route->link_list             = new std::vector<Link*>();
+
+  int table_size = static_cast<int>(vertices_.size());
+  for (int src = 0; src < table_size; src++) {
+    for (int dst = 0; dst < table_size; dst++) {
+      route->link_list->clear();
+      NetCard* src_elm = vertices_.at(src);
+      NetCard* dst_elm = vertices_.at(dst);
+      this->getRouteAndLatency(src_elm, dst_elm, route, nullptr);
+
+      if (route->link_list->size() == 1) {
+        Link* link = route->link_list->at(0);
+        Onelink* onelink;
+        if (hierarchy_ == RoutingMode::base)
+          onelink = new Onelink(link, src_elm, dst_elm);
+        else if (hierarchy_ == RoutingMode::recursive)
+          onelink = new Onelink(link, route->gw_src, route->gw_dst);
+        else
+          onelink = new Onelink(link, nullptr, nullptr);
+        xbt_dynar_push(accumulator, &onelink);
       }
     }
       }
     }
-    return ret;
+  }
   }
 
 void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
   }
 
 void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
index 9990166..7dd239c 100644 (file)
@@ -17,7 +17,7 @@ public:
   explicit AsRoutedGraph(As* father, const char* name);
   ~AsRoutedGraph() override;
 
   explicit AsRoutedGraph(As* father, const char* name);
   ~AsRoutedGraph() override;
 
-  xbt_dynar_t getOneLinkRoutes() override;
+  void getOneLinkRoutes(xbt_dynar_t accumulator) override;
 
   void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) override;
   virtual sg_platf_route_cbarg_t newExtendedRoute(RoutingMode hierarchy, sg_platf_route_cbarg_t routearg, int change_order);
 
   void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) override;
   virtual sg_platf_route_cbarg_t newExtendedRoute(RoutingMode hierarchy, sg_platf_route_cbarg_t routearg, int change_order);
index 65f4d52..42f3372 100644 (file)
@@ -18,7 +18,6 @@ public:
   explicit AsVivaldi(As* father, const char* name);
   ~AsVivaldi() override;
 
   explicit AsVivaldi(As* father, const char* name);
   ~AsVivaldi() override;
 
-  xbt_dynar_t getOneLinkRoutes() override {return nullptr;};
   void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override;
 };
 
   void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency) override;
 };
 
index aa86759..596ccee 100644 (file)
@@ -100,29 +100,24 @@ void RoutingPlatf::getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Li
   AsImpl::getRouteRecursive(src, dst, route, latency);
 }
 
   AsImpl::getRouteRecursive(src, dst, route, latency);
 }
 
-static xbt_dynar_t _recursiveGetOneLinkRoutes(AsImpl *as)
+static void _recursiveGetOneLinkRoutes(AsImpl* as, xbt_dynar_t accumulator)
 {
 {
-  xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
-
   //adding my one link routes
   //adding my one link routes
-  xbt_dynar_t onelink_mine = as->getOneLinkRoutes();
-  if (onelink_mine)
-    xbt_dynar_merge(&ret,&onelink_mine);
+  as->getOneLinkRoutes(accumulator);
 
   //recursing
   char *key;
   xbt_dict_cursor_t cursor = nullptr;
   AsImpl *rc_child;
   xbt_dict_foreach(as->children(), cursor, key, rc_child) {
 
   //recursing
   char *key;
   xbt_dict_cursor_t cursor = nullptr;
   AsImpl *rc_child;
   xbt_dict_foreach(as->children(), cursor, key, rc_child) {
-    xbt_dynar_t onelink_child = _recursiveGetOneLinkRoutes(rc_child);
-    if (onelink_child)
-      xbt_dynar_merge(&ret,&onelink_child);
+    _recursiveGetOneLinkRoutes(rc_child, accumulator);
   }
   }
-  return ret;
 }
 
 xbt_dynar_t RoutingPlatf::getOneLinkRoutes(){
 }
 
 xbt_dynar_t RoutingPlatf::getOneLinkRoutes(){
-  return _recursiveGetOneLinkRoutes(root_);
+  xbt_dynar_t res = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
+  _recursiveGetOneLinkRoutes(root_, res);
+  return res;
 }
 
 }}}
 }
 
 }}}