1 #include "surf_routing_cluster_fat_tree.hpp"
3 #include <boost/algorithm/string/split.hpp>
4 #include <boost/algorithm/string/classification.hpp>
10 AsClusterFatTree::AsClusterFatTree() : levels(0) {}
12 AsClusterFatTree::~AsClusterFatTree() {
13 for (int i = 0 ; i < this->nodes.size() ; i++) {
14 delete this->nodes[i];
18 void AsClusterFatTree::getRouteAndLatency(RoutingEdgePtr src,
20 sg_platf_route_cbarg_t into,
21 double *latency) const{
25 /* This function makes the assumption that parse_specific_arguments() and
26 * addNodes() have already been called
28 void AsClusterFatTree::create_links(sg_platf_cluster_cbarg_t cluster) {
30 if(this->levels == 0) {
33 std::vector<int> nodesByLevel(this->levels);
34 int nodesRequired = 0;
37 for (int i = 0 ; i < this->levels ; i++) {
38 int nodesInThisLevel = 1;
40 for (int j = 0 ; j < i ; j++) {
41 nodesInThisLevel *= this->upperLevelNodesNumber[j];
44 for (int j = i+1 ; j < this->levels ; j++) {
45 nodesInThisLevel *= this->lowerLevelNodesNumber[j];
48 nodesByLevel[i] = nodesInThisLevel;
49 nodesRequired += nodesInThisLevel;
52 if(nodesRequired > this->nodes.size()) {
53 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 %lu)", nodesRequired, this->nodes.size());
57 // Nodes are totally ordered, by level and then by position, in this->nodes
59 for (int i = 0 ; i < this->levels ; i++) {
60 for (int j = 0 ; j < nodesByLevel[i] ; j++) {
61 this->nodes[k]->level = i;
62 this->nodes[k]->position = j;
67 else if (i == this->levels - 1) {
78 void AsClusterFatTree::addNodes(std::vector<int> const& id) {
79 for (int i = 0 ; i < id.size() ; i++) {
80 this->nodes.push_back(new FatTreeNode(id[i]));
84 void AsClusterFatTree::parse_specific_arguments(sg_platf_cluster_cbarg_t
86 std::vector<string> parameters;
87 std::vector<string> tmp;
88 boost::split(parameters, cluster->topo_parameters, boost::is_any_of(";"));
91 // TODO : we have to check for zeros and negative numbers, or it might crash
92 if (parameters.size() != 4){
93 surf_parse_error("Fat trees are defined by the levels number and 3 vectors"
94 ", see the documentation for more informations");
95 // Well, there's no doc, yet
98 // The first parts of topo_parameters should be the levels number
99 this->levels = std::atoi(tmp[0].c_str()); // stoi() only in C++11...
101 // Then, a l-sized vector standing for the childs number by level
102 boost::split(tmp, parameters[1], boost::is_any_of(","));
103 if(tmp.size() != this->levels) {
104 surf_parse_error("Fat trees are defined by the levels number and 3 vectors"
105 ", see the documentation for more informations");
107 for(unsigned int i = 0 ; i < tmp.size() ; i++){
108 this->lowerLevelNodesNumber.push_back(std::atoi(tmp[i].c_str()));
111 // Then, a l-sized vector standing for the parents number by level
112 boost::split(tmp, parameters[2], boost::is_any_of(","));
113 if(tmp.size() != this->levels) {
114 surf_parse_error("Fat trees are defined by the levels number and 3 vectors"
115 ", see the documentation for more informations");
117 for(unsigned int i = 0 ; i < tmp.size() ; i++){
118 this->upperLevelNodesNumber.push_back(std::atoi(tmp[i].c_str()));
121 // Finally, a l-sized vector standing for the ports number with the lower level
122 boost::split(tmp, parameters[3], boost::is_any_of(","));
123 if(tmp.size() != this->levels) {
124 surf_parse_error("Fat trees are defined by the levels number and 3 vectors"
125 ", see the documentation for more informations");
128 for(unsigned int i = 0 ; i < tmp.size() ; i++){
129 this->lowerLevelPortsNumber.push_back(std::atoi(tmp[i].c_str()));
134 void AsClusterFatTree::generateDotFile(string filename) {
136 /* Maybe should we get directly a char*, as open takes strings only beginning
139 file.open(filename.c_str(), ios::out | ios::trunc);
142 /* TODO : Iterate through a map takes 10 chars with c++11, 100 with c++98.
143 * All I have to do is write it down...
146 // file << "graph AsClusterFatTree {\n";
147 // for (std::map<std::pair<int,int>, FatTreeLink*>::iterator link = this->links.begin() ; link != this->links.end() ; link++ ) {
148 // for (int j = 0 ; j < link->ports ; j++) {
149 // file << this->links[i]->source.id
150 // << " -- " this->links[i]->destination.id
158 std::cerr << "Unable to open file " << filename << std::endl;
163 FatTreeNode::FatTreeNode(int id, int level, int position) : id(id),