From 8b1c61e4ab2768975287e5ec62ca850c79d69bdc Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Mon, 22 Mar 2021 13:58:24 +0100 Subject: [PATCH] NetZone: father to parent and more accessors --- .../simgrid/kernel/routing/NetZoneImpl.hpp | 7 +++++-- include/simgrid/s4u/NetZone.hpp | 12 ++++++----- src/kernel/routing/NetZoneImpl.cpp | 12 +++++------ src/s4u/s4u_Netzone.cpp | 21 ++++++++++++++++++- src/surf/sg_platf.cpp | 4 ++-- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index b43331a348..421fa3e0b1 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -63,7 +63,7 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder { // our content, as known to our graph routing algorithm (maps vertex_id -> vertex) std::vector vertices_; - NetZoneImpl* father_ = nullptr; + NetZoneImpl* parent_ = nullptr; std::vector children_; // sub-netzones std::string name_; bool sealed_ = false; // We cannot add more content when sealed @@ -123,10 +123,13 @@ public: s4u::NetZone* get_iface() { return &piface_; } unsigned int get_table_size() const { return vertices_.size(); } std::vector get_vertices() const { return vertices_; } - NetZoneImpl* get_father() const { return father_; } + XBT_ATTRIB_DEPRECATED_v331("Please use get_parent()") NetZoneImpl* get_father() const { return parent_; } + NetZoneImpl* get_parent() const { return parent_; } /** @brief Returns the list of direct children (no grand-children). This returns the internal data, no copy. * Don't mess with it.*/ std::vector* get_children() { return &children_; } + void add_child(NetZoneImpl* new_zone) { children_.push_back(new_zone); } + /** @brief Retrieves the name of that netzone as a C++ string */ const std::string& get_name() const { return name_; } /** @brief Retrieves the name of that netzone as a C string */ diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index 870accb5d3..09ef29cf7a 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -26,6 +26,8 @@ namespace s4u { * s4u::Engine). */ class XBT_PUBLIC NetZone { + kernel::routing::NetZoneImpl* const pimpl_; + protected: friend kernel::routing::NetZoneImpl; @@ -37,17 +39,15 @@ public: /** @brief Retrieves the name of that netzone as a C string */ const char* get_cname() const; - NetZone* get_father(); + XBT_ATTRIB_DEPRECATED_v331("Please use get_parent()") NetZone* get_father(); + NetZone* get_parent() const; + NetZone* set_parent(NetZone* parent); std::vector get_all_hosts() const; int get_host_count() const; kernel::routing::NetZoneImpl* get_impl() const { return pimpl_; } -private: - kernel::routing::NetZoneImpl* const pimpl_; - -public: /** Get the properties assigned to a netzone */ const std::unordered_map* get_properties() const; /** Retrieve the property value (or nullptr if not set) */ @@ -55,6 +55,8 @@ public: void set_property(const std::string& key, const std::string& value); std::vector get_children() const; + NetZone* add_child(NetZone* new_zone); + void extract_xbt_graph(const s_xbt_graph_t* graph, std::map>* nodes, std::map>* edges); diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 4dd41beb6d..f11c9cddfd 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -212,13 +212,13 @@ static void find_common_ancestors(NetPoint* src, NetPoint* dst, NetZoneImpl* current = src->get_englobing_zone(); while (current != nullptr) { path_src.push_back(current); - current = current->get_father(); + current = current->get_parent(); } std::vector path_dst; current = dst->get_englobing_zone(); while (current != nullptr) { path_dst.push_back(current); - current = current->get_father(); + current = current->get_parent(); } /* (3) find the common father. @@ -276,14 +276,14 @@ bool NetZoneImpl::get_bypass_route(NetPoint* src, NetPoint* dst, NetZoneImpl* current = src->get_englobing_zone(); while (current != nullptr) { path_src.push_back(current); - current = current->father_; + current = current->parent_; } std::vector path_dst; current = dst->get_englobing_zone(); while (current != nullptr) { path_dst.push_back(current); - current = current->father_; + current = current->parent_; } /* (2) find the common father */ @@ -401,8 +401,8 @@ void NetZoneImpl::seal() void NetZoneImpl::set_parent(NetZoneImpl* parent) { xbt_assert(sealed_ == false, "Impossible to set parent to an already sealed NetZone(%s)", this->get_cname()); - father_ = parent; - netpoint_->set_englobing_zone(father_); + parent_ = parent; + netpoint_->set_englobing_zone(parent_); } void NetZoneImpl::set_network_model(std::shared_ptr netmodel) diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index 0a18e0cefd..8858aa31e8 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -45,17 +45,36 @@ std::vector NetZone::get_children() const return res; } +NetZone* NetZone::add_child(NetZone* new_zone) +{ + pimpl_->add_child(new_zone->get_impl()); + return this; +} + const std::string& NetZone::get_name() const { return pimpl_->get_name(); } + const char* NetZone::get_cname() const { return pimpl_->get_cname(); } + NetZone* NetZone::get_father() { - return pimpl_->get_father()->get_iface(); + return pimpl_->get_parent()->get_iface(); +} + +NetZone* NetZone::get_parent() const +{ + return pimpl_->get_parent()->get_iface(); +} + +NetZone* NetZone::set_parent(NetZone* parent) +{ + pimpl_->set_parent(parent->get_impl()); + return this; } /** @brief Returns the list of the hosts found in this NetZone (not recursively) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 618e36063f..34cfd07655 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -528,7 +528,7 @@ sg_platf_create_zone(const simgrid::kernel::routing::ZoneCreationArgs* zone) if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset) current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::recursive; /* add to the sons dictionary */ - current_routing->get_children()->push_back(new_zone); + current_routing->add_child(new_zone); /* set models from parent netzone */ new_zone->set_network_model(current_routing->get_network_model()); new_zone->set_cpu_pm_model(current_routing->get_cpu_pm_model()); @@ -600,7 +600,7 @@ void sg_platf_new_Zone_seal() xbt_assert(current_routing, "Cannot seal the current Zone: zone under construction"); current_routing->seal(); simgrid::s4u::NetZone::on_seal(*current_routing->get_iface()); - current_routing = current_routing->get_father(); + current_routing = current_routing->get_parent(); } /** @brief Add a link connecting a host to the rest of its Zone (which must be cluster or vivaldi) */ -- 2.20.1