Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
s/NULL/nullptr/ in our C++ codebase
[simgrid.git] / src / surf / AsClusterDragonfly.cpp
index 3844806..e3eff8c 100644 (file)
@@ -14,12 +14,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster_dragonfly, surf_route_cluster
 
 
 
-
-
-
-
 namespace simgrid {
-namespace surf {
+namespace routing {
 
 AsClusterDragonfly::AsClusterDragonfly(const char*name)
   : AsCluster(name) {
@@ -27,8 +23,8 @@ AsClusterDragonfly::AsClusterDragonfly(const char*name)
 
 AsClusterDragonfly::~AsClusterDragonfly() {
 
-  if(this->routers_!=NULL){
-    int i;
+  if(this->routers_!=nullptr){
+    unsigned int i;
     for (i=0; i<this->numGroups_*this->numChassisPerGroup_*this->numBladesPerChassis_;i++)
         delete(routers_[i]);
     xbt_free(routers_);
@@ -113,13 +109,13 @@ DragonflyRouter::DragonflyRouter(int group, int chassis, int blade){
 }
 
 DragonflyRouter::~DragonflyRouter(){
-  if(this->myNodes_!=NULL)
+  if(this->myNodes_!=nullptr)
     xbt_free(myNodes_);
-  if(this->greenLinks_!=NULL)
+  if(this->greenLinks_!=nullptr)
     xbt_free(greenLinks_);
-  if(this->blackLinks_!=NULL)
+  if(this->blackLinks_!=nullptr)
     xbt_free(blackLinks_);
-  if(this->blueLinks_!=NULL)
+  if(this->blueLinks_!=nullptr)
     xbt_free(blueLinks_);
 }
 
@@ -142,12 +138,12 @@ for(i=0;i<this->numGroups_;i++){
 }
 
 
-void AsClusterDragonfly::createLink(char* id, Link** linkup, Link** linkdown){
-  *linkup=NULL;
-  *linkdown=NULL;
+void AsClusterDragonfly::createLink(char* id, int numlinks, Link** linkup, Link** linkdown){
+  *linkup=nullptr;
+  *linkdown=nullptr;
   s_sg_platf_link_cbarg_t linkTemplate;
   memset(&linkTemplate, 0, sizeof(linkTemplate));
-  linkTemplate.bandwidth = this->cluster_->bw;
+  linkTemplate.bandwidth = this->cluster_->bw * numlinks;
   linkTemplate.latency = this->cluster_->lat;
   linkTemplate.policy = this->cluster_->sharing_policy; // sthg to do with that ?
   linkTemplate.id = id;
@@ -175,28 +171,27 @@ void AsClusterDragonfly::createLink(char* id, Link** linkup, Link** linkdown){
 
 void AsClusterDragonfly::generateLinks() {
 
-  unsigned int i, j, k, l,m;
+  unsigned int i, j, k, l;
   static int uniqueId = 0;
-  char* id = NULL;
+  char* id = nullptr;
   Link* linkup, *linkdown;
 
-  int numRouters = this->numGroups_*this->numChassisPerGroup_*this->numBladesPerChassis_;
+  unsigned int numRouters = this->numGroups_*this->numChassisPerGroup_*this->numBladesPerChassis_;
 
-  int numLinksperLink=1;
   if (this->cluster_->sharing_policy == SURF_LINK_FULLDUPLEX)
-    numLinksperLink=2;
+    numLinksperLink_=2;
 
 
   //Links from routers to their local nodes.
   for(i=0; i<numRouters;i++){
   //allocate structures
-    this->routers_[i]->myNodes_=(Link**)xbt_malloc0(numLinksperLink*this->numNodesPerBlade_*sizeof(Link*));
-    this->routers_[i]->greenLinks_=(Link**)xbt_malloc0(this->numLinksGreen_*this->numBladesPerChassis_*sizeof(Link*));
-    this->routers_[i]->blackLinks_=(Link**)xbt_malloc0(this->numLinksBlack_*this->numChassisPerGroup_*sizeof(Link*));
+    this->routers_[i]->myNodes_=(Link**)xbt_malloc0(numLinksperLink_*this->numNodesPerBlade_*sizeof(Link*));
+    this->routers_[i]->greenLinks_=(Link**)xbt_malloc0(this->numBladesPerChassis_*sizeof(Link*));
+    this->routers_[i]->blackLinks_=(Link**)xbt_malloc0(this->numChassisPerGroup_*sizeof(Link*));
 
-    for(j=0; j< numLinksperLink*this->numNodesPerBlade_; j+=numLinksperLink){
-      id = bprintf("local_link_from_router_%d_to_node_%d_%d", i, j/2, uniqueId);
-      this->createLink(id, &linkup, &linkdown);
+    for(j=0; j< numLinksperLink_*this->numNodesPerBlade_; j+=numLinksperLink_){
+      id = bprintf("local_link_from_router_%d_to_node_%d_%d", i, j/numLinksperLink_, uniqueId);
+      this->createLink(id, 1, &linkup, &linkdown);
       if (this->cluster_->sharing_policy == SURF_LINK_FULLDUPLEX) {
         this->routers_[i]->myNodes_[j] = linkup; 
         this->routers_[i]->myNodes_[j+1] = linkdown; 
@@ -212,13 +207,11 @@ void AsClusterDragonfly::generateLinks() {
   for(i=0; i<this->numGroups_*this->numChassisPerGroup_;i++){
     for(j=0; j<this->numBladesPerChassis_;j++){
       for(k=j+1;k<this->numBladesPerChassis_;k++){
-        for(l=0;l<this->numLinksGreen_;l++){
-          id = bprintf("green_link_in_chassis_%d_between_routers_%d_and_%d_%d", i%numChassisPerGroup_, j, k, uniqueId);
-          this->createLink(id, &linkup, &linkdown);
-          this->routers_[i*numBladesPerChassis_+j]->greenLinks_[k*this->numLinksGreen_+l] = linkup;
-          this->routers_[i*numBladesPerChassis_+k]->greenLinks_[j*this->numLinksGreen_+l] = linkdown; 
-          uniqueId++;
-        }
+        id = bprintf("green_link_in_chassis_%d_between_routers_%d_and_%d_%d", i%numChassisPerGroup_, j, k, uniqueId);
+        this->createLink(id, this->numLinksGreen_, &linkup, &linkdown);
+        this->routers_[i*numBladesPerChassis_+j]->greenLinks_[k] = linkup;
+        this->routers_[i*numBladesPerChassis_+k]->greenLinks_[j] = linkdown; 
+        uniqueId++;
       }
     }
   }
@@ -228,35 +221,30 @@ void AsClusterDragonfly::generateLinks() {
     for(j=0; j<this->numChassisPerGroup_;j++){
       for(k=j+1;k<this->numChassisPerGroup_;k++){
         for(l=0;l<this->numBladesPerChassis_;l++){
-          for(m=0;m<this->numLinksBlack_;m++){
-
-            id = bprintf("black_link_in_group_%d_between_chassis_%d_and_%d_blade_%d_%d", i, j, k,l, uniqueId);
-            this->createLink(id, &linkup, &linkdown);
-            this->routers_[i*numBladesPerChassis_*numChassisPerGroup_+j*numBladesPerChassis_+l]->blackLinks_[k*this->numLinksBlack_+m] = linkup;
-            this->routers_[i*numBladesPerChassis_*numChassisPerGroup_+k*numBladesPerChassis_+l]->blackLinks_[j*this->numLinksBlack_+m] = linkdown; 
-            uniqueId++;
-          }
+          id = bprintf("black_link_in_group_%d_between_chassis_%d_and_%d_blade_%d_%d", i, j, k,l, uniqueId);
+          this->createLink(id, this->numLinksBlack_,&linkup, &linkdown);
+          this->routers_[i*numBladesPerChassis_*numChassisPerGroup_+j*numBladesPerChassis_+l]->blackLinks_[k] = linkup;
+          this->routers_[i*numBladesPerChassis_*numChassisPerGroup_+k*numBladesPerChassis_+l]->blackLinks_[j] = linkdown; 
+          uniqueId++;
         }
       }
     }
   }
 
 
-  //Blue links betweeen groups - Not all routers involved, only one per group is linked to others. Let's say router n of each group is linked to group n. FIXME: this limits the number of groups
-
+  //Blue links betweeen groups - Not all routers involved, only one per group is linked to others. Let's say router n of each group is linked to group n. 
+//FIXME: in reality blue links may be attached to several different routers
   for(i=0; i<this->numGroups_;i++){
     for(j=i+1; j<this->numGroups_;j++){
       unsigned int routernumi=i*numBladesPerChassis_*numChassisPerGroup_+j;
       unsigned int routernumj=j*numBladesPerChassis_*numChassisPerGroup_+i;
-      this->routers_[routernumi]->blueLinks_=(Link**)xbt_malloc0(this->numLinksBlue_*sizeof(Link*));
-      this->routers_[routernumj]->blueLinks_=(Link**)xbt_malloc0(this->numLinksBlue_*sizeof(Link*));
-      for(m=0;m<this->numLinksBlue_;m++){
+      this->routers_[routernumi]->blueLinks_=(Link**)xbt_malloc0(sizeof(Link*));
+      this->routers_[routernumj]->blueLinks_=(Link**)xbt_malloc0(sizeof(Link*));
         id = bprintf("blue_link_between_group_%d_and_%d_routers_%d_and_%d_%d", i, j, routernumi,routernumj, uniqueId);
-        this->createLink(id, &linkup, &linkdown);
-        this->routers_[routernumi]->blueLinks_[m] = linkup;
-        this->routers_[routernumj]->blueLinks_[m] = linkdown; 
+        this->createLink(id, this->numLinksBlue_, &linkup, &linkdown);
+        this->routers_[routernumi]->blueLinks_[0] = linkup;
+        this->routers_[routernumj]->blueLinks_[0] = linkdown; 
         uniqueId++;
-      }
     }
   }
 }
@@ -265,21 +253,22 @@ void AsClusterDragonfly::generateLinks() {
 void AsClusterDragonfly::getRouteAndLatency(NetCard * src, NetCard * dst, sg_platf_route_cbarg_t route, double *latency) {
 
   //Minimal routing version.
+  // TODO : non-minimal random one, and adaptive ?
 
   if (dst->isRouter() || src->isRouter())
     return;
-  //TODO:loopback and limiters
-      XBT_VERB("dragonfly_get_route_and_latency from '%s'[%d] to '%s'[%d]",
+
+  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);
+  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);
 
-//        route->link_list->push_back(info.linkUp);
-//        if (lat)
-//          *lat += info.linkUp->getLatency();
-//        return;
-//      }
+     route->link_list->push_back(info.linkUp);
+     if (latency)
+       *latency += info.linkUp->getLatency();
+     return;
+  }
 
   unsigned int *myCoords, *targetCoords;
   myCoords = rankId_to_coords(src->id());
@@ -292,14 +281,17 @@ void AsClusterDragonfly::getRouteAndLatency(NetCard * src, NetCard * dst, sg_pla
   DragonflyRouter* currentRouter=myRouter;
 
   //node->router local link
-  route->link_list->push_back(myRouter->myNodes_[myCoords[3]]);
+  route->link_list->push_back(myRouter->myNodes_[myCoords[3]*numLinksperLink_]);
   if(latency) {
-    *latency += myRouter->myNodes_[myCoords[3]]->getLatency();
+    *latency += myRouter->myNodes_[myCoords[3]*numLinksperLink_]->getLatency();
+  }
+
+  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);
+    route->link_list->push_back(info.linkUp);
   }
 
-if (src->id() == dst->id()){
-return;
-}
   if(targetRouter!=myRouter){
 
     //are we on a different group ?
@@ -307,17 +299,15 @@ return;
       //go to the router of our group connected to this one.
       if(currentRouter->blade_!=targetCoords[0]){
         //go to the nth router in our chassis
-//TODO : randomize used green link
-        route->link_list->push_back(currentRouter->greenLinks_[targetCoords[0]*numLinksGreen_]);
+        route->link_list->push_back(currentRouter->greenLinks_[targetCoords[0]]);
         if(latency) {
-          *latency += currentRouter->greenLinks_[targetCoords[0]*numLinksGreen_]->getLatency();
+          *latency += currentRouter->greenLinks_[targetCoords[0]]->getLatency();
         }
         currentRouter=routers_[myCoords[0]*(numChassisPerGroup_*numBladesPerChassis_)+myCoords[1] * numBladesPerChassis_+targetCoords[0]];
       }
 
       if(currentRouter->chassis_!=0){
         //go to the first chassis of our group
-//TODO : randomize used black link
         route->link_list->push_back(currentRouter->blackLinks_[0]);
         if(latency) {
           *latency += currentRouter->blackLinks_[0]->getLatency();
@@ -325,7 +315,6 @@ return;
         currentRouter=routers_[myCoords[0]*(numChassisPerGroup_*numBladesPerChassis_)+targetCoords[0]];
       }
 
-//TODO : randomize used blue link
       //go to destination group - the only optical hop 
       route->link_list->push_back(currentRouter->blueLinks_[0]);
       if(latency) {
@@ -335,34 +324,35 @@ return;
     }
 
     
-    //same group, but same chassis ?
-    if(targetRouter->chassis_ != currentRouter->chassis_){
-//TODO : randomize used black link
-      route->link_list->push_back(currentRouter->blackLinks_[targetCoords[1]*numLinksBlack_]);
+    //same group, but same blade ?
+    if(targetRouter->blade_ != currentRouter->blade_){
+      route->link_list->push_back(currentRouter->greenLinks_[targetCoords[2]]);
       if(latency) {
-        *latency += currentRouter->blackLinks_[targetCoords[1]*numLinksBlack_]->getLatency();
+        *latency += currentRouter->greenLinks_[targetCoords[2]]->getLatency();
       }
-      currentRouter=routers_[targetCoords[0]*(numChassisPerGroup_*numBladesPerChassis_)+currentRouter->chassis_*numBladesPerChassis_+currentRouter->blade_];
+      currentRouter=routers_[targetCoords[0]*(numChassisPerGroup_*numBladesPerChassis_)+targetCoords[2]];
     }
 
-    //same chassis, but same blade ?
-    if(targetRouter->blade_ != currentRouter->blade_){
-//TODO : randomize used green link
-      route->link_list->push_back(currentRouter->greenLinks_[targetCoords[2]*numLinksGreen_]);
+    //same blade, but same chassis ?
+    if(targetRouter->chassis_ != currentRouter->chassis_){
+      route->link_list->push_back(currentRouter->blackLinks_[targetCoords[1]]);
       if(latency) {
-        *latency += currentRouter->greenLinks_[targetCoords[2]*numLinksGreen_]->getLatency();
+        *latency += currentRouter->blackLinks_[targetCoords[1]]->getLatency();
       }
       currentRouter=routers_[targetCoords[0]*(numChassisPerGroup_*numBladesPerChassis_)+targetCoords[1]*numBladesPerChassis_+targetCoords[2]];
-    xbt_assert(currentRouter==targetRouter, "You've got routed into oblivion. Oops");
     }
   }
 
+  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);
+    route->link_list->push_back(info.linkUp);
+  }
 
   //router->node local link
-  route->link_list->push_back(targetRouter->myNodes_[targetCoords[3]]);
+  route->link_list->push_back(targetRouter->myNodes_[targetCoords[3]*numLinksperLink_+numLinksperLink_-1]);
   if(latency) {
-    *latency += targetRouter->myNodes_[targetCoords[3]]->getLatency();
+    *latency += targetRouter->myNodes_[targetCoords[3]*numLinksperLink_+numLinksperLink_-1]->getLatency();
   }
 
   xbt_free(myCoords);