Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use vector for privateLinks_
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 19 Aug 2016 07:25:45 +0000 (09:25 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 19 Aug 2016 07:25:45 +0000 (09:25 +0200)
 + fought hard against this one :/
 + emptty, have a look please

include/simgrid/s4u/As.hpp
src/kernel/routing/AsCluster.cpp
src/kernel/routing/AsCluster.hpp
src/kernel/routing/AsClusterDragonfly.cpp
src/kernel/routing/AsClusterTorus.cpp
src/kernel/routing/AsVivaldi.cpp
src/surf/sg_platf.cpp

index 852692c..7de5a36 100644 (file)
@@ -61,7 +61,7 @@ public:
 protected:
   char *name_ = nullptr;
   xbt_dict_t children_ = xbt_dict_new_homogeneous(nullptr); // sub-ASes
-  std::vector<kernel::routing::NetCard*>vertices_; // 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 fd5f540..94e2f14 100644 (file)
@@ -17,21 +17,18 @@ namespace routing {
   AsCluster::AsCluster(const char*name)
     : AsImpl(name)
   {}
-  AsCluster::~AsCluster()
-  {
-    xbt_dynar_free(&privateLinks_);
-  }
+  AsCluster::~AsCluster()=default;
 
 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
 {
   s_surf_parsing_link_up_down_t info;
   XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
             src->name(), src->id(), dst->name(), dst->id());
-  xbt_assert(!xbt_dynar_is_empty(privateLinks_), "Cluster routing : no links attached to the source node - did you use host_link tag?");
+  xbt_assert(!privateLinks_.empty(), "Cluster routing : no links attached to the source node - did you use host_link tag?");
   if (! src->isRouter()) {    // No specific link for router
 
     if((src->id() == dst->id()) && hasLoopback_ ){
-      info = xbt_dynar_get_as(privateLinks_, src->id() * linkCountPerNode_, s_surf_parsing_link_up_down_t);
+      info = privateLinks_.at(src->id() * linkCountPerNode_);
       route->link_list->push_back(info.linkUp);
       if (lat)
         *lat += info.linkUp->getLatency();
@@ -40,11 +37,11 @@ void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
 
 
     if (hasLimiter_){          // limiter for sender
-      info = xbt_dynar_get_as(privateLinks_, src->id() * linkCountPerNode_ + (hasLoopback_?1:0), s_surf_parsing_link_up_down_t);
+      info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_?1:0));
       route->link_list->push_back((Link*)info.linkUp);
     }
 
-    info = xbt_dynar_get_as(privateLinks_, src->id() * linkCountPerNode_ + (hasLoopback_?1:0) + (hasLimiter_?1:0), s_surf_parsing_link_up_down_t);
+    info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_?1:0) + (hasLimiter_?1:0));
     if (info.linkUp) {         // link up
       route->link_list->push_back(info.linkUp);
       if (lat)
@@ -60,7 +57,7 @@ void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
   }
 
   if (! dst->isRouter()) {    // No specific link for router
-    info = xbt_dynar_get_as(privateLinks_, dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_, s_surf_parsing_link_up_down_t);
+    info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_);
 
     if (info.linkDown) {       // link down
       route->link_list->push_back(info.linkDown);
@@ -68,7 +65,7 @@ void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
         *lat += info.linkDown->getLatency();
     }
     if (hasLimiter_){          // limiter for receiver
-        info = xbt_dynar_get_as(privateLinks_, dst->id() * linkCountPerNode_ + hasLoopback_, s_surf_parsing_link_up_down_t);
+        info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_);
         route->link_list->push_back(info.linkUp);
     }
   }
@@ -96,7 +93,7 @@ void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
     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);
+      info = privateLinks_.at(src->id());
 
       if (info.linkUp) {     // link up
         const char *link_name = static_cast<simgrid::surf::Resource*>(info.linkUp)->getName();
@@ -149,7 +146,7 @@ void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id,
     info.linkUp = Link::byName(link_id);
     info.linkDown = info.linkUp;
   }
-  xbt_dynar_set(privateLinks_, position, &info);
+  privateLinks_.insert(privateLinks_.begin()+position, info);
   xbt_free(link_id);
 }
 
index 7a8d4e3..013ca08 100644 (file)
@@ -23,7 +23,7 @@ public:
   virtual void create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position);
   virtual void parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) {}
 
-  xbt_dynar_t privateLinks_ = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),nullptr);
+  std::vector<s_surf_parsing_link_up_down_t> privateLinks_;
 
   Link* backbone_ = nullptr;
   void *loopback_ = nullptr;
index cec68d8..cfdb63a 100644 (file)
@@ -245,7 +245,7 @@ void AsClusterDragonfly::getRouteAndLatency(NetCard * src, NetCard * dst, sg_pla
   XBT_VERB("dragonfly_get_route_and_latency from '%s'[%d] to '%s'[%d]", src->name(), src->id(), dst->name(), dst->id());
 
   if ((src->id() == dst->id()) && hasLoopback_) {
-     s_surf_parsing_link_up_down_t info = xbt_dynar_get_as(privateLinks_, src->id() * linkCountPerNode_, s_surf_parsing_link_up_down_t);
+     s_surf_parsing_link_up_down_t info = privateLinks_.at(src->id() * linkCountPerNode_);
 
      route->link_list->push_back(info.linkUp);
      if (latency)
@@ -270,7 +270,7 @@ void AsClusterDragonfly::getRouteAndLatency(NetCard * src, NetCard * dst, sg_pla
 
   if (hasLimiter_) {    // limiter for sender
     s_surf_parsing_link_up_down_t info;
-    info = xbt_dynar_get_as(privateLinks_, src->id() * linkCountPerNode_ + hasLoopback_, s_surf_parsing_link_up_down_t);
+    info = privateLinks_.at(src->id() * linkCountPerNode_ + hasLoopback_);
     route->link_list->push_back(info.linkUp);
   }
 
@@ -327,7 +327,7 @@ void AsClusterDragonfly::getRouteAndLatency(NetCard * src, NetCard * dst, sg_pla
 
   if (hasLimiter_) {    // limiter for receiver
     s_surf_parsing_link_up_down_t info;
-    info = xbt_dynar_get_as(privateLinks_, dst->id() * linkCountPerNode_ + hasLoopback_, s_surf_parsing_link_up_down_t);
+    info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_);
     route->link_list->push_back(info.linkUp);
   }
 
index 55a4606..b88ed42 100644 (file)
@@ -78,7 +78,7 @@ namespace simgrid {
          * note that position rankId*(xbt_dynar_length(dimensions)+has_loopack?+has_limiter?)
          * holds the link "rankId->rankId"
          */
-        xbt_dynar_set(privateLinks_, position + j, &info);
+        privateLinks_.insert(privateLinks_.begin() + position + j, info);
         dim_product *= current_dimension;
         xbt_free(link_id);
       }
@@ -118,7 +118,7 @@ namespace simgrid {
         return;
 
       if ((src->id() == dst->id()) && hasLoopback_) {
-        s_surf_parsing_link_up_down_t info = xbt_dynar_get_as(privateLinks_, src->id() * linkCountPerNode_, s_surf_parsing_link_up_down_t);
+        s_surf_parsing_link_up_down_t info = privateLinks_.at(src->id() * linkCountPerNode_);
 
         route->link_list->push_back(info.linkUp);
         if (lat)
@@ -200,11 +200,11 @@ namespace simgrid {
         s_surf_parsing_link_up_down_t info;
 
         if (hasLimiter_) {    // limiter for sender
-          info = xbt_dynar_get_as(privateLinks_, nodeOffset + hasLoopback_, s_surf_parsing_link_up_down_t);
+          info = privateLinks_.at(nodeOffset + hasLoopback_);
           route->link_list->push_back(info.linkUp);
         }
 
-        info = xbt_dynar_get_as(privateLinks_, linkOffset, s_surf_parsing_link_up_down_t);
+        info = privateLinks_.at(linkOffset);
 
         if (use_lnk_up == false) {
           route->link_list->push_back(info.linkDown);
index c25b4e0..c922633 100644 (file)
@@ -68,16 +68,16 @@ void AsVivaldi::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
   }
 
   /* Retrieve the private links */
-  if ((int)xbt_dynar_length(privateLinks_) > src->id()) {
-    s_surf_parsing_link_up_down_t info = xbt_dynar_get_as(privateLinks_, src->id(), s_surf_parsing_link_up_down_t);
+  if (static_cast<int>(privateLinks_.size()) > src->id()) {
+    s_surf_parsing_link_up_down_t info = privateLinks_.at(src->id());
     if(info.linkUp) {
       route->link_list->push_back(info.linkUp);
       if (lat)
         *lat += info.linkUp->getLatency();
     }
   }
-  if ((int)xbt_dynar_length(privateLinks_)>dst->id()) {
-    s_surf_parsing_link_up_down_t info = xbt_dynar_get_as(privateLinks_, dst->id(), s_surf_parsing_link_up_down_t);
+  if (static_cast<int>(privateLinks_.size()) >dst->id()) {
+    s_surf_parsing_link_up_down_t info = privateLinks_.at(dst->id());
     if(info.linkDown) {
       route->link_list->push_back(info.linkDown);
       if (lat)
index 19d8243..b69168e 100644 (file)
@@ -310,7 +310,8 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
 
     XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id, cluster->bw, cluster->lat);
 
-    s_surf_parsing_link_up_down_t info_lim, info_loop;
+    s_surf_parsing_link_up_down_t info_lim;
+    s_surf_parsing_link_up_down_t info_loop;
     // All links are saved in a matrix;
     // every row describes a single node; every node may have multiple links.
     // the first column may store a link from x to x if p_has_loopback is set
@@ -328,10 +329,18 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
       link.latency   = cluster->loopback_lat;
       link.policy    = SURF_LINK_FATPIPE;
       sg_platf_new_link(&link);
-      info_loop.linkUp = info_loop.linkDown = Link::byName(tmp_link);
+      info_loop.linkUp = Link::byName(tmp_link);
+      info_loop.linkDown = Link::byName(tmp_link);
       free(tmp_link);
       auto as_cluster = static_cast<AsCluster*>(current_as);
-      xbt_dynar_set(as_cluster->privateLinks_, rankId*as_cluster->linkCountPerNode_, &info_loop);
+      if (rankId*as_cluster->linkCountPerNode_ >= static_cast<int>(as_cluster->privateLinks_.size())){
+        s_surf_parsing_link_up_down_t dummy;
+        dummy.linkUp = nullptr;
+        dummy.linkDown = nullptr;
+        as_cluster->privateLinks_.resize(rankId*as_cluster->linkCountPerNode_,dummy);
+      }
+      as_cluster->privateLinks_.insert(as_cluster->privateLinks_.begin() + rankId*as_cluster->linkCountPerNode_,
+                                       info_loop);
     }
 
     //add a limiter link (shared link to account for maximal bandwidth of the node)
@@ -347,7 +356,8 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
       sg_platf_new_link(&link);
       info_lim.linkUp = info_lim.linkDown = Link::byName(tmp_link);
       free(tmp_link);
-      xbt_dynar_set(current_as->privateLinks_, rankId * current_as->linkCountPerNode_ + current_as->hasLoopback_ , &info_lim);
+      current_as->privateLinks_.insert(current_as->privateLinks_.begin() + rankId * current_as->linkCountPerNode_ +
+                                       current_as->hasLoopback_ , info_lim);
     }
 
     //call the cluster function that adds the others links
@@ -903,10 +913,15 @@ void sg_platf_new_hostlink(sg_platf_host_link_cbarg_t hostlink)
 
   // If dynar is is greater than netcard id and if the host_link is already defined
   auto as_cluster = static_cast<simgrid::kernel::routing::AsCluster*>(current_routing);
-  if((int)xbt_dynar_length(as_cluster->privateLinks_) > netcard->id() &&
-      xbt_dynar_get_as(as_cluster->privateLinks_, netcard->id(), void*))
-  surf_parse_error("Host_link for '%s' is already defined!",hostlink->id);
-
+  if(static_cast<int>(as_cluster->privateLinks_.size()) > netcard->id()){
+    if (as_cluster->privateLinks_.at(netcard->id()).linkUp != nullptr)
+    surf_parse_error("Host_link for '%s' is already defined!",hostlink->id);
+  } else {
+    s_surf_parsing_link_up_down_t dummy;
+    dummy.linkUp = nullptr;
+    dummy.linkDown = nullptr;
+    as_cluster->privateLinks_.resize(netcard->id(), dummy);
+  }
   XBT_DEBUG("Push Host_link for host '%s' to position %d", netcard->name(), netcard->id());
-  xbt_dynar_set_as(as_cluster->privateLinks_, netcard->id(), s_surf_parsing_link_up_down_t, link_up_down);
+  as_cluster->privateLinks_.insert(as_cluster->privateLinks_.begin() + netcard->id(), link_up_down);
 }