#define SIMGRID_ROUTING_CLUSTER_HPP_
#include <simgrid/kernel/routing/NetZoneImpl.hpp>
+#include <xbt/ex.h>
#include <unordered_map>
namespace kernel {
namespace routing {
-/** @ingroup ROUTING_API
- * @brief NetZone where each component is connected through a private link
+/**
+ * @brief Placeholder for old ClusterZone class
+ *
+ * The ClusterZone is now implemented through a StarZone.
+ *
+ * Leave this class as a placeholder to avoid compatibility issues
+ * with codes that use the Engine::get_filtered_netzones.
+ *
+ * The old ClusterZone is now called BaseCluster and it's used ONLY as base to
+ * implement the complex cluster such as Torus, DragonFly and Fat-Tree
+ */
+class ClusterZone : public NetZoneImpl {
+protected:
+ using NetZoneImpl::NetZoneImpl;
+};
+
+/**
+ * @brief Old ClusterZone implementation
+ *
+ * NOTE: Cannot be directly instantiated anymore.
+ *
+ * NetZone where each component is connected through a private link
*
* Cluster zones have a collection of private links that interconnect their components.
* This is particularly well adapted to model a collection of elements interconnected
* <tt>limiter(A)_UP, private(A)_UP, backbone</tt>
* (because the private router is directly connected to the cluster core).
*/
-
-class ClusterZone : public NetZoneImpl {
+class XBT_PRIVATE ClusterBase : public ClusterZone {
/* We use a map instead of a std::vector here because that's a sparse vector. Some values may not exist */
/* The pair is {link_up, link_down} */
std::unordered_map<unsigned int, std::pair<resource::LinkImpl*, resource::LinkImpl*>> private_links_;
std::unordered_map<unsigned int, NetPoint*> gateways_; //!< list of gateways for leafs (if they're netzones)
- resource::LinkImpl* backbone_ = nullptr;
- NetPoint* router_ = nullptr;
- bool has_limiter_ = false;
- bool has_loopback_ = false;
+ resource::LinkImpl* backbone_ = nullptr;
+ NetPoint* router_ = nullptr;
+ bool has_limiter_ = false;
+ bool has_loopback_ = false;
unsigned long num_links_per_node_ = 1; /* may be 1 (if only a private link), 2 or 3 (if limiter and loopback) */
s4u::Link::SharingPolicy link_sharing_policy_; //!< cluster links: sharing policy
double link_lat_; //!< cluster links: latency
protected:
+ using ClusterZone::ClusterZone;
void set_num_links_per_node(unsigned long num) { num_links_per_node_ = num; }
resource::LinkImpl* get_uplink_from(unsigned int position) const { return private_links_.at(position).first; }
resource::LinkImpl* get_downlink_to(unsigned int position) const { return private_links_.at(position).second; }
double get_link_bandwidth() const { return link_bw_; }
s4u::Link::SharingPolicy get_link_sharing_policy() const { return link_sharing_policy_; }
-public:
- explicit ClusterZone(const std::string& name);
-
- /** @brief Set the characteristics of links inside a Cluster zone */
- virtual void set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy);
void set_loopback();
bool has_loopback() const { return has_loopback_; }
void set_limiter();
return private_links_.find(position) != private_links_.end();
}
- void get_local_route(NetPoint* src, NetPoint* dst, Route* into, double* latency) override;
void get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t, std::less<>>* nodes,
- std::map<std::string, xbt_edge_t, std::less<>>* edges) override;
-
- void create_links(int id, int rank);
+ std::map<std::string, xbt_edge_t, std::less<>>* edges) override
+ {
+ /* the old and generic implementation of get_graph doesn't make sense for complex clusters */
+ THROW_UNIMPLEMENTED;
+ };
unsigned int node_pos(int id) const { return id * num_links_per_node_; }
unsigned int node_pos_with_loopback(int id) const { return node_pos(id) + (has_loopback_ ? 1 : 0); }
- unsigned int node_pos_with_loopback_limiter(int id) const
- {
- return node_pos_with_loopback(id) + (has_limiter_ ? 1 : 0);
- }
+
+public:
/** Fill the leaf retriving netpoint from a user's callback */
void fill_leaf_from_cb(unsigned int position, const std::vector<unsigned int>& dimensions,
const s4u::ClusterCallbacks& set_callbacks, NetPoint** node_netpoint, s4u::Link** lb_link,
s4u::Link** limiter_link);
+ /** @brief Set the characteristics of links inside a Cluster zone */
+ virtual void set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy);
+ unsigned int node_pos_with_loopback_limiter(int id) const
+ {
+ return node_pos_with_loopback(id) + (has_limiter_ ? 1 : 0);
+ }
};
} // namespace routing
} // namespace kernel
* is also not realistic, as blue level can use more links than a single
* Aries can handle, thus it should use several routers.
*/
-class XBT_PUBLIC DragonflyZone : public ClusterZone {
+class XBT_PUBLIC DragonflyZone : public ClusterBase {
public:
struct Coords {
unsigned group;
*
* Routing is made using a destination-mod-k scheme.
*/
-class XBT_PRIVATE FatTreeZone : public ClusterZone {
+class XBT_PRIVATE FatTreeZone : public ClusterBase {
/** @brief Generate the fat tree
*
* Once all processing nodes have been added, this will make sure the fat
void do_seal() override;
public:
- using ClusterZone::ClusterZone;
+ explicit FatTreeZone(const std::string& name) : ClusterBase(name){};
FatTreeZone(const FatTreeZone&) = delete;
FatTreeZone& operator=(const FatTreeZone&) = delete;
void get_local_route(NetPoint* src, NetPoint* dst, Route* into, double* latency) override;
#ifndef SIMGRID_KERNEL_ROUTING_STARZONE_HPP_
#define SIMGRID_KERNEL_ROUTING_STARZONE_HPP_
-#include <simgrid/kernel/routing/NetZoneImpl.hpp>
+#include <simgrid/kernel/routing/ClusterZone.hpp>
#include <unordered_map>
#include <unordered_set>
* In this case, a communication from A to B goes through the links: <tt> l0, backbone, l1. </tt>
* Note that the backbone only appears once in the link list.
*/
-
-class StarZone : public NetZoneImpl {
+class StarZone : public ClusterZone { // implements the old ClusterZone
public:
explicit StarZone(const std::string& name);
*
*/
-class XBT_PRIVATE TorusZone : public ClusterZone {
+class XBT_PRIVATE TorusZone : public ClusterBase {
std::vector<unsigned int> dimensions_;
public:
- using ClusterZone::ClusterZone;
+ explicit TorusZone(const std::string& name) : ClusterBase(name){};
void create_torus_links(int id, int rank, unsigned int position);
void get_local_route(NetPoint* src, NetPoint* dst, Route* into, double* latency) override;
void set_topology(const std::vector<unsigned int>& dimensions);
namespace simgrid {
namespace kernel {
namespace routing {
-ClusterZone::ClusterZone(const std::string& name) : NetZoneImpl(name) {}
-void ClusterZone::set_loopback()
+void ClusterBase::set_loopback()
{
if (not has_loopback_) {
num_links_per_node_++;
}
}
-void ClusterZone::set_limiter()
+void ClusterBase::set_limiter()
{
if (not has_limiter_) {
num_links_per_node_++;
}
}
-void ClusterZone::set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy)
+void ClusterBase::set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy)
{
link_sharing_policy_ = sharing_policy;
link_bw_ = bw;
link_lat_ = lat;
}
-void ClusterZone::add_private_link_at(unsigned int position, std::pair<resource::LinkImpl*, resource::LinkImpl*> link)
+void ClusterBase::add_private_link_at(unsigned int position, std::pair<resource::LinkImpl*, resource::LinkImpl*> link)
{
private_links_.insert({position, link});
}
-void ClusterZone::get_local_route(NetPoint* src, NetPoint* dst, Route* route, double* lat)
+void ClusterBase::set_gateway(unsigned int position, NetPoint* gateway)
{
- XBT_VERB("cluster getLocalRoute from '%s'[%u] to '%s'[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
- xbt_assert(not private_links_.empty(),
- "Cluster routing: no links attached to the source node - did you use host_link tag?");
-
- if ((src->id() == dst->id()) && has_loopback_) {
- if (src->is_router()) {
- XBT_WARN("Routing from a cluster private router to itself is meaningless");
- } else {
- std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos(src->id()));
- route->link_list_.push_back(info.first);
- if (lat)
- *lat += info.first->get_latency();
- }
- return;
- }
-
- if (not src->is_router()) { // No private link for the private router
- if (has_limiter_) { // limiter for sender
- std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos_with_loopback(src->id()));
- route->link_list_.push_back(info.first);
- }
-
- std::pair<resource::LinkImpl*, resource::LinkImpl*> info =
- private_links_.at(node_pos_with_loopback_limiter(src->id()));
- if (info.first) { // link up
- route->link_list_.push_back(info.first);
- if (lat)
- *lat += info.first->get_latency();
- }
- }
-
- if (backbone_) {
- route->link_list_.push_back(backbone_);
- if (lat)
- *lat += backbone_->get_latency();
- }
-
- if (not dst->is_router()) { // No specific link for router
- std::pair<resource::LinkImpl*, resource::LinkImpl*> info =
- private_links_.at(node_pos_with_loopback_limiter(dst->id()));
-
- if (info.second) { // link down
- route->link_list_.push_back(info.second);
- if (lat)
- *lat += info.second->get_latency();
- }
- if (has_limiter_) { // limiter for receiver
- info = private_links_.at(node_pos_with_loopback(dst->id()));
- route->link_list_.push_back(info.first);
- }
- }
-}
-
-void ClusterZone::get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t, std::less<>>* nodes,
- std::map<std::string, xbt_edge_t, std::less<>>* edges)
-{
- xbt_assert(router_,
- "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
-
- /* create the router */
- xbt_node_t routerNode = new_xbt_graph_node(graph, router_->get_cname(), nodes);
-
- xbt_node_t backboneNode = nullptr;
- if (backbone_) {
- backboneNode = new_xbt_graph_node(graph, backbone_->get_cname(), nodes);
- new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
- }
-
- for (auto const& src : get_vertices()) {
- if (not src->is_router()) {
- xbt_node_t previous = new_xbt_graph_node(graph, src->get_cname(), nodes);
-
- std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(src->id());
-
- if (info.first) { // link up
- xbt_node_t current = new_xbt_graph_node(graph, info.first->get_cname(), nodes);
- new_xbt_graph_edge(graph, previous, current, edges);
-
- if (backbone_) {
- new_xbt_graph_edge(graph, current, backboneNode, edges);
- } else {
- new_xbt_graph_edge(graph, current, routerNode, edges);
- }
- }
-
- if (info.second) { // link down
- xbt_node_t current = new_xbt_graph_node(graph, info.second->get_cname(), nodes);
- new_xbt_graph_edge(graph, previous, current, edges);
-
- if (backbone_) {
- new_xbt_graph_edge(graph, current, backboneNode, edges);
- } else {
- new_xbt_graph_edge(graph, current, routerNode, edges);
- }
- }
- }
- }
-}
-
-void ClusterZone::create_links(int id, int rank)
-{
- std::string link_id = get_name() + "_link_" + std::to_string(id);
-
- const s4u::Link* linkUp;
- const s4u::Link* linkDown;
- if (link_sharing_policy_ == simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX) {
- linkUp = create_link(link_id + "_UP", std::vector<double>{link_bw_})->set_latency(link_lat_)->seal();
- linkDown = create_link(link_id + "_DOWN", std::vector<double>{link_bw_})->set_latency(link_lat_)->seal();
- } else {
- linkUp = create_link(link_id, std::vector<double>{link_bw_})->set_latency(link_lat_)->seal();
- linkDown = linkUp;
- }
- private_links_.insert({node_pos_with_loopback_limiter(rank), {linkUp->get_impl(), linkDown->get_impl()}});
-}
-
-void ClusterZone::set_gateway(unsigned int position, NetPoint* gateway)
-{
- xbt_assert(not gateway || not gateway->is_netzone(), "ClusterZone: gateway cannot be another netzone %s",
+ xbt_assert(not gateway || not gateway->is_netzone(), "ClusterBase: gateway cannot be another netzone %s",
gateway->get_cname());
gateways_[position] = gateway;
}
-NetPoint* ClusterZone::get_gateway(unsigned int position)
+NetPoint* ClusterBase::get_gateway(unsigned int position)
{
NetPoint* res = nullptr;
auto it = gateways_.find(position);
return res;
}
-void ClusterZone::fill_leaf_from_cb(unsigned int position, const std::vector<unsigned int>& dimensions,
+void ClusterBase::fill_leaf_from_cb(unsigned int position, const std::vector<unsigned int>& dimensions,
const s4u::ClusterCallbacks& set_callbacks, NetPoint** node_netpoint,
s4u::Link** lb_link, s4u::Link** limiter_link)
{
namespace kernel {
namespace routing {
-DragonflyZone::DragonflyZone(const std::string& name) : ClusterZone(name) {}
+DragonflyZone::DragonflyZone(const std::string& name) : ClusterBase(name) {}
DragonflyZone::Coords DragonflyZone::rankId_to_coords(int rankId) const
{
void DragonflyZone::set_link_characteristics(double bw, double lat, s4u::Link::SharingPolicy sharing_policy)
{
- ClusterZone::set_link_characteristics(bw, lat, sharing_policy);
+ ClusterBase::set_link_characteristics(bw, lat, sharing_policy);
if (sharing_policy == s4u::Link::SharingPolicy::SPLITDUPLEX)
num_links_per_link_ = 2;
}
namespace simgrid {
namespace kernel {
namespace routing {
-StarZone::StarZone(const std::string& name) : NetZoneImpl(name) {}
+StarZone::StarZone(const std::string& name) : ClusterZone(name) {}
void StarZone::add_links_to_route(const std::vector<resource::LinkImpl*>& links, Route* route, double* latency,
std::unordered_set<resource::LinkImpl*>& added_links) const
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/Exception.hpp"
-#include "simgrid/kernel/routing/ClusterZone.hpp"
#include "simgrid/kernel/routing/DijkstraZone.hpp"
#include "simgrid/kernel/routing/DragonflyZone.hpp"
#include "simgrid/kernel/routing/EmptyZone.hpp"
/*************************************************************************************************/
/** @brief Create regular Cluster */
-static void sg_platf_new_cluster_flat2(simgrid::kernel::routing::ClusterCreationArgs* cluster)
+static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationArgs* cluster)
{
auto* zone = simgrid::s4u::create_star_zone(cluster->id);
simgrid::s4u::NetZone const* parent = routing_get_current() ? routing_get_current()->get_iface() : nullptr;
simgrid::kernel::routing::on_cluster_creation(*cluster);
}
+void sg_platf_new_tag_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster)
+{
+ switch (cluster->topology) {
+ case simgrid::kernel::routing::ClusterTopology::TORUS:
+ case simgrid::kernel::routing::ClusterTopology::DRAGONFLY:
+ case simgrid::kernel::routing::ClusterTopology::FAT_TREE:
+ sg_platf_new_cluster_hierarchical(cluster);
+ break;
+ default:
+ sg_platf_new_cluster_flat(cluster);
+ break;
+ }
+}
/*************************************************************************************************/
/** @brief Set the links for internal node inside a Cluster(Star) */
static void sg_platf_cluster_set_hostlink(simgrid::kernel::routing::StarZone* zone,
sg_platf_new_cabinet(zone, &cabinet, backbone);
}
}
-/*************************************************************************************************/
-
-static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationArgs* cluster)
-{
- using simgrid::kernel::routing::ClusterZone;
-
- int rankId = 0;
-
- // What an inventive way of initializing the NetZone that I have as ancestor :-(
- simgrid::kernel::routing::ZoneCreationArgs zone;
- zone.id = cluster->id;
- zone.routing = "Cluster";
- sg_platf_new_Zone_begin(&zone);
- auto* current_zone = static_cast<ClusterZone*>(routing_get_current());
- for (auto const& elm : cluster->properties)
- current_zone->get_iface()->set_property(elm.first, elm.second);
-
- if (cluster->loopback_bw > 0 || cluster->loopback_lat > 0) {
- current_zone->set_loopback();
- }
-
- if (cluster->limiter_link > 0) {
- current_zone->set_limiter();
- }
-
- for (int const& i : cluster->radicals) {
- std::string host_id = std::string(cluster->prefix) + std::to_string(i) + cluster->suffix;
-
- XBT_DEBUG("<host\tid=\"%s\"\tspeed=\"%f\">", host_id.c_str(), cluster->speeds.front());
- current_zone->create_host(host_id, cluster->speeds)
- ->set_core_count(cluster->core_amount)
- ->set_properties(cluster->properties)
- ->seal();
-
- XBT_DEBUG("</host>");
-
- std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(i);
- XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id.c_str(), cluster->bw, cluster->lat);
-
- // All links are saved in a matrix;
- // every row describes a single node; every node may have multiple links.
- // the first column may store a link from x to x if p_has_loopback is set
- // the second column may store a limiter link if p_has_limiter is set
- // other columns are to store one or more link for the node
-
- // add a loopback link
- simgrid::kernel::resource::LinkImpl* loopback = nullptr;
- if (cluster->loopback_bw > 0 || cluster->loopback_lat > 0) {
- std::string loopback_name = link_id + "_loopback";
- XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", loopback_name.c_str(), cluster->loopback_bw);
-
- loopback = current_zone->create_link(loopback_name, std::vector<double>{cluster->loopback_bw})
- ->set_sharing_policy(simgrid::s4u::Link::SharingPolicy::FATPIPE)
- ->set_latency(cluster->loopback_lat)
- ->seal()
- ->get_impl();
-
- current_zone->add_private_link_at(current_zone->node_pos(rankId), {loopback, loopback});
- }
-
- // add a limiter link (shared link to account for maximal bandwidth of the node)
- simgrid::kernel::resource::LinkImpl* limiter = nullptr;
- if (cluster->limiter_link > 0) {
- std::string limiter_name = std::string(link_id) + "_limiter";
- XBT_DEBUG("<limiter\tid=\"%s\"\tbw=\"%f\"/>", limiter_name.c_str(), cluster->limiter_link);
-
- limiter = current_zone->create_link(limiter_name, std::vector<double>{cluster->limiter_link})->seal()->get_impl();
-
- current_zone->add_private_link_at(current_zone->node_pos_with_loopback(rankId), {limiter, limiter});
- }
-
- current_zone->set_link_characteristics(cluster->bw, cluster->lat, cluster->sharing_policy);
- // call the cluster function that adds the others links
- current_zone->create_links(i, rankId);
- rankId++;
- }
-
- // Add a router.
- XBT_DEBUG(" ");
- XBT_DEBUG("<router id=\"%s\"/>", cluster->router_id.c_str());
- if (cluster->router_id.empty())
- cluster->router_id = std::string(cluster->prefix) + cluster->id + "_router" + cluster->suffix;
- current_zone->set_router(current_zone->create_router(cluster->router_id));
-
- // Make the backbone
- if ((cluster->bb_bw > 0) || (cluster->bb_lat > 0)) {
- std::string bb_name = std::string(cluster->id) + "_backbone";
- XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/> <!--backbone -->", bb_name.c_str(), cluster->bb_bw,
- cluster->bb_lat);
-
- auto* backbone = current_zone->create_link(bb_name, std::vector<double>{cluster->bb_bw})
- ->set_sharing_policy(cluster->bb_sharing_policy)
- ->set_latency(cluster->bb_lat)
- ->seal()
- ->get_impl();
- current_zone->set_backbone(backbone);
- }
-
- XBT_DEBUG("</zone>");
- sg_platf_new_Zone_seal();
- simgrid::kernel::routing::on_cluster_creation(*cluster);
-}
-void sg_platf_new_tag_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster)
-{
- switch (cluster->topology) {
- case simgrid::kernel::routing::ClusterTopology::TORUS:
- case simgrid::kernel::routing::ClusterTopology::DRAGONFLY:
- case simgrid::kernel::routing::ClusterTopology::FAT_TREE:
- sg_platf_new_cluster_hierarchical(cluster);
- break;
- default:
- sg_platf_new_cluster_flat2(cluster);
- break;
- }
-}
/*************************************************************************************************/
-
void sg_platf_new_route(simgrid::kernel::routing::RouteCreationArgs* route)
{
routing_get_current()->add_route(route->src, route->dst, route->gw_src, route->gw_dst, route->link_list,