Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / surf / network_constant.cpp
index b8e9606..6183b2d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2013-2023. 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. */
@@ -15,17 +15,19 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
 /*********
  * Model *
  *********/
-void surf_network_model_init_Constant()
-{
-  auto net_model = std::make_shared<simgrid::kernel::resource::NetworkConstantModel>("Network_Constant");
-  auto* engine   = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model(net_model);
-  engine->get_netzone_root()->set_network_model(net_model);
-}
+SIMGRID_REGISTER_NETWORK_MODEL(
+    Constant,
+    "Simplistic network model where all communication take a constant time (one second). This model "
+    "provides the lowest realism, but is (marginally) faster. It is mostly useful when studying theoretical "
+    "distributed algorithms where the network is usually abstracted away.",
+    []() {
+      auto net_model = std::make_shared<simgrid::kernel::resource::NetworkConstantModel>("Network_Constant");
+      auto* engine   = simgrid::kernel::EngineImpl::get_instance();
+      engine->add_model(net_model);
+      engine->get_netzone_root()->set_network_model(net_model);
+    });
 
-namespace simgrid {
-namespace kernel {
-namespace resource {
+namespace simgrid::kernel::resource {
 
 StandardLinkImpl* NetworkConstantModel::create_link(const std::string& name, const std::vector<double>& /*bandwidth*/)
 {
@@ -63,7 +65,7 @@ void NetworkConstantModel::update_actions_state(double /*now*/, double delta)
         action.latency_ = 0.0;
       }
     }
-    action.update_remains(action.get_cost() * delta / sg_latency_factor);
+    action.update_remains(action.get_cost() * delta / get_latency_factor());
     action.update_max_duration(delta);
 
     if ((action.get_remains_no_update() <= 0) ||
@@ -73,7 +75,8 @@ void NetworkConstantModel::update_actions_state(double /*now*/, double delta)
   }
 }
 
-Action* NetworkConstantModel::communicate(s4u::Host* src, s4u::Host* dst, double size, double /*rate*/)
+Action* NetworkConstantModel::communicate(s4u::Host* src, s4u::Host* dst, double size, double /*rate*/,
+                                          bool /*streamed*/)
 {
   return (new NetworkConstantAction(this, *src, *dst, size));
 }
@@ -84,7 +87,7 @@ Action* NetworkConstantModel::communicate(s4u::Host* src, s4u::Host* dst, double
 NetworkConstantAction::NetworkConstantAction(NetworkConstantModel* model_, s4u::Host& src, s4u::Host& dst, double size)
     : NetworkAction(model_, src, dst, size, false)
 {
-  latency_ = sg_latency_factor;
+  latency_ = model_->get_latency_factor();
   if (latency_ <= 0.0)
     set_state(Action::State::FINISHED);
 }
@@ -94,6 +97,4 @@ void NetworkConstantAction::update_remains_lazy(double /*now*/)
   THROW_IMPOSSIBLE;
 }
 
-} // namespace resource
-} // namespace kernel
-} // namespace simgrid
+} // namespace simgrid::kernel::resource