1 /* Copyright (c) 2014-2022. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_ROUTING_CLUSTER_FAT_TREE_HPP_
7 #define SIMGRID_ROUTING_CLUSTER_FAT_TREE_HPP_
9 #include <simgrid/kernel/routing/ClusterZone.hpp>
15 class XBT_PRIVATE FatTreeLink;
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
21 class XBT_PRIVATE FatTreeNode {
23 /** Unique ID which identifies every node. */
25 /* Level into the tree, with 0 being the leafs.
28 /* @brief Position into the level, starting from 0.
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.
36 std::vector<unsigned int> label;
38 /** Links to the lower level, where the position in the vector corresponds to
41 std::vector<std::shared_ptr<FatTreeLink>> children;
42 /** Links to the upper level, where the position in the vector corresponds to
45 std::vector<std::shared_ptr<FatTreeLink>> parents;
47 /** Virtual link standing for the node global capacity.
49 resource::StandardLinkImpl* 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.
53 resource::StandardLinkImpl* loopback_;
54 FatTreeNode(int id, int level, int position, resource::StandardLinkImpl* limiter,
55 resource::StandardLinkImpl* loopback)
56 : id(id), level(level), position(position), limiter_link_(limiter), loopback_(loopback)
61 /** @brief Link in a fat tree (@ref FatTreeZone).
63 * Represents a single, duplex link in a fat tree. This is necessary to have a tree.
64 * It is equivalent to a physical link.
68 FatTreeLink(FatTreeNode* src, FatTreeNode* dst, resource::StandardLinkImpl* linkup,
69 resource::StandardLinkImpl* linkdown)
70 : up_node_(dst), down_node_(src), up_link_(linkup), down_link_(linkdown)
73 /** Upper end of the link */
74 FatTreeNode* up_node_;
75 /** Lower end of the link */
76 FatTreeNode* down_node_;
77 /** Link going up in the tree */
78 resource::StandardLinkImpl* up_link_;
79 /** Link going down in the tree */
80 resource::StandardLinkImpl* down_link_;
83 /** @ingroup ROUTING_API
84 * @brief NetZone using a Fat-Tree topology
86 * Generate fat trees according to the topology asked for, according to:
87 * Eitan Zahavi, D-Mod-K Routing Providing Non-Blocking Traffic for Shift
88 * Permutations on Real Life Fat Trees (2010).
90 * RLFT are PGFT with some restrictions to address real world constraints,
91 * which are not currently enforced.
93 * The exact topology is described in the mandatory topo_parameters
94 * field, and follow the "h ; m_1, ..., m_h ; w_1, ..., w_h ; p_1, ..., p_h" format.
95 * h stands for the switches levels number, i.e. the fat tree is of height h,
96 * without the processing nodes. m_i stands for the number of lower level nodes
97 * connected to a node in level i. w_i stands for the number of upper levels
98 * nodes connected to a node in level i-1. p_i stands for the number of
99 * parallel links connecting two nodes between level i and i - 1. Level h is
100 * the topmost switch level, level 1 is the lowest switch level, and level 0
101 * represents the processing nodes. The number of provided nodes must be exactly
102 * the number of processing nodes required to fit the topology, which is the
103 * product of the m_i's.
105 * Routing is made using a destination-mod-k scheme.
107 class XBT_PRIVATE FatTreeZone : public ClusterBase {
108 /** @brief Generate the fat tree
110 * Once all processing nodes have been added, this will make sure the fat
111 * tree is generated by calling generateLabels(), generateSwitches() and
112 * then connection all nodes between them, using their label.
114 // description of a PGFT (TODO : better doc)
115 unsigned long levels_ = 0;
116 std::vector<unsigned int> num_children_per_node_; // number of children by node
117 std::vector<unsigned int> num_parents_per_node_; // number of parents by node
118 std::vector<unsigned int> num_port_lower_level_; // ports between each level l and l-1
120 std::map<unsigned long, std::shared_ptr<FatTreeNode>> compute_nodes_;
121 std::vector<std::shared_ptr<FatTreeNode>> nodes_;
122 std::vector<std::shared_ptr<FatTreeLink>> links_;
123 std::vector<unsigned int> nodes_by_level_;
125 void add_link(FatTreeNode* parent, unsigned int parent_port, FatTreeNode* child, unsigned int child_port);
126 int get_level_position(const unsigned int level);
127 void generate_switches(const s4u::ClusterCallbacks& set_callbacks);
128 void generate_labels();
129 int connect_node_to_parents(FatTreeNode* node);
130 bool are_related(FatTreeNode* parent, FatTreeNode* child) const;
131 bool is_in_sub_tree(const FatTreeNode* root, const FatTreeNode* node) const;
133 void do_seal() override;
136 explicit FatTreeZone(const std::string& name) : ClusterBase(name){};
137 FatTreeZone(const FatTreeZone&) = delete;
138 FatTreeZone& operator=(const FatTreeZone&) = delete;
139 void get_local_route(const NetPoint* src, const NetPoint* dst, Route* into, double* latency) override;
142 * @brief Parse the topology parameters from string format
144 * @param topo_parameters String with topology, e.g. "2;4,4;1,2;1,2"
146 static s4u::FatTreeParams parse_topo_parameters(const std::string& topo_parameters);
147 /** @brief Checks topology parameters */
148 static void check_topology(unsigned int n_levels, const std::vector<unsigned int>& down_links,
149 const std::vector<unsigned int>& up_links, const std::vector<unsigned int>& link_count);
150 /** @brief Set FatTree topology */
151 void set_topology(unsigned int n_levels, const std::vector<unsigned int>& down_links,
152 const std::vector<unsigned int>& up_links, const std::vector<unsigned int>& link_count);
153 void add_processing_node(int id, resource::StandardLinkImpl* limiter, resource::StandardLinkImpl* loopback);
155 * @brief Build upper levels (switches) in Fat-Tree
157 * Suppose that set_topology and add_processing_node have already been called
159 void build_upper_levels(const s4u::ClusterCallbacks& set_callbacks);
160 void generate_dot_file(const std::string& filename = "fat_tree.dot") const;
162 } // namespace routing
163 } // namespace kernel
164 } // namespace simgrid