Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Misc sonar and codefactor.io issues.
[simgrid.git] / src / surf / network_cm02.cpp
index 5037e6a..73e4ba8 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2013-2022. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
 
+/***********
+ * Options *
+ ***********/
+static simgrid::config::Flag<std::string> cfg_network_solver("network/solver",
+                                                             "Set linear equations solver used by network model",
+                                                             "maxmin", &simgrid::kernel::lmm::System::validate_solver);
+
 double sg_latency_factor     = 1.0; /* default value; can be set by model or from command line */
 double sg_bandwidth_factor   = 1.0; /* default value; can be set by model or from command line */
 double sg_weight_S_parameter = 0.0; /* default value; can be set by model or from command line */
@@ -72,9 +79,7 @@ void surf_network_model_init_CM02()
   engine->get_netzone_root()->set_network_model(net_model);
 }
 
-namespace simgrid {
-namespace kernel {
-namespace resource {
+namespace simgrid::kernel::resource {
 
 NetworkCm02Model::NetworkCm02Model(const std::string& name) : NetworkModel(name)
 {
@@ -88,11 +93,12 @@ NetworkCm02Model::NetworkCm02Model(const std::string& name) : NetworkModel(name)
     select = true;
   }
 
-  set_maxmin_system(new lmm::System(select));
-  loopback_ = create_link("__loopback__", {config::get_value<double>("network/loopback-bw")});
+  set_maxmin_system(lmm::System::build(cfg_network_solver.get(), select));
+
+  loopback_.reset(create_link("__loopback__", {config::get_value<double>("network/loopback-bw")}));
   loopback_->set_sharing_policy(s4u::Link::SharingPolicy::FATPIPE, {});
   loopback_->set_latency(config::get_value<double>("network/loopback-lat"));
-  loopback_->seal();
+  loopback_->get_iface()->seal();
 }
 
 void NetworkCm02Model::check_lat_factor_cb()
@@ -174,13 +180,10 @@ void NetworkCm02Model::update_actions_state_full(double /*now*/, double delta)
     auto& action = static_cast<NetworkCm02Action&>(*it);
     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
     XBT_DEBUG("Something happened to action %p", &action);
-    double deltap = delta;
     if (action.latency_ > 0) {
-      if (action.latency_ > deltap) {
-        double_update(&action.latency_, deltap, sg_surf_precision);
-        deltap = 0.0;
+      if (action.latency_ > delta) {
+        double_update(&action.latency_, delta, sg_surf_precision);
       } else {
-        double_update(&deltap, action.latency_, sg_surf_precision);
         action.latency_ = 0.0;
       }
       if (action.latency_ <= 0.0 && not action.is_suspended())
@@ -221,12 +224,23 @@ void NetworkCm02Model::comm_action_expand_constraints(const s4u::Host* src, cons
   }
 
   /* WI-FI links needs special treatment, do it here */
-  if (src_wifi_link != nullptr)
-    get_maxmin_system()->expand(src_wifi_link->get_constraint(), action->get_variable(),
-                                1.0 / src_wifi_link->get_host_rate(src));
-  if (dst_wifi_link != nullptr)
-    get_maxmin_system()->expand(dst_wifi_link->get_constraint(), action->get_variable(),
-                                1.0 / dst_wifi_link->get_host_rate(dst));
+  if (src_wifi_link != nullptr) {
+    if (src_wifi_link->get_host_rate(src) > 0)
+      get_maxmin_system()->expand(src_wifi_link->get_constraint(), action->get_variable(),
+                                  1.0 / src_wifi_link->get_host_rate(src));
+    else {
+      get_maxmin_system()->update_variable_penalty(action->get_variable(), 0);
+    }
+  }
+
+  if (dst_wifi_link != nullptr) {
+    if (dst_wifi_link->get_host_rate(dst) > 0)
+      get_maxmin_system()->expand(dst_wifi_link->get_constraint(), action->get_variable(),
+                                  1.0 / dst_wifi_link->get_host_rate(dst));
+    else {
+      get_maxmin_system()->update_variable_penalty(action->get_variable(), 0);
+    }
+  }
 
   for (auto const* link : route) {
     if (link->get_sharing_policy() != s4u::Link::SharingPolicy::WIFI)
@@ -246,9 +260,6 @@ void NetworkCm02Model::comm_action_expand_constraints(const s4u::Host* src, cons
       if (link->get_sharing_policy() != s4u::Link::SharingPolicy::WIFI)
         get_maxmin_system()->expand(link->get_constraint(), action->get_variable(), .05);
     }
-    // Change concurrency_share here, if you want that cross-traffic is included in the SURF concurrency
-    // (You would also have to change simgrid::kernel::lmm::Element::get_concurrency())
-    // action->getVariable()->set_concurrency_share(2)
   }
 }
 
@@ -316,11 +327,10 @@ bool NetworkCm02Model::comm_get_route_info(const s4u::Host* src, const s4u::Host
 
   bool failed = std::any_of(route.begin(), route.end(), [](const StandardLinkImpl* link) { return not link->is_on(); });
 
-  if (cfg_crosstraffic) {
+  if (not failed && cfg_crosstraffic) {
     dst->route_to(src, back_route, nullptr);
-    if (not failed)
-      failed = std::any_of(back_route.begin(), back_route.end(),
-                           [](const StandardLinkImpl* link) { return not link->is_on(); });
+    failed = std::any_of(back_route.begin(), back_route.end(),
+                         [](const StandardLinkImpl* link) { return not link->is_on(); });
   }
   return failed;
 }
@@ -570,6 +580,4 @@ void NetworkCm02Action::update_remains_lazy(double now)
   set_last_value(get_rate());
 }
 
-} // namespace resource
-} // namespace kernel
-} // namespace simgrid
+} // namespace simgrid::kernel::resource