Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reindent
[simgrid.git] / src / surf / surf_routing_cluster_fat_tree.cpp
index b4667dd..579e1e3 100644 (file)
@@ -6,7 +6,6 @@
 #include <vector>
 #include <iostream>
 
-#include "src/surf/surf_routing_private.hpp"
 #include "src/surf/surf_routing_cluster_fat_tree.hpp"
 #include "xbt/lib.h"
 
@@ -16,6 +15,9 @@
 #include <fstream>
 #include <sstream>
 
+#include "src/surf/xml/platf.hpp" // FIXME: move that back to the parsing area
+
+
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_fat_tree, surf, "Routing for fat trees");
 
 namespace simgrid {
@@ -64,7 +66,8 @@ void AsClusterFatTree::getRouteAndLatency(NetCard *src,
 
   std::map<int, FatTreeNode*>::const_iterator tempIter;
   
-if (dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_NETWORK_ELEMENT_ROUTER) return;
+  if (dst->isRouter() || src->isRouter())
+    return;
 
   /* Let's find the source and the destination in our internal structure */
   tempIter = this->computeNodes_.find(src->id());
@@ -90,7 +93,7 @@ if (dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_
   /* In case destination is the source, and there is a loopback, let's get
      through it instead of going up to a switch*/
   if(source->id == destination->id && this->has_loopback_) {
-    xbt_dynar_push_as(into->link_list, void*, source->loopback);
+    into->link_list->push_back(source->loopback);
     if(latency) {
       *latency += source->loopback->getLatency();
     }
@@ -109,14 +112,14 @@ if (dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_
     }
     k = this->upperLevelNodesNumber_[currentNode->level];
     d = d % k;
-    xbt_dynar_push_as(into->link_list, void*,currentNode->parents[d]->upLink);
+    into->link_list->push_back(currentNode->parents[d]->upLink);
 
     if(latency) {
       *latency += currentNode->parents[d]->upLink->getLatency();
     }
 
     if (this->has_limiter_) {
-      xbt_dynar_push_as(into->link_list, void*,currentNode->limiterLink);
+      into->link_list->push_back(currentNode->limiterLink);
     }
     currentNode = currentNode->parents[d]->upNode;
   }
@@ -130,13 +133,13 @@ if (dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_
     for(unsigned int i = 0 ; i < currentNode->children.size() ; i++) {
       if(i % this->lowerLevelNodesNumber_[currentNode->level - 1] ==
          destination->label[currentNode->level - 1]) {
-        xbt_dynar_push_as(into->link_list, void*,currentNode->children[i]->downLink);
+        into->link_list->push_back(currentNode->children[i]->downLink);
         if(latency) {
           *latency += currentNode->children[i]->downLink->getLatency();
         }
         currentNode = currentNode->children[i]->downNode;
         if (this->has_limiter_) {
-          xbt_dynar_push_as(into->link_list, void*,currentNode->limiterLink);
+          into->link_list->push_back(currentNode->limiterLink);
         }
         XBT_DEBUG("%d(%u,%u) is accessible through %d(%u,%u)", destination->id,
                   destination->level, destination->position, currentNode->id,
@@ -266,12 +269,10 @@ void AsClusterFatTree::generateSwitches() {
   this->nodesByLevel_.resize(this->levels_ + 1, 0);
   unsigned int nodesRequired = 0;
 
-  // We take care of the number of nodes by level
+  // Take care of the number of nodes by level
   this->nodesByLevel_[0] = 1;
-  for (unsigned int i = 0 ; i < this->levels_ ; i++) {
+  for (unsigned int i = 0 ; i < this->levels_ ; i++)
     this->nodesByLevel_[0] *= this->lowerLevelNodesNumber_[i];
-  }
-
      
   if(this->nodesByLevel_[0] != this->nodes_.size()) {
     surf_parse_error("The number of provided nodes does not fit with the wanted topology."
@@ -284,27 +285,23 @@ void AsClusterFatTree::generateSwitches() {
   for (unsigned int i = 0 ; i < this->levels_ ; i++) {
     int nodesInThisLevel = 1;
       
-    for (unsigned int j = 0 ;  j <= i ; j++) {
+    for (unsigned int j = 0 ;  j <= i ; j++)
       nodesInThisLevel *= this->upperLevelNodesNumber_[j];
-    }
       
-    for (unsigned int j = i+1 ; j < this->levels_ ; j++) {
+    for (unsigned int j = i+1 ; j < this->levels_ ; j++)
       nodesInThisLevel *= this->lowerLevelNodesNumber_[j];
-    }
 
     this->nodesByLevel_[i+1] = nodesInThisLevel;
     nodesRequired += nodesInThisLevel;
   }
 
 
-  // We create the switches
+  // Create the switches
   int k = 0;
   for (unsigned int i = 0 ; i < this->levels_ ; i++) {
     for (unsigned int j = 0 ; j < this->nodesByLevel_[i + 1] ; j++) {
-      FatTreeNode* newNode;
-      newNode = new FatTreeNode(this->cluster_, --k, i + 1, j);
-      XBT_DEBUG("We create the switch %d(%d,%d)", newNode->id, newNode->level,
-                newNode->position);
+      FatTreeNode* newNode = new FatTreeNode(this->cluster_, --k, i + 1, j);
+      XBT_DEBUG("We create the switch %d(%d,%d)", newNode->id, newNode->level, newNode->position);
       newNode->children.resize(this->lowerLevelNodesNumber_[i] *
                                this->lowerLevelPortsNumber_[i]);
       if (i != this->levels_ - 1) {
@@ -346,27 +343,19 @@ void AsClusterFatTree::generateLabels() {
       this->nodes_[k]->label.assign(currentLabel.begin(), currentLabel.end());
 
       bool remainder = true;
-      
       unsigned int pos = 0;
-      do {
-        std::stringstream msgBuffer;
-
+      while (remainder && pos < this->levels_) {
         ++currentLabel[pos];
         if (currentLabel[pos] >= maxLabel[pos]) {
           currentLabel[pos] = 0;
           remainder = true;
+          ++pos;
         }
         else {
-          remainder = false;
-        }
-        if (!remainder) {
           pos = 0;
-        }
-        else {
-          ++pos;
+          remainder = false;
         }
       }
-      while(remainder && pos < this->levels_);
       k++;
     }
   }
@@ -374,16 +363,13 @@ void AsClusterFatTree::generateLabels() {
 
 
 int AsClusterFatTree::getLevelPosition(const unsigned  int level) {
-  if (level > this->levels_) {
-    // Well, that should never happen. Maybe should we throw instead.
-    return -1;
-  }
+  xbt_assert(level <= this->levels_, "The impossible did happen. Yet again.");
   int tempPosition = 0;
 
-  for (unsigned int i = 0 ; i < level ; i++) {
+  for (unsigned int i = 0 ; i < level ; i++)
     tempPosition += this->nodesByLevel_[i];
-  }
- return tempPosition;
+
 return tempPosition;
 }
 
 void AsClusterFatTree::addProcessingNode(int id) {
@@ -402,29 +388,22 @@ void AsClusterFatTree::addLink(FatTreeNode *parent, unsigned int parentPort,
                                FatTreeNode *child, unsigned int childPort) {
   FatTreeLink *newLink;
   newLink = new FatTreeLink(this->cluster_, child, parent);
-  XBT_DEBUG("Creating a link between the parent (%d,%d,%u)"
-            " and the child (%d,%d,%u)", parent->level, parent->position,
-            parentPort, child->level, child->position, childPort);
+  XBT_DEBUG("Creating a link between the parent (%d,%d,%u) and the child (%d,%d,%u)",
+      parent->level, parent->position, parentPort, child->level, child->position, childPort);
   parent->children[parentPort] = newLink;
   child->parents[childPort] = newLink;
 
   this->links_.push_back(newLink);
-
-  
-
 }
 
-void AsClusterFatTree::parse_specific_arguments(sg_platf_cluster_cbarg_t 
-                                                cluster) {
+void AsClusterFatTree::parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) {
   std::vector<std::string> parameters;
   std::vector<std::string> tmp;
   boost::split(parameters, cluster->topo_parameters, boost::is_any_of(";"));
 
   // TODO : we have to check for zeros and negative numbers, or it might crash
   if (parameters.size() != 4){
-    surf_parse_error("Fat trees are defined by the levels number and 3 vectors" 
-                     ", see the documentation for more informations");
+    surf_parse_error("Fat trees are defined by the levels number and 3 vectors, see the documentation for more informations");
   }
 
   // The first parts of topo_parameters should be the levels number
@@ -466,36 +445,26 @@ void AsClusterFatTree::parse_specific_arguments(sg_platf_cluster_cbarg_t
 
 void AsClusterFatTree::generateDotFile(const std::string& filename) const {
   std::ofstream file;
-  /* Maybe should we get directly a char*, as open takes strings only beginning
-   * with C++11...
-   */
-  file.open(filename.c_str(), std::ios::out | std::ios::trunc); 
-  
-  if(file.is_open()) {
-    file << "graph AsClusterFatTree {\n";
-    for (unsigned int i = 0 ; i < this->nodes_.size() ; i++) {
-      file << this->nodes_[i]->id;
-      if(this->nodes_[i]->id < 0) {
-        file << " [shape=circle];\n";
-      }
-      else {
-        file << " [shape=hexagon];\n";
-      }
-    }
+  file.open(filename, std::ios::out | std::ios::trunc);
+  xbt_assert(file.is_open(), "Unable to open file %s", filename.c_str());
 
-    for (unsigned int i = 0 ; i < this->links_.size() ; i++ ) {
-      file << this->links_[i]->downNode->id
-             << " -- "
-           << this->links_[i]->upNode->id
-             << ";\n";
-    }
-    file << "}";
-    file.close();
+  file << "graph AsClusterFatTree {\n";
+  for (unsigned int i = 0 ; i < this->nodes_.size() ; i++) {
+    file << this->nodes_[i]->id;
+    if(this->nodes_[i]->id < 0)
+      file << " [shape=circle];\n";
+    else
+      file << " [shape=hexagon];\n";
   }
-  else {
-    XBT_DEBUG("Unable to open file %s", filename.c_str());
-    return;
+
+  for (unsigned int i = 0 ; i < this->links_.size() ; i++ ) {
+    file << this->links_[i]->downNode->id
+        << " -- "
+        << this->links_[i]->upNode->id
+        << ";\n";
   }
+  file << "}";
+  file.close();
 }
 
 FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level,
@@ -506,7 +475,6 @@ FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level,
     memset(&linkTemplate, 0, sizeof(linkTemplate));
     linkTemplate.bandwidth = cluster->limiter_link;
     linkTemplate.latency = 0;
-    linkTemplate.initiallyOn = 1;
     linkTemplate.policy = SURF_LINK_SHARED;
     linkTemplate.id = bprintf("limiter_%d", id);
     sg_platf_new_link(&linkTemplate);
@@ -517,7 +485,6 @@ FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level,
     memset(&linkTemplate, 0, sizeof(linkTemplate));
     linkTemplate.bandwidth = cluster->loopback_bw;
     linkTemplate.latency = cluster->loopback_lat;
-    linkTemplate.initiallyOn = 1;
     linkTemplate.policy = SURF_LINK_FATPIPE;
     linkTemplate.id = bprintf("loopback_%d", id);
     sg_platf_new_link(&linkTemplate);
@@ -535,7 +502,6 @@ FatTreeLink::FatTreeLink(sg_platf_cluster_cbarg_t cluster,
   memset(&linkTemplate, 0, sizeof(linkTemplate));
   linkTemplate.bandwidth = cluster->bw;
   linkTemplate.latency = cluster->lat;
-  linkTemplate.initiallyOn = 1;
   linkTemplate.policy = cluster->sharing_policy; // sthg to do with that ?
   linkTemplate.id = bprintf("link_from_%d_to_%d_%d", downNode->id, upNode->id,
                             uniqueId);