Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
privatize and snake_case some methods in DijkstraZone
[simgrid.git] / include / simgrid / kernel / routing / FatTreeZone.hpp
1 /* Copyright (c) 2014-2018. 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 <simgrid/kernel/routing/ClusterZone.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 FatTreeZone).
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   resource::LinkImpl* limiter_link_;
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   resource::LinkImpl* loopback;
54   FatTreeNode(ClusterCreationArgs* cluster, int id, int level, int position);
55 };
56
57 /** \brief Link in a fat tree (@ref FatTreeZone).
58  *
59  * Represents a single, duplex link in a fat tree. This is necessary to have a tree.
60  * It is equivalent to a physical link.
61  */
62 class FatTreeLink {
63 public:
64   FatTreeLink(ClusterCreationArgs* cluster, FatTreeNode* source, FatTreeNode* destination);
65   /** Link going up in the tree */
66   resource::LinkImpl* up_link_;
67   /** Link going down in the tree */
68   resource::LinkImpl* down_link_;
69   /** Upper end of the link */
70   FatTreeNode* up_node_;
71   /** Lower end of the link */
72   FatTreeNode* down_node_;
73 };
74
75 /** @ingroup ROUTING_API
76  * @brief NetZone using a Fat-Tree topology
77  *
78  * Generate fat trees according to the topology asked for, according to:
79  * Eitan Zahavi, D-Mod-K Routing Providing Non-Blocking Traffic for Shift
80  * Permutations on Real Life Fat Trees (2010).
81  *
82  * RLFT are PGFT with some restrictions to address real world constraints,
83  * which are not currently enforced.
84  *
85  * The exact topology is described in the mandatory topo_parameters
86  * field, and follow the "h ; m_1, ..., m_h ; w_1, ..., w_h ; p_1, ..., p_h" format.
87  * h stands for the switches levels number, i.e. the fat tree is of height h,
88  * without the processing nodes. m_i stands for the number of lower level nodes
89  * connected to a node in level i. w_i stands for the number of upper levels
90  * nodes connected to a node in level i-1. p_i stands for the number of
91  * parallel links connecting two nodes between level i and i - 1. Level h is
92  * the topmost switch level, level 1 is the lowest switch level, and level 0
93  * represents the processing nodes. The number of provided nodes must be exactly
94  * the number of processing nodes required to fit the topology, which is the
95  * product of the m_i's.
96  *
97  * Routing is made using a destination-mod-k scheme.
98  */
99 class XBT_PRIVATE FatTreeZone : public ClusterZone {
100 public:
101   explicit FatTreeZone(NetZone* father, std::string name);
102   ~FatTreeZone() override;
103   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
104
105   /** \brief Generate the fat tree
106    *
107    * Once all processing nodes have been added, this will make sure the fat
108    * tree is generated by calling generateLabels(), generateSwitches() and
109    * then connection all nodes between them, using their label.
110    */
111   void seal() override;
112   /** \brief Read the parameters in topo_parameters field.
113    *
114    * It will also store the cluster for future use.
115    */
116   void parse_specific_arguments(ClusterCreationArgs* cluster) override;
117   void add_processing_node(int id);
118   void generate_dot_file(const std::string& filename = "fat_tree.dot") const;
119
120 private:
121   // description of a PGFT (TODO : better doc)
122   unsigned long levels_ = 0;
123   std::vector<unsigned int> num_children_per_node_; // number of children by node
124   std::vector<unsigned int> num_parents_per_node_;  // number of parents by node
125   std::vector<unsigned int> num_port_lower_level_;  // ports between each level l and l-1
126
127   std::map<int, FatTreeNode*> compute_nodes_;
128   std::vector<FatTreeNode*> nodes_;
129   std::vector<FatTreeLink*> links_;
130   std::vector<unsigned int> nodes_by_level_;
131
132   ClusterCreationArgs* cluster_ = nullptr;
133
134   void add_link(FatTreeNode* parent, unsigned int parent_port, FatTreeNode* child, unsigned int child_port);
135   int get_level_position(const unsigned int level);
136   void generate_labels();
137   void generate_switches();
138   int connect_node_to_parents(FatTreeNode* node);
139   bool are_related(FatTreeNode* parent, FatTreeNode* child);
140   bool is_in_sub_tree(FatTreeNode* root, FatTreeNode* node);
141 };
142 } // namespace routing
143 } // namespace kernel
144 } // namespace simgrid
145
146 #endif