Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename As::getRouteAndLatency into As::getLocalRoute
[simgrid.git] / src / kernel / routing / AsClusterFatTree.hpp
1 /* Copyright (c) 2014-2016. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_ROUTING_CLUSTER_FAT_TREE_HPP_
7 #define SIMGRID_ROUTING_CLUSTER_FAT_TREE_HPP_
8
9 #include "src/kernel/routing/AsCluster.hpp"
10
11 namespace simgrid {
12 namespace kernel {
13 namespace routing {
14
15 class XBT_PRIVATE FatTreeLink;
16
17 /** \brief A node in a fat tree (@ref AsClusterFatTree).
18  * A FatTreeNode can either be a switch or a processing node. Switches are
19  * identified by a negative ID. This class is closely related to fat
20  */
21 class XBT_PRIVATE FatTreeNode {
22 public:
23   /** Unique ID which identifies every node. */
24   int id;
25   /* Level into the tree, with 0 being the leafs.
26    */
27   unsigned int level; 
28   /* \brief Position into the level, starting from 0.
29    */
30   unsigned int position; 
31   /** In order to link nodes between them, each one must be assigned a label,
32    * consisting of l integers, l being the levels number of the tree. Each label
33    * is unique in the level, and the way it is generated allows the construction
34    * of a fat tree which fits the desired topology.
35    */
36   std::vector<unsigned int> label;
37
38   /** Links to the lower level, where the position in the vector corresponds to
39    * a port number. 
40    */
41   std::vector<FatTreeLink*> children;
42   /** Links to the upper level, where the position in the vector corresponds to
43    * a port number. 
44    */ 
45   std::vector<FatTreeLink*> parents;
46
47   /** Virtual link standing for the node global capacity.
48    */
49   Link* limiterLink;
50   /** If present, communications from this node to this node will pass through it
51    * instead of passing by an upper level switch.
52    */
53   Link* loopback;
54   FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, int position);
55 };
56
57
58
59 /** \brief Link in a fat tree (@ref AsClusterFatTree).
60  *
61  * Represents a single, duplex link in a fat tree. This is necessary to have a tree.
62  * It is equivalent to a physical link.
63  */
64 class FatTreeLink {
65 public:
66   FatTreeLink(sg_platf_cluster_cbarg_t cluster, FatTreeNode *source, FatTreeNode *destination);
67   /** Link going up in the tree */
68   Link *upLink; 
69   /** Link going down in the tree */
70   Link *downLink;
71   /** Upper end of the link */
72   FatTreeNode *upNode;
73   /** Lower end of the link */
74   FatTreeNode *downNode;
75 };
76
77 /** 
78  * \class AsClusterFatTree
79  *
80  * \brief Fat tree representation and routing.
81  *
82  * Generate fat trees according to the topology asked for, according to:
83  * Eitan Zahavi, D-Mod-K Routing Providing Non-Blocking Traffic for Shift
84  * Permutations on Real Life Fat Trees (2010).
85  *
86  * RLFT are PGFT with some restrictions to address real world constraints,
87  * which are not currently enforced.
88  *
89  * The exact topology is described in the mandatory topo_parameters
90  * field, and follow the "h ; m_h, ..., m_1 ; w_h, ..., w_1 ; p_h, ..., p_1" format.
91  * h stands for the switches levels number, i.e. the fat tree is of height h,
92  * without the processing nodes. m_i stands for the number of lower level nodes
93  * connected to a node in level i. w_i stands for the number of upper levels
94  * nodes connected to a node in level i-1. p_i stands for the number of 
95  * parallel links connecting two nodes between level i and i - 1. Level h is
96  * the topmost switch level, level 1 is the lowest switch level, and level 0
97  * represents the processing nodes. The number of provided nodes must be exactly
98  * the number of processing nodes required to fit the topology, which is the
99  * product of the m_i's.
100  *
101  * Routing is made using a destination-mod-k scheme.
102  */
103 class XBT_PRIVATE AsClusterFatTree : public AsCluster {
104 public:
105   explicit AsClusterFatTree(As* father, const char* name);
106   ~AsClusterFatTree() override;
107   void getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg_t into, double* latency) override;
108
109   /** \brief Generate the fat tree
110    * 
111    * Once all processing nodes have been added, this will make sure the fat
112    * tree is generated by calling generateLabels(), generateSwitches() and 
113    * then connection all nodes between them, using their label.
114    */
115   void seal() override;
116   /** \brief Read the parameters in topo_parameters field.
117    *
118    * It will also store the cluster for future use.
119    */
120   void parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) override;
121   void addProcessingNode(int id);
122   void generateDotFile(const std::string& filename = "fatTree.dot") const;
123
124 private:
125   
126   //description of a PGFT (TODO : better doc)
127   unsigned int levels_ = 0;
128   std::vector<unsigned int> lowerLevelNodesNumber_; // number of children by node
129   std::vector<unsigned int> upperLevelNodesNumber_; // number of parents by node
130   std::vector<unsigned int> lowerLevelPortsNumber_; // ports between each level l and l-1
131   
132   std::map<int, FatTreeNode*> computeNodes_;
133   std::vector<FatTreeNode*> nodes_;
134   std::vector<FatTreeLink*> links_;
135   std::vector<unsigned int> nodesByLevel_;
136
137   sg_platf_cluster_cbarg_t cluster_;
138
139   void addLink(FatTreeNode *parent, unsigned int parentPort,
140                FatTreeNode *child, unsigned int childPort);
141   int getLevelPosition(const unsigned int level);
142   void generateLabels();
143   void generateSwitches();
144   int connectNodeToParents(FatTreeNode *node);
145   bool areRelated(FatTreeNode *parent, FatTreeNode *child);
146   bool isInSubTree(FatTreeNode *root, FatTreeNode *node);
147 };
148
149 }}} // namespaces
150
151 #endif