Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
vertices_ is now a vector in routing
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 18 Aug 2016 16:25:52 +0000 (18:25 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 18 Aug 2016 16:25:52 +0000 (18:25 +0200)
include/simgrid/s4u/As.hpp
src/kernel/routing/AsCluster.cpp
src/kernel/routing/AsFloyd.cpp
src/kernel/routing/AsFull.cpp
src/kernel/routing/AsRoutedGraph.cpp
src/s4u/s4u_as.cpp

index 50c485481467da397be7c68b55790ab34fdc31ff..852692c2611e005109844a5dff2d987a031c6ae0 100644 (file)
@@ -61,7 +61,7 @@ public:
 protected:
   char *name_ = nullptr;
   xbt_dict_t children_ = xbt_dict_new_homogeneous(nullptr); // sub-ASes
-  xbt_dynar_t vertices_ = xbt_dynar_new(sizeof(char*),nullptr); // our content, as known to our graph routing algorithm (maps vertexId -> vertex)
+  std::vector<kernel::routing::NetCard*>vertices_; // our content, as known to our graph routing algorithm (maps vertexId -> vertex)
 
   std::map<std::pair<std::string, std::string>, std::vector<surf::Link*>*> bypassRoutes_; // srcName x dstName -> route
 
index e85becf24c196286d0809b9de1e10c5496759b26..fd5f54064ea88192654aac019fc0341914e2ff78 100644 (file)
@@ -76,10 +76,6 @@ void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
 
 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
 {
-  int isrc;
-  int table_size = xbt_dynar_length(vertices_);
-
-  NetCard *src;
   xbt_node_t current, previous, backboneNode = nullptr, routerNode;
   s_surf_parsing_link_up_down_t info;
 
@@ -96,18 +92,14 @@ void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
   }
 
-  for (isrc = 0; isrc < table_size; isrc++) {
-    src = xbt_dynar_get_as(vertices_, isrc, NetCard*);
-
+  for (auto src: vertices_){
     if (! src->isRouter()) {
       previous = new_xbt_graph_node(graph, src->name(), nodes);
 
       info = xbt_dynar_get_as(privateLinks_, src->id(), s_surf_parsing_link_up_down_t);
 
       if (info.linkUp) {     // link up
-
-        const char *link_name = static_cast<simgrid::surf::Resource*>(
-          info.linkUp)->getName();
+        const char *link_name = static_cast<simgrid::surf::Resource*>(info.linkUp)->getName();
         current = new_xbt_graph_node(graph, link_name, nodes);
         new_xbt_graph_edge(graph, previous, current, edges);
 
@@ -116,7 +108,6 @@ void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
         } else {
           new_xbt_graph_edge(graph, current, routerNode, edges);
         }
-
       }
 
       if (info.linkDown) {    // link down
@@ -132,7 +123,6 @@ void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
         }
       }
     }
-
   }
 }
 
index 77047752fbd1a4b696c9f59112c0be8122c5824d..78d60e1db9c154db4c45087fe4fe1fcaa3006f26 100644 (file)
@@ -27,7 +27,7 @@ AsFloyd::AsFloyd(const char*name)
 }
 
 AsFloyd::~AsFloyd(){
-  int table_size = static_cast<int>(xbt_dynar_length(vertices_));
+  int table_size = static_cast<int>(vertices_.size());
   if (linkTable_ == nullptr) // Dealing with a parse error in the file?
     return;
   /* Delete link_table */
@@ -42,7 +42,7 @@ AsFloyd::~AsFloyd(){
 
 void AsFloyd::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
 {
-  size_t table_size = xbt_dynar_length(vertices_);
+  size_t table_size = vertices_.size();
 
   getRouteCheckParams(src, dst);
 
@@ -85,7 +85,7 @@ void AsFloyd::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbar
 void AsFloyd::addRoute(sg_platf_route_cbarg_t route)
 {
   /* set the size of table routing */
-  int table_size = static_cast<int>(xbt_dynar_length(vertices_));
+  int table_size = static_cast<int>(vertices_.size());
 
   addRouteCheckParams(route);
 
@@ -147,9 +147,8 @@ void AsFloyd::addRoute(sg_platf_route_cbarg_t route)
 }
 
 void AsFloyd::seal(){
-
   /* set the size of table routing */
-  size_t table_size = xbt_dynar_length(vertices_);
+  size_t table_size = vertices_.size();
 
   if(!linkTable_) {
     /* Create Cost, Predecessor and Link tables */
index e0b6cda7fe04145f114013a3fe57f041be9480a8..0b5807e4975f685645dc69d1777690dc334f95a8 100644 (file)
@@ -23,7 +23,7 @@ void AsFull::seal() {
   sg_platf_route_cbarg_t e_route;
 
   /* set utils vars */
-  int table_size = (int)xbt_dynar_length(vertices_);
+  int table_size = static_cast<int>(vertices_.size());
 
   /* Create table if necessary */
   if (!routingTable_)
@@ -47,11 +47,10 @@ void AsFull::seal() {
 
 AsFull::~AsFull(){
   if (routingTable_) {
-    int table_size = (int)xbt_dynar_length(vertices_);
-    int i, j;
+    int table_size = static_cast<int>(vertices_.size());
     /* Delete routing table */
-    for (i = 0; i < table_size; i++)
-      for (j = 0; j < table_size; j++) {
+    for (int i = 0; i < table_size; i++)
+      for (int j = 0; j < table_size; j++) {
         if (TO_ROUTE_FULL(i,j)){
           delete TO_ROUTE_FULL(i,j)->link_list;
           xbt_free(TO_ROUTE_FULL(i,j));
@@ -67,7 +66,7 @@ void AsFull::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg
       src->name(), src->id(), dst->name(), dst->id());
 
   /* set utils vars */
-  size_t table_size = xbt_dynar_length(vertices_);
+  size_t table_size = vertices_.size();
 
   sg_platf_route_cbarg_t e_route = nullptr;
 
@@ -93,7 +92,7 @@ void AsFull::addRoute(sg_platf_route_cbarg_t route)
 
   addRouteCheckParams(route);
 
-  size_t table_size = xbt_dynar_length(vertices_);
+  size_t table_size = vertices_.size();
 
   if (!routingTable_)
     routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
index b256dd00a018d8a58b01531780e5699cca8fc845..db43c0c237a77fe386c7c3b55d75e38d6d0c1b31 100644 (file)
@@ -31,10 +31,7 @@ AsRoutedGraph::AsRoutedGraph(const char*name)
 {
 }
 
-AsRoutedGraph::~AsRoutedGraph()
-{
-}
-
+AsRoutedGraph::~AsRoutedGraph()=default;
 
 }}} // namespace simgrid::kernel::routing
 
@@ -66,7 +63,6 @@ xbt_edge_t new_xbt_graph_edge(xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt
   int len = strlen(sn) + strlen(dn) + 1;
   char *name = (char *) xbt_malloc(len * sizeof(char));
 
-
   snprintf(name, len, "%s%s", sn, dn);
   xbt_edge_t ret = (xbt_edge_t) xbt_dict_get_or_null(edges, name);
   if (ret == nullptr) {
@@ -92,12 +88,12 @@ namespace routing {
     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 = (int)xbt_dynar_length(vertices_);
+    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 = xbt_dynar_get_as(vertices_, src, NetCard*);
-        NetCard *dst_elm = xbt_dynar_get_as(vertices_, dst, NetCard*);
+        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) {
@@ -118,18 +114,10 @@ namespace routing {
 
 void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
 {
-  int src, dst;
-  int table_size = xbt_dynar_length(vertices_);
-
-
-  for (src = 0; src < table_size; src++) {
-    NetCard *my_src =
-        xbt_dynar_get_as(vertices_, src, NetCard*);
-    for (dst = 0; dst < table_size; dst++) {
-      if (src == dst)
+  for (auto my_src: vertices_){
+    for (auto my_dst: vertices_){
+      if (my_src == my_dst)
         continue;
-      NetCard *my_dst =
-          xbt_dynar_get_as(vertices_, dst, NetCard*);
 
       sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
       route->link_list = new std::vector<Link*>();
@@ -175,7 +163,6 @@ void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edg
   }
 }
 
-
 /* ************************************************************************** */
 /* ************************* GENERIC AUX FUNCTIONS ************************** */
 /* change a route containing link names into a route containing link entities */
index 56864b5f473b0d7d86fe4df647e82a18cdce4adc..32d5eca29a90ec5f8ea700fa5a8f906808e2c62d 100644 (file)
@@ -36,7 +36,6 @@ namespace simgrid {
 
 
       xbt_dict_free(&children_);
-      xbt_dynar_free(&vertices_);
       for (auto &kv : bypassRoutes_)
         delete kv.second;
       xbt_free(name_);
@@ -58,9 +57,8 @@ namespace simgrid {
     {
       xbt_dynar_t res =  xbt_dynar_new(sizeof(sg_host_t), nullptr);
 
-      for (unsigned int index = 0; index < xbt_dynar_length(vertices_); index++) {
-        kernel::routing::NetCard *card = xbt_dynar_get_as(vertices_, index, kernel::routing::NetCard*);
-        s4u::Host                *host = simgrid::s4u::Host::by_name_or_null(card->name());
+      for (auto card : vertices_) {
+        s4u::Host *host = simgrid::s4u::Host::by_name_or_null(card->name());
         if (host!=nullptr)
           xbt_dynar_push(res, &host);
       }
@@ -68,8 +66,8 @@ namespace simgrid {
     }
 
     int As::addComponent(kernel::routing::NetCard *elm) {
-      xbt_dynar_push_as(vertices_, kernel::routing::NetCard*, elm);
-      return xbt_dynar_length(vertices_)-1;
+      vertices_.push_back(elm);
+      return vertices_.size()-1; //FIXME -1 ?
     }
 
     void As::addRoute(sg_platf_route_cbarg_t /*route*/){