Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid using surf_network_model global
authorBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 1 Mar 2021 18:20:22 +0000 (19:20 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 9 Mar 2021 14:17:12 +0000 (15:17 +0100)
Get network model from NetZoneImpl instead of using the global.
First step to remove global model variables.

Extra: clang-format modified files.

include/simgrid/kernel/routing/NetZoneImpl.hpp
src/kernel/activity/CommImpl.cpp
src/kernel/routing/NetZoneImpl.cpp
src/surf/network_ib.cpp
teshsuite/surf/surf_usage/surf_usage.cpp
teshsuite/surf/surf_usage2/surf_usage2.cpp

index fcb69c9..0765aa4 100644 (file)
@@ -103,6 +103,7 @@ public:
 
   resource::NetworkModel* network_model_;
 
+  resource::NetworkModel* get_network_model() const { return network_model_; }
   const s4u::NetZone* get_iface() const { return &piface_; }
   s4u::NetZone* get_iface() { return &piface_; }
   unsigned int get_table_size() const { return vertices_.size(); }
index 469cfdb..f8de83a 100644 (file)
@@ -6,6 +6,7 @@
 #include "src/kernel/activity/CommImpl.hpp"
 #include "simgrid/Exception.hpp"
 #include "simgrid/kernel/resource/Action.hpp"
+#include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/modelchecker.h"
 #include "simgrid/s4u/Host.hpp"
 #include "src/kernel/activity/MailboxImpl.hpp"
@@ -430,7 +431,12 @@ CommImpl* CommImpl::start()
     from_ = from_ != nullptr ? from_ : src_actor_->get_host();
     to_   = to_ != nullptr ? to_ : dst_actor_->get_host();
 
-    surf_action_ = surf_network_model->communicate(from_, to_, size_, rate_);
+    /* 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();
+
+    surf_action_ = net_model->communicate(from_, to_, size_, rate_);
     surf_action_->set_activity(this);
     surf_action_->set_category(get_tracing_category());
     state_ = State::RUNNING;
index d0a894a..70bcd20 100644 (file)
@@ -68,7 +68,7 @@ int NetZoneImpl::get_host_count() const
 s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector<double>& bandwidths,
                                     s4u::Link::SharingPolicy policy)
 {
-  auto* l = surf_network_model->create_link(name, bandwidths, policy);
+  auto* l = network_model_->create_link(name, bandwidths, policy);
 
   return l->get_iface();
 }
index 12ae797..f04b3fb 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/surf/network_ib.hpp"
+#include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/sg_config.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/xml/platf.hpp"
@@ -20,8 +21,8 @@ static void IB_create_host_callback(simgrid::s4u::Host const& host)
   using simgrid::kernel::resource::NetworkIBModel;
 
   static int id = 0;
-
-  ((NetworkIBModel*)surf_network_model)->active_nodes.emplace(host.get_name(), IBNode(id));
+  auto* ibModel = static_cast<NetworkIBModel*>(host.get_netpoint()->get_englobing_zone()->get_network_model());
+  ibModel->active_nodes.emplace(host.get_name(), IBNode(id));
   id++;
 }
 
@@ -29,21 +30,21 @@ static void IB_action_state_changed_callback(simgrid::kernel::resource::NetworkA
                                              simgrid::kernel::resource::Action::State /*previous*/)
 {
   using simgrid::kernel::resource::IBNode;
-  using simgrid::kernel::resource::NetworkIBModel;
 
   if (action.get_state() != simgrid::kernel::resource::Action::State::FINISHED)
     return;
-  std::pair<IBNode*, IBNode*> pair = ((NetworkIBModel*)surf_network_model)->active_comms[&action];
+  auto* ibModel                    = static_cast<simgrid::kernel::resource::NetworkIBModel*>(action.get_model());
+  std::pair<IBNode*, IBNode*> pair = ibModel->active_comms[&action];
   XBT_DEBUG("IB callback - action %p finished", &action);
 
-  ((NetworkIBModel*)surf_network_model)->updateIBfactors(&action, pair.first, pair.second, 1);
+  ibModel->updateIBfactors(&action, pair.first, pair.second, 1);
 
-  ((NetworkIBModel*)surf_network_model)->active_comms.erase(&action);
+  ibModel->active_comms.erase(&action);
 }
 
 static void IB_action_init_callback(simgrid::kernel::resource::NetworkAction& action)
 {
-  auto* ibModel = static_cast<simgrid::kernel::resource::NetworkIBModel*>(surf_network_model);
+  auto* ibModel = static_cast<simgrid::kernel::resource::NetworkIBModel*>(action.get_model());
   auto* act_src = &ibModel->active_nodes.at(action.get_src().get_name());
   auto* act_dst = &ibModel->active_nodes.at(action.get_dst().get_name());
 
index f6d4a8e..b7b46d6 100644 (file)
@@ -6,6 +6,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/host.h"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp" // full type for NetZoneImpl object
+#include "simgrid/zone.h"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
 #include "surf/surf.hpp"
@@ -40,8 +42,11 @@ int main(int argc, char** argv)
   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
   parse_platform_file(argv[1]);
 
+  sg_netzone_t as_zone                               = sg_zone_get_by_name("AS0");
+  simgrid::kernel::resource::NetworkModel* net_model = as_zone->get_impl()->get_network_model();
+
   XBT_DEBUG("CPU model: %p", surf_cpu_model_pm);
-  XBT_DEBUG("Network model: %p", surf_network_model);
+  XBT_DEBUG("Network model: %p", net_model);
   simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
   simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
 
@@ -60,7 +65,7 @@ int main(int argc, char** argv)
   XBT_INFO("actionC state: %s", string_action(stateActionC));
 
   /* Let's do something on it */
-  surf_network_model->communicate(hostA, hostB, 150.0, -1.0);
+  net_model->communicate(hostA, hostB, 150.0, -1.0);
 
   surf_solve(-1.0);
   do {
@@ -83,7 +88,7 @@ int main(int argc, char** argv)
       action.unref();
     }
 
-    action_list = surf_network_model->get_failed_action_set();
+    action_list = net_model->get_failed_action_set();
     while (not action_list->empty()) {
       simgrid::kernel::resource::Action& action = action_list->front();
       XBT_INFO("   Network Failed action");
@@ -91,16 +96,15 @@ int main(int argc, char** argv)
       action.unref();
     }
 
-    action_list = surf_network_model->get_finished_action_set();
+    action_list = net_model->get_finished_action_set();
     while (not action_list->empty()) {
       simgrid::kernel::resource::Action& action = action_list->front();
       XBT_INFO("   Network Done action");
       XBT_DEBUG("\t * Done : %p", &action);
       action.unref();
     }
-  } while (
-      (surf_network_model->get_started_action_set()->size() || surf_cpu_model_pm->get_started_action_set()->size()) &&
-      surf_solve(-1.0) >= 0.0);
+  } while ((net_model->get_started_action_set()->size() || surf_cpu_model_pm->get_started_action_set()->size()) &&
+           surf_solve(-1.0) >= 0.0);
 
   XBT_DEBUG("Simulation Terminated");
 
index 8f3e1a0..4984d79 100644 (file)
@@ -6,6 +6,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/host.h"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp" // full type for NetZoneImpl object
+#include "simgrid/zone.h"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
 #include "src/surf/surf_interface.hpp"
@@ -35,7 +37,9 @@ int main(int argc, char** argv)
   hostB->pimpl_cpu->execution_start(1000.0);
   hostB->pimpl_cpu->sleep(7.32);
 
-  surf_network_model->communicate(hostA, hostB, 150.0, -1.0);
+  sg_netzone_t as_zone                               = sg_zone_get_by_name("AS0");
+  simgrid::kernel::resource::NetworkModel* 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 */
   do {