Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allow several hosts to open the same file simultaneously
[simgrid.git] / src / surf / surf_routing_cluster_fat_tree.cpp
index 8e55925c77ec0917be98107c8005356c4de890a5..066cd0fdeef791f6d801b0598f75a1463b8655c7 100644 (file)
@@ -7,6 +7,12 @@
 #include <fstream>
 
 
+
+AS_t model_fat_tree_cluster_create(void)
+{
+  return new AsClusterFatTree();
+}
+
 AsClusterFatTree::AsClusterFatTree() : levels(0) {}
 
 AsClusterFatTree::~AsClusterFatTree() {
@@ -16,9 +22,20 @@ AsClusterFatTree::~AsClusterFatTree() {
 }
 
 bool AsClusterFatTree::isInSubTree(FatTreeNode *root, FatTreeNode *node) {
-  // stub
-  return false;
+  for (unsigned int i = 0 ; i < node->level ; i++) {
+    if(root->label[i] != node->label[i]) {
+      return false;
+    }
+  }
+  
+  for (unsigned int i = root->level + 1 ; i < this->levels ; i++) {
+    if(root->label[i] != node->label[i]) {
+      return false;
+    }
+  }
+  return true;
 }
+
 void AsClusterFatTree::getRouteAndLatency(RoutingEdgePtr src,
                                           RoutingEdgePtr dst,
                                           sg_platf_route_cbarg_t into,
@@ -28,12 +45,13 @@ void AsClusterFatTree::getRouteAndLatency(RoutingEdgePtr src,
   source = this->nodes.find(src->getId())->second;
   destination = this->nodes.find(dst->getId())->second;
 
-  int d, k; // as in d-mod-k
 
   currentNode = source;
 
   // up part
   while (!isInSubTree(currentNode, destination)) {
+    int d, k; // as in d-mod-k
     d = destination->position;
 
     for (unsigned int i = 0 ; i < currentNode->level ; i++) {
@@ -43,6 +61,9 @@ void AsClusterFatTree::getRouteAndLatency(RoutingEdgePtr src,
       this->lowerLevelNodesNumber[currentNode->level];
      d = d % k;
      route.push_back(currentNode->parents[d]->upLink);
+     if(latency) {
+       *latency += currentNode->parents[d]->upLink->getLatency();
+     }
      currentNode = currentNode->parents[d]->upNode;
   }
   
@@ -52,10 +73,18 @@ void AsClusterFatTree::getRouteAndLatency(RoutingEdgePtr src,
       if(i % this->lowerLevelNodesNumber[currentNode->level] ==
          destination->label[currentNode->level]) {
         route.push_back(currentNode->children[i]->downLink);
+        if(latency) {
+          *latency += currentNode->children[i]->downLink->getLatency();
+        }
         currentNode = currentNode->children[i]->downNode;
       }
     }
   }
+  
+  for (unsigned int i = 0 ; i < route.size() ; i++) {
+    xbt_dynar_push_as(into->link_list, void*, route[i]);
+  }
+
 }
 
 /* This function makes the assumption that parse_specific_arguments() and
@@ -126,7 +155,7 @@ void AsClusterFatTree::generateSwitches() {
   }
 
      
-  if(this->nodesByLevel[0] < this->nodes.size()) {
+  if(this->nodesByLevel[0] > this->nodes.size()) {
     surf_parse_error("There is not enough nodes to fit to the described topology."
                      " Please check your platform description (We need %d nodes, we only got %zu)",
                      this->nodesByLevel[0], this->nodes.size());
@@ -214,14 +243,13 @@ int AsClusterFatTree::getLevelPosition(const unsigned  int level) {
  return tempPosition;
 }
 
-void AsClusterFatTree::addComputeNodes(std::vector<int> const& id) {
+void AsClusterFatTree::addComputeNode(int id) {
   using std::make_pair;
+  static int position = 0;
   FatTreeNode* newNode;
-  for (size_t  i = 0 ; i < id.size() ; i++) {
-    newNode = new FatTreeNode(id[i], 0, i);
-    newNode->parents.resize(this->upperLevelNodesNumber[0] * this->lowerLevelPortsNumber[i]);
-    this->nodes.insert(make_pair(id[i],newNode));
-  }
+  newNode = new FatTreeNode(id, 0, position);
+  newNode->parents.resize(this->upperLevelNodesNumber[0] * this->lowerLevelPortsNumber[0]);
+  this->nodes.insert(make_pair(id,newNode));
 }
 
 void AsClusterFatTree::addLink(sg_platf_cluster_cbarg_t cluster, 
@@ -254,7 +282,7 @@ void AsClusterFatTree::parse_specific_arguments(sg_platf_cluster_cbarg_t
   }
 
   // The first parts of topo_parameters should be the levels number
-  this->levels = std::atoi(tmp[0].c_str()); // stoi() only in C++11...
+  this->levels = std::atoi(parameters[0].c_str()); // stoi() only in C++11...
   
   // Then, a l-sized vector standing for the childs number by level
   boost::split(tmp, parameters[1], boost::is_any_of(","));
@@ -343,4 +371,3 @@ FatTreeLink::FatTreeLink(sg_platf_cluster_cbarg_t cluster, FatTreeNode *downNode
   uniqueId++;
 
 }
-