Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Initializing SimGrid's model in another way
authorBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 11 Mar 2021 17:19:38 +0000 (18:19 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 11 Mar 2021 17:29:55 +0000 (18:29 +0100)
Preparing the field to change models type to primary/virtual.
To do so, we need another way to set the "default" models in the root
netzone.

For that, we changed the order we created the zone during the XML
parser:
1) Create the netzone object (and set as root netzone if it's the first)
2) Create the simgrid's models (if
  2.1) During the initialization of simgrid's models (by the
surf_model_description_t structure), the default models are set in the
root netzone
3) If it's a child netzone, copy models from its father

Probably temporary changes:
- Create setters for each model in the NetZoneImpl. To be reviewed after
we decided where to put the "default" models.

16 files changed:
include/simgrid/kernel/routing/NetZoneImpl.hpp
src/kernel/activity/CommImpl.cpp
src/kernel/routing/NetZoneImpl.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_ti.cpp
src/surf/disk_s19.cpp
src/surf/host_clm03.cpp
src/surf/network_cm02.cpp
src/surf/network_constant.cpp
src/surf/network_ib.cpp
src/surf/network_ns3.cpp
src/surf/network_smpi.cpp
src/surf/ptask_L07.cpp
src/surf/sg_platf.cpp
teshsuite/surf/surf_usage/surf_usage.cpp
teshsuite/surf/surf_usage2/surf_usage2.cpp

index d530a4e..b43331a 100644 (file)
@@ -70,11 +70,11 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder {
 
   std::map<std::pair<NetPoint*, NetPoint*>, BypassRoute*> bypass_routes_; // src x dst -> route
   routing::NetPoint* netpoint_ = nullptr;                                 // Our representative in the father NetZone
-  resource::NetworkModel* network_model_;
-  resource::CpuModel* cpu_model_vm_;
-  resource::CpuModel* cpu_model_pm_;
-  resource::DiskModel* disk_model_;
-  simgrid::surf::HostModel* host_model_;
+  std::shared_ptr<resource::NetworkModel> network_model_;
+  std::shared_ptr<resource::CpuModel> cpu_model_vm_;
+  std::shared_ptr<resource::CpuModel> cpu_model_pm_;
+  std::shared_ptr<resource::DiskModel> disk_model_;
+  std::shared_ptr<simgrid::surf::HostModel> host_model_;
   /** @brief Perform sealing procedure for derived classes, if necessary */
   virtual void do_seal(){};
 
@@ -109,15 +109,15 @@ public:
   RoutingMode hierarchy_ = RoutingMode::unset;
 
   /** @brief Retrieves the network model associated to this NetZone */
-  resource::NetworkModel* get_network_model() const { return network_model_; }
+  const std::shared_ptr<resource::NetworkModel>& get_network_model() const { return network_model_; }
   /** @brief Retrieves the CPU model for virtual machines associated to this NetZone */
-  resource::CpuModel* get_cpu_vm_model() const { return cpu_model_vm_; }
+  const std::shared_ptr<resource::CpuModel>& get_cpu_vm_model() const { return cpu_model_vm_; }
   /** @brief Retrieves the CPU model for physical machines associated to this NetZone */
-  resource::CpuModel* get_cpu_pm_model() const { return cpu_model_pm_; }
+  const std::shared_ptr<resource::CpuModel>& get_cpu_pm_model() const { return cpu_model_pm_; }
   /** @brief Retrieves the disk model associated to this NetZone */
-  resource::DiskModel* get_disk_model() const { return disk_model_; }
+  const std::shared_ptr<resource::DiskModel>& get_disk_model() const { return disk_model_; }
   /** @brief Retrieves the host model associated to this NetZone */
-  simgrid::surf::HostModel* get_host_model() const { return host_model_; }
+  const std::shared_ptr<surf::HostModel>& get_host_model() const { return host_model_; }
 
   const s4u::NetZone* get_iface() const { return &piface_; }
   s4u::NetZone* get_iface() { return &piface_; }
@@ -155,7 +155,11 @@ public:
   /** @brief Set parent of this Netzone */
   void set_parent(NetZoneImpl* parent);
   /** @brief Set network model for this Netzone */
-  void set_network_model(simgrid::kernel::resource::NetworkModel* netmodel);
+  void set_network_model(std::shared_ptr<resource::NetworkModel> netmodel);
+  void set_cpu_vm_model(std::shared_ptr<resource::CpuModel> cpu_model);
+  void set_cpu_pm_model(std::shared_ptr<resource::CpuModel> cpu_model);
+  void set_disk_model(std::shared_ptr<resource::DiskModel> disk_model);
+  void set_host_model(std::shared_ptr<surf::HostModel> host_model);
 
   /* @brief get the route between two nodes in the full platform
    *
index f8de83a..a99954b 100644 (file)
@@ -434,7 +434,7 @@ CommImpl* CommImpl::start()
     /* FIXME[donassolo]: getting the network_model from the origin host
      * Soon we need to change this function to first get the routes and later
      * create the respective surf actions */
-    auto* net_model = from_->get_netpoint()->get_englobing_zone()->get_network_model();
+    auto net_model = from_->get_netpoint()->get_englobing_zone()->get_network_model();
 
     surf_action_ = net_model->communicate(from_, to_, size_, rate_);
     surf_action_->set_activity(this);
index 94ef8be..4dd41be 100644 (file)
@@ -26,14 +26,6 @@ NetZoneImpl::NetZoneImpl(const std::string& name) : piface_(this), name_(name)
   xbt_assert(nullptr == s4u::Engine::get_instance()->netpoint_by_name_or_null(get_name()),
              "Refusing to create a second NetZone called '%s'.", get_cname());
   netpoint_     = new NetPoint(name_, NetPoint::Type::NetZone);
-  cpu_model_vm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
-      simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::CPU_VM));
-  cpu_model_pm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
-      simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::CPU_PM));
-  disk_model_ = static_cast<simgrid::kernel::resource::DiskModel*>(
-      simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::DISK));
-  host_model_ = static_cast<simgrid::surf::HostModel*>(
-      simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::HOST));
   XBT_DEBUG("NetZone '%s' created with the id '%u'", get_cname(), netpoint_->id());
 }
 
@@ -413,10 +405,34 @@ void NetZoneImpl::set_parent(NetZoneImpl* parent)
   netpoint_->set_englobing_zone(father_);
 }
 
-void NetZoneImpl::set_network_model(simgrid::kernel::resource::NetworkModel* netmodel)
+void NetZoneImpl::set_network_model(std::shared_ptr<resource::NetworkModel> netmodel)
 {
   xbt_assert(sealed_ == false, "Impossible to set network model to an already sealed NetZone(%s)", this->get_cname());
-  network_model_ = netmodel;
+  network_model_ = std::move(netmodel);
+}
+
+void NetZoneImpl::set_cpu_vm_model(std::shared_ptr<resource::CpuModel> cpu_model)
+{
+  xbt_assert(sealed_ == false, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname());
+  cpu_model_vm_ = std::move(cpu_model);
+}
+
+void NetZoneImpl::set_cpu_pm_model(std::shared_ptr<resource::CpuModel> cpu_model)
+{
+  xbt_assert(sealed_ == false, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname());
+  cpu_model_pm_ = std::move(cpu_model);
+}
+
+void NetZoneImpl::set_disk_model(std::shared_ptr<resource::DiskModel> disk_model)
+{
+  xbt_assert(sealed_ == false, "Impossible to set disk model to an already sealed NetZone(%s)", this->get_cname());
+  disk_model_ = std::move(disk_model);
+}
+
+void NetZoneImpl::set_host_model(std::shared_ptr<surf::HostModel> host_model)
+{
+  xbt_assert(sealed_ == false, "Impossible to set host model to an already sealed NetZone(%s)", this->get_cname());
+  host_model_ = std::move(host_model);
 }
 
 } // namespace routing
index 973cadc..cd9544b 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "cpu_cas01.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "simgrid/sg_config.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
@@ -49,11 +51,14 @@ void surf_cpu_model_init_Cas01()
     algo = simgrid::kernel::resource::Model::UpdateAlgo::FULL;
 
   auto cpu_model_pm = std::make_shared<simgrid::kernel::resource::CpuCas01Model>(algo);
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM,
-                                                         std::move(cpu_model_pm), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM, cpu_model_pm,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_cpu_pm_model(cpu_model_pm);
+
   auto cpu_model_vm = std::make_shared<simgrid::kernel::resource::CpuCas01Model>(algo);
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM,
-                                                         std::move(cpu_model_vm), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM, cpu_model_vm,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_cpu_vm_model(cpu_model_vm);
 }
 
 namespace simgrid {
index c62b93b..6492de2 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "cpu_ti.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
 #include "src/kernel/resource/profile/Profile.hpp"
@@ -269,16 +271,16 @@ int CpuTiProfile::binary_search(const std::vector<double>& array, double a)
 void CpuTiModel::create_pm_vm_models()
 {
   auto cpu_model_pm = std::make_shared<CpuTiModel>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM,
-                                                         std::move(cpu_model_pm), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM, cpu_model_pm,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_cpu_pm_model(cpu_model_pm);
   auto cpu_model_vm = std::make_shared<CpuTiModel>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM,
-                                                         std::move(cpu_model_vm), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM, cpu_model_vm,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_cpu_vm_model(cpu_model_vm);
 }
 
-CpuTiModel::CpuTiModel() : CpuModel(Model::UpdateAlgo::FULL)
-{
-}
+CpuTiModel::CpuTiModel() : CpuModel(Model::UpdateAlgo::FULL) {}
 
 Cpu* CpuTiModel::create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
 {
index c39c8f9..8e910ff 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "disk_s19.hpp"
 #include "simgrid/kernel/routing/NetPoint.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "src/kernel/EngineImpl.hpp"
@@ -21,8 +22,9 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_disk);
 void surf_disk_model_init_default()
 {
   auto disk_model = std::make_shared<simgrid::kernel::resource::DiskS19Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::DISK,
-                                                         std::move(disk_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::DISK, disk_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_disk_model(disk_model);
 }
 
 namespace simgrid {
index fb5bab9..c29dd27 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "src/surf/host_clm03.hpp"
 #include "simgrid/kernel/routing/NetPoint.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "simgrid/sg_config.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "surf/surf.hpp"
@@ -15,8 +17,9 @@ void surf_host_model_init_current_default()
 {
   auto host_model = std::make_shared<simgrid::surf::HostCLM03Model>();
   simgrid::config::set_default<bool>("network/crosstraffic", true);
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
-                                                         std::move(host_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST, host_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_host_model(host_model);
   surf_cpu_model_init_Cas01();
   surf_network_model_init_LegrandVelho();
 }
@@ -24,8 +27,9 @@ void surf_host_model_init_current_default()
 void surf_host_model_init_compound()
 {
   auto host_model = std::make_shared<simgrid::surf::HostCLM03Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
-                                                         std::move(host_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST, host_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_host_model(host_model);
 }
 
 namespace simgrid {
@@ -58,7 +62,7 @@ kernel::resource::Action* HostCLM03Model::execute_parallel(const std::vector<s4u
   /* FIXME[donassolo]: getting the network_model from the origin host
    * Soon we need to change this function to first get the routes and later
    * create the respective surf actions */
-  auto* net_model = host_list[0]->get_netpoint()->get_englobing_zone()->get_network_model();
+  auto net_model = host_list[0]->get_netpoint()->get_englobing_zone()->get_network_model();
   if ((host_list.size() == 1) && (has_cost(bytes_amount, 0) <= 0) && (has_cost(flops_amount, 0) > 0)) {
     action = host_list[0]->pimpl_cpu->execution_start(flops_amount[0]);
   } else if ((host_list.size() == 1) && (has_cost(flops_amount, 0) <= 0)) {
index 856bc11..a392cd3 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/surf/network_cm02.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/sg_config.hpp"
 #include "src/kernel/EngineImpl.hpp"
@@ -38,8 +40,9 @@ double sg_weight_S_parameter = 0.0; /* default value; can be set by model or fro
 void surf_network_model_init_LegrandVelho()
 {
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 
   simgrid::config::set_default<double>("network/latency-factor", 13.01);
   simgrid::config::set_default<double>("network/bandwidth-factor", 0.97);
@@ -64,8 +67,9 @@ void surf_network_model_init_CM02()
   simgrid::config::set_default<double>("network/weight-S", 0.0);
 
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 }
 
 namespace simgrid {
index 2fc20ce..ba728d4 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "network_constant.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/surf/surf_interface.hpp"
 #include "surf/surf.hpp"
@@ -16,17 +18,16 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
 void surf_network_model_init_Constant()
 {
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkConstantModel>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 }
 
 namespace simgrid {
 namespace kernel {
 namespace resource {
 
-NetworkConstantModel::NetworkConstantModel() : NetworkModel(Model::UpdateAlgo::FULL)
-{
-}
+NetworkConstantModel::NetworkConstantModel() : NetworkModel(Model::UpdateAlgo::FULL) {}
 
 LinkImpl* NetworkConstantModel::create_link(const std::string& name, const std::vector<double>& /*bandwidth*/,
                                             s4u::Link::SharingPolicy)
index 6bd014a..6daaa8c 100644 (file)
@@ -22,7 +22,7 @@ static void IB_create_host_callback(simgrid::s4u::Host const& host)
   using simgrid::kernel::resource::NetworkIBModel;
 
   static int id = 0;
-  auto* ibModel = static_cast<NetworkIBModel*>(host.get_netpoint()->get_englobing_zone()->get_network_model());
+  auto* ibModel = static_cast<NetworkIBModel*>(host.get_netpoint()->get_englobing_zone()->get_network_model().get());
   ibModel->active_nodes.emplace(host.get_name(), IBNode(id));
   id++;
 }
@@ -70,8 +70,9 @@ static void IB_action_init_callback(simgrid::kernel::resource::NetworkAction& ac
 void surf_network_model_init_IB()
 {
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkIBModel>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 
   simgrid::s4u::Link::on_communication_state_change.connect(IB_action_state_changed_callback);
   simgrid::s4u::Link::on_communicate.connect(IB_action_init_callback);
index dc283e2..cba54fc 100644 (file)
@@ -28,6 +28,7 @@
 #include "ns3/ns3_simulator.hpp"
 
 #include "simgrid/kernel/routing/NetPoint.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
 #include "simgrid/kernel/routing/WifiZone.hpp"
 #include "simgrid/plugins/energy.h"
 #include "simgrid/s4u/Engine.hpp"
@@ -260,8 +261,9 @@ static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoin
 void surf_network_model_init_NS3()
 {
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkNS3Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 }
 
 static simgrid::config::Flag<std::string>
index 72e8c02..0c32b4f 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "network_smpi.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "simgrid/sg_config.hpp"
 #include "smpi_utils.hpp"
 #include "src/kernel/EngineImpl.hpp"
@@ -34,8 +36,9 @@ std::vector<s_smpi_factor_t> smpi_lat_factor;
 void surf_network_model_init_SMPI()
 {
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkSmpiModel>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 
   simgrid::config::set_default<double>("network/weight-S", 8775);
 }
@@ -44,9 +47,7 @@ namespace simgrid {
 namespace kernel {
 namespace resource {
 
-NetworkSmpiModel::NetworkSmpiModel() : NetworkCm02Model()
-{
-}
+NetworkSmpiModel::NetworkSmpiModel() : NetworkCm02Model() {}
 
 double NetworkSmpiModel::get_bandwidth_factor(double size)
 {
index dbb89d7..d735582 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "ptask_L07.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
 #include "surf/surf.hpp"
@@ -22,8 +24,9 @@ void surf_host_model_init_ptask_L07()
   XBT_CINFO(xbt_cfg, "Switching to the L07 model to handle parallel tasks.");
 
   auto host_model = std::make_shared<simgrid::surf::HostL07Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
-                                                         std::move(host_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST, host_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_host_model(host_model);
 }
 
 namespace simgrid {
@@ -36,10 +39,12 @@ HostL07Model::HostL07Model() : HostModel()
 
   auto net_model = std::make_shared<NetworkL07Model>(this, maxmin_system);
   auto engine    = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model(simgrid::kernel::resource::Model::Type::NETWORK, std::move(net_model), true);
+  engine->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model, true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 
   auto cpu_model = std::make_shared<CpuL07Model>(this, maxmin_system);
-  engine->add_model(simgrid::kernel::resource::Model::Type::CPU_PM, std::move(cpu_model), true);
+  engine->add_model(simgrid::kernel::resource::Model::Type::CPU_PM, cpu_model, true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_cpu_pm_model(cpu_model);
 }
 
 CpuL07Model::CpuL07Model(HostL07Model* hmodel, kernel::lmm::System* sys)
index 0bbe851..c71b8b2 100644 (file)
@@ -484,41 +484,17 @@ static void surf_config_models_setup()
 }
 
 /**
- * @brief Add a Zone to the platform
- *
- * Add a new autonomous system to the platform. Any elements (such as host, router or sub-Zone) added after this call
- * and before the corresponding call to sg_platf_new_Zone_seal() will be added to this Zone.
- *
- * Once this function was called, the configuration concerning the used models cannot be changed anymore.
+ * @brief Auxiliary function to build the object NetZoneImpl
  *
+ * Builds the objects, setting its father properties and root netzone if needed
  * @param zone the parameters defining the Zone to build.
+ * @return Pointer to recently created netzone
  */
-simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::kernel::routing::ZoneCreationArgs* zone)
+static simgrid::kernel::routing::NetZoneImpl*
+sg_platf_create_zone(const simgrid::kernel::routing::ZoneCreationArgs* zone)
 {
-  if (not surf_parse_models_setup_already_called) {
-    simgrid::s4u::Engine::on_platform_creation();
-
-    /* Initialize the surf models. That must be done after we got all config, and before we need the models.
-     * That is, after the last <config> tag, if any, and before the first of cluster|peer|zone|trace|trace_connect
-     *
-     * I'm not sure for <trace> and <trace_connect>, there may be a bug here
-     * (FIXME: check it out by creating a file beginning with one of these tags)
-     * but cluster and peer come down to zone creations, so putting this verification here is correct.
-     */
-    surf_parse_models_setup_already_called = 1;
-    surf_config_models_setup();
-  }
-
-  _sg_cfg_init_status = 2; /* HACK: direct access to the global controlling the level of configuration to prevent
-                            * any further config now that we created some real content */
-
   /* search the routing model */
   simgrid::kernel::routing::NetZoneImpl* new_zone = nullptr;
-  simgrid::kernel::resource::NetworkModel* netmodel =
-      current_routing == nullptr ? static_cast<simgrid::kernel::resource::NetworkModel*>(
-                                       simgrid::kernel::EngineImpl::get_instance()->get_default_model(
-                                           simgrid::kernel::resource::Model::Type::NETWORK))
-                                 : current_routing->get_network_model();
 
   if (strcasecmp(zone->routing.c_str(), "Cluster") == 0) {
     new_zone = new simgrid::kernel::routing::ClusterZone(zone->id);
@@ -546,7 +522,6 @@ simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::ke
     xbt_die("Not a valid model!");
   }
   new_zone->set_parent(current_routing);
-  new_zone->set_network_model(netmodel);
 
   if (current_routing == nullptr) { /* it is the first one */
     simgrid::s4u::Engine::get_instance()->set_netzone_root(new_zone->get_iface());
@@ -556,8 +531,51 @@ simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::ke
       current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::recursive;
     /* add to the sons dictionary */
     current_routing->get_children()->push_back(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());
+    new_zone->set_cpu_vm_model(current_routing->get_cpu_vm_model());
+    new_zone->set_disk_model(current_routing->get_disk_model());
+    new_zone->set_host_model(current_routing->get_host_model());
+  }
+  return new_zone;
+}
+
+/**
+ * @brief Add a Zone to the platform
+ *
+ * Add a new autonomous system to the platform. Any elements (such as host, router or sub-Zone) added after this call
+ * and before the corresponding call to sg_platf_new_Zone_seal() will be added to this Zone.
+ *
+ * Once this function was called, the configuration concerning the used models cannot be changed anymore.
+ *
+ * @param zone the parameters defining the Zone to build.
+ */
+simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::kernel::routing::ZoneCreationArgs* zone)
+{
+  /* First create the zone.
+   * This order is important to assure that root netzone is set when models are setting
+   * the default mode for each resource (CPU, network, etc)
+   */
+  auto* new_zone = sg_platf_create_zone(zone);
+
+  if (not surf_parse_models_setup_already_called) {
+    simgrid::s4u::Engine::on_platform_creation();
+
+    /* Initialize the surf models. That must be done after we got all config, and before we need the models.
+     * That is, after the last <config> tag, if any, and before the first of cluster|peer|zone|trace|trace_connect
+     *
+     * I'm not sure for <trace> and <trace_connect>, there may be a bug here
+     * (FIXME: check it out by creating a file beginning with one of these tags)
+     * but cluster and peer come down to zone creations, so putting this verification here is correct.
+     */
+    surf_parse_models_setup_already_called = 1;
+    surf_config_models_setup();
   }
 
+  _sg_cfg_init_status = 2; /* HACK: direct access to the global controlling the level of configuration to prevent
+                            * any further config now that we created some real content */
+
   /* set the new current component of the tree */
   current_routing = new_zone;
   simgrid::s4u::NetZone::on_creation(*new_zone->get_iface()); // notify the signal
index 1286111..5cf04a0 100644 (file)
@@ -42,12 +42,12 @@ int main(int argc, char** argv)
   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
   parse_platform_file(argv[1]);
 
-  const_sg_netzone_t as_zone                         = sg_zone_get_by_name("AS0");
-  simgrid::kernel::resource::NetworkModel* net_model = as_zone->get_impl()->get_network_model();
-  simgrid::kernel::resource::CpuModel* cpu_model_pm  = as_zone->get_impl()->get_cpu_pm_model();
+  const_sg_netzone_t as_zone = sg_zone_get_by_name("AS0");
+  auto net_model             = as_zone->get_impl()->get_network_model();
+  auto cpu_model_pm          = as_zone->get_impl()->get_cpu_pm_model();
 
-  XBT_DEBUG("CPU model: %p", cpu_model_pm);
-  XBT_DEBUG("Network model: %p", net_model);
+  XBT_DEBUG("CPU model: %p", cpu_model_pm.get());
+  XBT_DEBUG("Network model: %p", net_model.get());
   simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
   simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
 
index 5288350..c79d19b 100644 (file)
@@ -38,8 +38,8 @@ int main(int argc, char** argv)
   hostB->pimpl_cpu->execution_start(1000.0);
   hostB->pimpl_cpu->sleep(7.32);
 
-  const_sg_netzone_t as_zone                         = sg_zone_get_by_name("AS0");
-  simgrid::kernel::resource::NetworkModel* net_model = as_zone->get_impl()->get_network_model();
+  const_sg_netzone_t as_zone = sg_zone_get_by_name("AS0");
+  auto net_model             = as_zone->get_impl()->get_network_model();
   net_model->communicate(hostA, hostB, 150.0, -1.0);
 
   surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */