Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
NetZone: father to parent and more accessors
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Mon, 22 Mar 2021 12:58:24 +0000 (13:58 +0100)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Mon, 22 Mar 2021 15:41:54 +0000 (16:41 +0100)
include/simgrid/kernel/routing/NetZoneImpl.hpp
include/simgrid/s4u/NetZone.hpp
src/kernel/routing/NetZoneImpl.cpp
src/s4u/s4u_Netzone.cpp
src/surf/sg_platf.cpp

index b43331a..421fa3e 100644 (file)
@@ -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<kernel::routing::NetPoint*> vertices_;
 
-  NetZoneImpl* father_ = nullptr;
+  NetZoneImpl* parent_ = nullptr;
   std::vector<NetZoneImpl*> 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<kernel::routing::NetPoint*> 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<NetZoneImpl*>* 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 */
index 870accb..09ef29c 100644 (file)
@@ -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<Host*> 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<std::string, std::string>* 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<NetZone*> get_children() const;
+  NetZone* add_child(NetZone* new_zone);
+
   void extract_xbt_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);
 
index 4dd41be..f11c9cd 100644 (file)
@@ -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<NetZoneImpl*> 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<NetZoneImpl*> 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<resource::NetworkModel> netmodel)
index 0a18e0c..8858aa3 100644 (file)
@@ -45,17 +45,36 @@ std::vector<NetZone*> 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)
index 618e360..34cfd07 100644 (file)
@@ -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) */