Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
generateDotFile, to generate dot files for fat trees
[simgrid.git] / src / surf / surf_routing_cluster_fat_tree.cpp
index 309a9fa..5057c98 100644 (file)
@@ -18,7 +18,7 @@ AsClusterFatTree::~AsClusterFatTree() {
 void AsClusterFatTree::getRouteAndLatency(RoutingEdgePtr src,
                                           RoutingEdgePtr dst,
                                           sg_platf_route_cbarg_t into,
-                                          double *latency) const{
+                                          double *latency) {
   // TODO
 }
 
@@ -34,14 +34,14 @@ void AsClusterFatTree::create_links(sg_platf_cluster_cbarg_t cluster) {
   unsigned int nodesRequired = 0;
 
 
-    for (int i = 0 ; i < this->levels ; i++) {
+    for (unsigned int i = 0 ; i < this->levels ; i++) {
       int nodesInThisLevel = 1;
       
-      for (int j = 0 ;  j < i ; j++) {
+      for (unsigned int j = 0 ;  j < i ; j++) {
         nodesInThisLevel *= this->upperLevelNodesNumber[j];
       }
       
-      for (int j = i+1 ; j < this->levels ; j++) {
+      for (unsigned int j = i+1 ; j < this->levels ; j++) {
         nodesInThisLevel *= this->lowerLevelNodesNumber[j];
       }
 
@@ -58,17 +58,16 @@ void AsClusterFatTree::create_links(sg_platf_cluster_cbarg_t cluster) {
 
     // Nodes are totally ordered, by level and then by position, in this->nodes
     int k = 0;
-    for (int i = 0 ; i < this->levels ; i++) {
-      for (int j = 0 ; j < this->nodesByLevel[i] ; j++) {
+    for (unsigned int i = 0 ; i < this->levels ; i++) {
+      for (unsigned int j = 0 ; j < this->nodesByLevel[i] ; j++) {
         this->nodes[k]->level = i;
         this->nodes[k]->position = j;
       }
     }
-
     
 }
 
-void AsClusterFatTree::getLevelPosition(const int level, int &position, int &size) {
+void AsClusterFatTree::getLevelPosition(const unsigned  int level, int &position, int &size) {
   if (level > this->levels - 1) {
     position = -1;
     size =  -1;
@@ -76,7 +75,7 @@ void AsClusterFatTree::getLevelPosition(const int level, int &position, int &siz
   }
   int tempPosition = 0;
 
-  for (int i = 0 ; i < level ; i++) {
+  for (unsigned int i = 0 ; i < level ; i++) {
     tempPosition += this->nodesByLevel[i];
   }
   position = tempPosition;
@@ -84,15 +83,15 @@ void AsClusterFatTree::getLevelPosition(const int level, int &position, int &siz
 }
 
 void AsClusterFatTree::addNodes(std::vector<int> const& id) {
-  for (unsigned int i = 0 ; i < id.size() ; i++) {
+  for (unsigned int  i = 0 ; i < id.size() ; i++) {
     this->nodes.push_back(new FatTreeNode(id[i]));
   }
 }
 
 void AsClusterFatTree::addLink(FatTreeNode *parent, FatTreeNode *child) {
   using std::make_pair;
-  if ((int)parent->children.size() == this->nodesByLevel[parent->level] ||
-      (int)child->parents.size()   == this->nodesByLevel[child->level]) {
+  if (parent->children.size() == this->nodesByLevel[parent->level] ||
+      child->parents.size()   == this->nodesByLevel[child->level]) {
     /* NB : This case should never happen, if this private function is not misused,
      * so should we keep this test, keep it only for debug, throw an exception
      * or get rid of it ? In all cases, anytime we get in there, code should be
@@ -133,7 +132,7 @@ void AsClusterFatTree::parse_specific_arguments(sg_platf_cluster_cbarg_t
 
   // Then, a l-sized vector standing for the childs number by level
   boost::split(tmp, parameters[1], boost::is_any_of(","));
-  if((int)tmp.size() != this->levels) {
+  if(tmp.size() != this->levels) {
     surf_parse_error("Fat trees are defined by the levels number and 3 vectors" 
                      ", see the documentation for more informations"); 
   }
@@ -143,7 +142,7 @@ void AsClusterFatTree::parse_specific_arguments(sg_platf_cluster_cbarg_t
   
   // Then, a l-sized vector standing for the parents number by level
   boost::split(tmp, parameters[2], boost::is_any_of(","));
-  if((int)tmp.size() != this->levels) {
+  if(tmp.size() != this->levels) {
     surf_parse_error("Fat trees are defined by the levels number and 3 vectors" 
                      ", see the documentation for more informations"); 
   }
@@ -153,7 +152,7 @@ void AsClusterFatTree::parse_specific_arguments(sg_platf_cluster_cbarg_t
   
   // Finally, a l-sized vector standing for the ports number with the lower level
   boost::split(tmp, parameters[3], boost::is_any_of(","));
-  if((int)tmp.size() != this->levels) {
+  if(tmp.size() != this->levels) {
     surf_parse_error("Fat trees are defined by the levels number and 3 vectors" 
                      ", see the documentation for more informations"); 
     
@@ -173,16 +172,16 @@ void AsClusterFatTree::generateDotFile(const string& filename) const {
   
   if(file.is_open()) {
     // That could also be greatly clarified with C++11
-    // std::map<std::pair<int,int>,FatTreeLink*>::iterator iter;
-    // file << "graph AsClusterFatTree {\n";
-    // for (iter = this->links.begin() ; iter != this->links.end() ; iter++ ) {
-    //   for (int j = 0 ; j < iter->second->ports ; j++) {
-    //     file << iter->second->source->id 
-    //          << " -- " 
-    //          << iter->second->destination->id
-    //          << ";\n";
-    //   }
-    //}
+    std::map<std::pair<int,int>,FatTreeLink*>::const_iterator iter;
+    file << "graph AsClusterFatTree {\n";
+    for (iter = this->links.begin() ; iter != this->links.end() ; iter++ ) {
+      for (unsigned int j = 0 ; j < iter->second->ports ; j++) {
+        file << iter->second->source->id
+             << " -- "
+             << iter->second->destination->id
+             << ";\n";
+      }
+    }
     file << "}";
     file.close();
   }