Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix lua compilation
[simgrid.git] / src / surf / network_cm02.cpp
index 856bc11..3ddb8ce 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"
@@ -37,9 +39,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);
+  auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>("Network_LegrandVelho");
+  simgrid::kernel::EngineImpl::get_instance()->add_model(net_model);
+  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);
@@ -63,49 +65,43 @@ void surf_network_model_init_CM02()
   simgrid::config::set_default<double>("network/bandwidth-factor", 1.0);
   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);
+  auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>("Network_CM02");
+  simgrid::kernel::EngineImpl::get_instance()->add_model(net_model);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 }
 
 namespace simgrid {
 namespace kernel {
 namespace resource {
 
-NetworkCm02Model::NetworkCm02Model()
-    : NetworkModel(config::get_value<std::string>("network/optim") == "Full" ? Model::UpdateAlgo::FULL
-                                                                             : Model::UpdateAlgo::LAZY)
+NetworkCm02Model::NetworkCm02Model(const std::string& name) : NetworkModel(name)
 {
   std::string optim = config::get_value<std::string>("network/optim");
   bool select       = config::get_value<bool>("network/maxmin-selective-update");
 
   if (optim == "Lazy") {
+    set_update_algorithm(Model::UpdateAlgo::LAZY);
     xbt_assert(select || config::is_default("network/maxmin-selective-update"),
                "You cannot disable network selective update when using the lazy update mechanism");
     select = true;
   }
 
   set_maxmin_system(new lmm::System(select));
-  loopback_ = NetworkCm02Model::create_link("__loopback__",
-                                            std::vector<double>{config::get_value<double>("network/loopback-bw")},
-                                            s4u::Link::SharingPolicy::FATPIPE)
+  loopback_ = create_link("__loopback__", std::vector<double>{config::get_value<double>("network/loopback-bw")})
+                  ->set_sharing_policy(s4u::Link::SharingPolicy::FATPIPE)
                   ->set_latency(config::get_value<double>("network/loopback-lat"));
   loopback_->seal();
 }
 
-LinkImpl* NetworkCm02Model::create_link(const std::string& name, const std::vector<double>& bandwidths,
-                                        s4u::Link::SharingPolicy policy)
+LinkImpl* NetworkCm02Model::create_link(const std::string& name, const std::vector<double>& bandwidths)
 {
-  LinkImpl* link;
-  if (policy == s4u::Link::SharingPolicy::WIFI) {
-    link = new NetworkWifiLink(name, bandwidths, get_maxmin_system());
-  } else {
-    xbt_assert(bandwidths.size() == 1, "Non-WIFI links must use only 1 bandwidth.");
-    link = new NetworkCm02Link(name, bandwidths[0], policy, get_maxmin_system());
-  }
+  xbt_assert(bandwidths.size() == 1, "Non-WIFI links must use only 1 bandwidth.");
+  return (new NetworkCm02Link(name, bandwidths[0], get_maxmin_system()))->set_model(this);
+}
 
-  link->set_model(this);
-  return link;
+LinkImpl* NetworkCm02Model::create_wifi_link(const std::string& name, const std::vector<double>& bandwidths)
+{
+  return (new NetworkWifiLink(name, bandwidths, get_maxmin_system()))->set_model(this);
 }
 
 void NetworkCm02Model::update_actions_state_lazy(double now, double /*delta*/)
@@ -313,16 +309,12 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz
 /************
  * Resource *
  ************/
-NetworkCm02Link::NetworkCm02Link(const std::string& name, double bandwidth, s4u::Link::SharingPolicy policy,
-                                 kernel::lmm::System* system)
+NetworkCm02Link::NetworkCm02Link(const std::string& name, double bandwidth, kernel::lmm::System* system)
     : LinkImpl(name)
 {
   bandwidth_.scale = 1.0;
   bandwidth_.peak  = bandwidth;
   this->set_constraint(system->constraint_new(this, sg_bandwidth_factor * bandwidth));
-
-  if (policy == s4u::Link::SharingPolicy::FATPIPE)
-    get_constraint()->unshare();
 }
 
 void NetworkCm02Link::apply_event(kernel::profile::Event* triggered, double value)
@@ -362,11 +354,10 @@ void NetworkCm02Link::set_bandwidth(double value)
   if (sg_weight_S_parameter > 0) {
     double delta = sg_weight_S_parameter / value - sg_weight_S_parameter / (bandwidth_.peak * bandwidth_.scale);
 
-    const kernel::lmm::Variable* var;
     const kernel::lmm::Element* elem     = nullptr;
     const kernel::lmm::Element* nextelem = nullptr;
     int numelem                          = 0;
-    while ((var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
+    while (const auto* var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem)) {
       auto* action = static_cast<NetworkCm02Action*>(var->get_id());
       action->sharing_penalty_ += delta;
       if (not action->is_suspended())
@@ -380,7 +371,6 @@ LinkImpl* NetworkCm02Link::set_latency(double value)
   latency_check(value);
 
   double delta = value - latency_.peak;
-  const kernel::lmm::Variable* var;
   const kernel::lmm::Element* elem     = nullptr;
   const kernel::lmm::Element* nextelem = nullptr;
   int numelem                          = 0;
@@ -388,7 +378,7 @@ LinkImpl* NetworkCm02Link::set_latency(double value)
   latency_.scale = 1.0;
   latency_.peak  = value;
 
-  while ((var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
+  while (const auto* var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem)) {
     auto* action = static_cast<NetworkCm02Action*>(var->get_id());
     action->lat_current_ += delta;
     action->sharing_penalty_ += delta;