Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'multi_models_no_globals' into 'master'
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 9 Mar 2021 15:02:50 +0000 (15:02 +0000)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 9 Mar 2021 15:02:50 +0000 (15:02 +0000)
Refactoring: remove surf_*_model globals

See merge request simgrid/simgrid!49

43 files changed:
doc/doxygen/inside_extending.doc
include/simgrid/kernel/resource/Model.hpp
include/simgrid/kernel/routing/NetZoneImpl.hpp
src/include/surf/surf.hpp
src/kernel/EngineImpl.cpp
src/kernel/EngineImpl.hpp
src/kernel/activity/CommImpl.cpp
src/kernel/activity/ExecImpl.cpp
src/kernel/resource/DiskImpl.cpp
src/kernel/resource/DiskImpl.hpp
src/kernel/routing/DijkstraZone.cpp
src/kernel/routing/FloydZone.cpp
src/kernel/routing/FullZone.cpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/VivaldiZone.cpp
src/plugins/vm/VirtualMachineImpl.cpp
src/plugins/vm/VirtualMachineImpl.hpp
src/plugins/vm/s4u_VirtualMachine.cpp
src/s4u/s4u_Host.cpp
src/simdag/sd_global.cpp
src/simdag/sd_task.cpp
src/simix/smx_global.cpp
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp
src/surf/cpu_cas01.cpp
src/surf/cpu_interface.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_interface.cpp
src/surf/network_interface.hpp
src/surf/network_ns3.cpp
src/surf/network_smpi.cpp
src/surf/ptask_L07.cpp
src/surf/ptask_L07.hpp
src/surf/sg_platf.cpp
src/surf/surf_c_bindings.cpp
src/surf/surf_interface.cpp
teshsuite/surf/surf_usage/surf_usage.cpp
teshsuite/surf/surf_usage2/surf_usage2.cpp

index 54f7dcc..fefe0a2 100644 (file)
@@ -256,4 +256,4 @@ catch (std::runtime_error& e) {
 You should not do something like that. Please work instead to make XML
 avoidable, ie to make the C++ interface nice and usable.
 
-*/
\ No newline at end of file
+*/
index 39a7cc6..72617af 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <memory>
 #include <simgrid/kernel/resource/Action.hpp>
+#include <unordered_map>
 
 namespace simgrid {
 namespace kernel {
@@ -19,6 +20,16 @@ namespace resource {
  */
 class XBT_PUBLIC Model {
 public:
+  /** @brief Possible model types */
+  enum class Type {
+    HOST,    /**< Host models: see surf_host_model_description for more details */
+    NETWORK, /**< Network models: see surf_network_model_description for more details */
+    CPU_PM,  /**< CPU model for physical machines: see surf_cpu_model_description for more details */
+    CPU_VM,  /**< CPU model for virtual machines: see surf_cpu_model_description for more details */
+    DISK,    /**< Disk models: see surf_disk_model_description for more details */
+    VM       /**< VM model */
+  };
+
   /** @brief Possible update mechanisms */
   enum class UpdateAlgo {
     FULL, /**< Full update mechanism: the remaining time of every action is recomputed at each step */
@@ -140,9 +151,4 @@ private:
 } // namespace kernel
 } // namespace simgrid
 
-/** @ingroup SURF_models
- *  @brief List of initialized models
- */
-XBT_PUBLIC_DATA std::vector<simgrid::kernel::resource::Model*> all_existing_models;
-
 #endif
index fcb69c9..b550fc4 100644 (file)
@@ -70,6 +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_;
 
 protected:
   explicit NetZoneImpl(NetZoneImpl* father, const std::string& name, resource::NetworkModel* network_model);
@@ -101,7 +106,16 @@ public:
   /* FIXME: protect the following fields once the construction madness is sorted out */
   RoutingMode hierarchy_ = RoutingMode::unset;
 
-  resource::NetworkModel* network_model_;
+  /** @brief Retrieves the network model associated to this NetZone */
+  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_; }
+  /** @brief Retrieves the CPU model for physical machines associated to this NetZone */
+  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_; }
+  /** @brief Retrieves the host model associated to this NetZone */
+  simgrid::surf::HostModel* get_host_model() const { return host_model_; }
 
   const s4u::NetZone* get_iface() const { return &piface_; }
   s4u::NetZone* get_iface() { return &piface_; }
@@ -121,6 +135,8 @@ public:
 
   /** @brief Make a host within that NetZone */
   s4u::Host* create_host(const std::string& name, const std::vector<double>& speed_per_pstate, int core_amount);
+  /** @brief Create a disk with the disk model from this NetZone */
+  s4u::Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth);
   /** @brief Make a link within that NetZone */
   virtual s4u::Link* create_link(const std::string& name, const std::vector<double>& bandwidths,
                                  s4u::Link::SharingPolicy policy);
index 772465a..d5d1645 100644 (file)
@@ -8,25 +8,6 @@
 
 #include "simgrid/forward.h"
 
-/** @ingroup SURF_models
- *  @brief The CPU model object for the physical machine layer
- */
-XBT_PUBLIC_DATA simgrid::kernel::resource::CpuModel* surf_cpu_model_pm;
-
-/** @ingroup SURF_models
- *  @brief The CPU model object for the virtual machine layer
- */
-XBT_PUBLIC_DATA simgrid::kernel::resource::CpuModel* surf_cpu_model_vm;
-
-/** @ingroup SURF_models
- *  @brief The host model
- *
- *  Note that when you create an API on top of SURF, the host model should be the only one you use
- *  because depending on the platform model, the network model and the CPU model may not exist.
- */
-XBT_PUBLIC_DATA simgrid::surf::HostModel* surf_host_model;
-
-
 /*** SURF Globals **************************/
 
 /** @ingroup SURF_simulation
index 1956f49..e45b5e0 100644 (file)
@@ -53,5 +53,29 @@ void EngineImpl::register_default(const actor::ActorCodeFactory& code)
   default_function = code;
 }
 
+void EngineImpl::add_model_ptask(simgrid::kernel::resource::Model::Type type, simgrid::kernel::resource::Model* model,
+                                 bool is_default)
+{
+  if (is_default)
+    models_by_type_[type].insert(models_by_type_[type].begin(), model);
+  else
+    models_by_type_[type].push_back(model);
+}
+
+void EngineImpl::add_model(simgrid::kernel::resource::Model::Type type,
+                           std::unique_ptr<simgrid::kernel::resource::Model> model, bool is_default)
+{
+  add_model_ptask(type, model.get(), is_default);
+  models_.push_back(std::move(model));
+}
+
+simgrid::kernel::resource::Model* EngineImpl::get_default_model(simgrid::kernel::resource::Model::Type type)
+{
+  if (models_by_type_[type].size() > 0)
+    return models_by_type_[type][0];
+  else
+    return nullptr;
+}
+
 } // namespace kernel
 } // namespace simgrid
index 6a3ee06..4599d92 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef SIMGRID_KERNEL_ENGINEIMPL_HPP
 #define SIMGRID_KERNEL_ENGINEIMPL_HPP
 
+#include <simgrid/kernel/resource/Model.hpp>
 #include <simgrid/s4u/Engine.hpp>
 #include <simgrid/s4u/NetZone.hpp>
 #include <simgrid/simix.hpp>
@@ -23,6 +24,9 @@ class EngineImpl {
   std::unordered_map<std::string, routing::NetPoint*> netpoints_;
   std::unordered_map<std::string, actor::ActorCodeFactory> registered_functions; // Maps function names to actor code
   actor::ActorCodeFactory default_function; // Function to use as a fallback when the provided name matches nothing
+  std::vector<std::unique_ptr<simgrid::kernel::resource::Model>> models_;
+  std::unordered_map<simgrid::kernel::resource::Model::Type, std::vector<simgrid::kernel::resource::Model*>>
+      models_by_type_;
 
   friend s4u::Engine;
 
@@ -37,6 +41,37 @@ public:
   void register_function(const std::string& name, const actor::ActorCodeFactory& code);
   void register_default(const actor::ActorCodeFactory& code);
 
+  /**
+   * @brief Add a model to engine list
+   *
+   * @param type Model type (network, disk, etc)
+   * @param model Pointer to model
+   * @param is_default Is this the default model for this type of resource in this exp
+   */
+  void add_model(simgrid::kernel::resource::Model::Type type, std::unique_ptr<simgrid::kernel::resource::Model> model,
+                 bool is_default = false);
+  /**
+   * @brief Add a model (specific for ptask)
+   *
+   * Ptask is special. The CPU and NETWORK models need to be in the managed
+   * resources by surf_solve (model_by_type) but cannot be in the list of
+   * all models (old all_existing_models global variable)
+   *
+   * This methods does this job while we cannot handle ptask as the remaining models
+   */
+  void add_model_ptask(simgrid::kernel::resource::Model::Type type, simgrid::kernel::resource::Model* model,
+                       bool is_default);
+  /** @brief Get current default model for a resource type */
+  simgrid::kernel::resource::Model* get_default_model(simgrid::kernel::resource::Model::Type type);
+
+  /** @brief Get list of models created for a resource type */
+  const std::vector<simgrid::kernel::resource::Model*>& get_model_list(simgrid::kernel::resource::Model::Type type)
+  {
+    return models_by_type_[type];
+  }
+  /** @brief Get list of all models managed by this engine */
+  const std::vector<std::unique_ptr<simgrid::kernel::resource::Model>>& get_all_models() { return models_; }
+
   routing::NetZoneImpl* netzone_root_ = nullptr;
   static EngineImpl* get_instance() { return simgrid::s4u::Engine::get_instance()->pimpl; }
   actor::ActorCodeFactory get_function(const std::string& name)
index 0191ebf..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"
@@ -80,8 +81,8 @@ XBT_PRIVATE simgrid::kernel::activity::ActivityImplPtr simcall_HANDLER_comm_isen
   }
 
   /* Setup the communication synchro */
-  other_comm->src_actor_     = src_proc;
-  other_comm->src_data_      = data;
+  other_comm->src_actor_ = src_proc;
+  other_comm->src_data_  = data;
   (*other_comm).set_src_buff(src_buff, src_buff_size).set_size(task_size).set_rate(rate);
 
   other_comm->match_fun     = match_fun;
@@ -162,8 +163,8 @@ simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, smx_actor_t receiver, smx_
   }
 
   /* Setup communication synchro */
-  other_comm->dst_actor_     = receiver;
-  other_comm->dst_data_      = data;
+  other_comm->dst_actor_ = receiver;
+  other_comm->dst_data_  = data;
   other_comm->set_dst_buff(dst_buff, dst_buff_size);
 
   if (rate > -1.0 && (other_comm->get_rate() < 0.0 || rate < other_comm->get_rate()))
@@ -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 d7e4ad8..40b9f95 100644 (file)
@@ -3,10 +3,11 @@
 /* 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. */
 
-#include "simgrid/s4u/Exec.hpp"
 #include "src/kernel/activity/ExecImpl.hpp"
 #include "simgrid/Exception.hpp"
+#include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/modelchecker.h"
+#include "simgrid/s4u/Exec.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
@@ -58,7 +59,7 @@ namespace activity {
 
 ExecImpl::ExecImpl()
 {
-  piface_ = new s4u::Exec(this);
+  piface_                = new s4u::Exec(this);
   actor::ActorImpl* self = actor::ActorImpl::self();
   if (self) {
     actor_ = self;
@@ -120,7 +121,9 @@ ExecImpl* ExecImpl::start()
         surf_action_->set_user_bound(bound_);
       }
     } else {
-      surf_action_ = surf_host_model->execute_parallel(hosts_, flops_amounts_.data(), bytes_amounts_.data(), -1);
+      // FIXME[donassolo]: verify if all hosts belongs to the same netZone?
+      auto host_model = hosts_.front()->get_netpoint()->get_englobing_zone()->get_host_model();
+      surf_action_    = host_model->execute_parallel(hosts_, flops_amounts_.data(), bytes_amounts_.data(), -1);
     }
     surf_action_->set_activity(this);
   }
@@ -196,7 +199,7 @@ void ExecImpl::finish()
      * simcall */
 
     if (simcall->call_ == simix::Simcall::NONE) // FIXME: maybe a better way to handle this case
-      continue;                        // if process handling comm is killed
+      continue;                                 // if process handling comm is killed
     if (simcall->call_ == simix::Simcall::EXECUTION_WAITANY_FOR) {
       simgrid::kernel::activity::ExecImpl** execs = simcall_execution_waitany_for__get__execs(simcall);
       size_t count                                = simcall_execution_waitany_for__get__count(simcall);
index d8eeae5..3388bdf 100644 (file)
@@ -11,8 +11,6 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_disk, ker_resource, "Disk resources, fuelling I/O activities");
 
-simgrid::kernel::resource::DiskModel* surf_disk_model = nullptr;
-
 namespace simgrid {
 namespace kernel {
 namespace resource {
@@ -28,7 +26,6 @@ DiskModel::DiskModel() : Model(Model::UpdateAlgo::FULL)
 
 DiskModel::~DiskModel()
 {
-  surf_disk_model = nullptr;
 }
 
 /************
@@ -54,13 +51,13 @@ DiskImpl* DiskImpl::set_write_bandwidth(double write_bw)
 
 DiskImpl* DiskImpl::set_read_constraint(lmm::Constraint* constraint_read)
 {
-  constraint_read_  = constraint_read;
+  constraint_read_ = constraint_read;
   return this;
 }
 
 DiskImpl* DiskImpl::set_write_constraint(lmm::Constraint* constraint_write)
 {
-  constraint_write_  = constraint_write;
+  constraint_write_ = constraint_write;
   return this;
 }
 
@@ -101,6 +98,7 @@ void DiskImpl::turn_off()
 
 void DiskImpl::seal()
 {
+  xbt_assert(this->get_model(), "Cannot seal Disk (%s) without setting the model first", this->get_cname());
   lmm::System* maxmin_system = get_model()->get_maxmin_system();
   this->set_read_constraint(maxmin_system->constraint_new(this, read_bw_))
       ->set_write_constraint(maxmin_system->constraint_new(this, write_bw_))
index 8418916..c7bdd53 100644 (file)
@@ -20,8 +20,6 @@
  * Model *
  *********/
 
-XBT_PUBLIC_DATA simgrid::kernel::resource::DiskModel* surf_disk_model;
-
 namespace simgrid {
 namespace kernel {
 namespace resource {
index 3c3378d..7855c4f 100644 (file)
@@ -44,7 +44,7 @@ void DijkstraZone::seal()
   xbt_node_t node = nullptr;
 
   /* Add the loopback if needed */
-  if (network_model_->loopback_ && hierarchy_ == RoutingMode::base) {
+  if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) {
     xbt_dynar_foreach (xbt_graph_get_nodes(route_graph_.get()), cursor, node) {
       bool found = false;
       xbt_edge_t edge = nullptr;
@@ -58,7 +58,7 @@ void DijkstraZone::seal()
 
       if (not found) {
         auto* route = new simgrid::kernel::routing::RouteCreationArgs();
-        route->link_list.push_back(network_model_->loopback_);
+        route->link_list.push_back(get_network_model()->loopback_);
         xbt_graph_new_edge(route_graph_.get(), node, node, route);
       }
     }
index 7b2c688..e374648 100644 (file)
@@ -146,12 +146,12 @@ void FloydZone::seal()
   init_tables(table_size);
 
   /* Add the loopback if needed */
-  if (network_model_->loopback_ && hierarchy_ == RoutingMode::base) {
+  if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) {
     for (unsigned int i = 0; i < table_size; i++) {
       RouteCreationArgs* route = TO_FLOYD_LINK(i, i);
       if (not route) {
         route = new RouteCreationArgs();
-        route->link_list.push_back(network_model_->loopback_);
+        route->link_list.push_back(get_network_model()->loopback_);
         TO_FLOYD_LINK(i, i) = route;
         TO_FLOYD_PRED(i, i) = i;
         TO_FLOYD_COST(i, i) = 1;
index e912ea0..b7c0f33 100644 (file)
@@ -30,12 +30,12 @@ void FullZone::seal()
     routing_table_.resize(table_size * table_size, nullptr);
 
   /* Add the loopback if needed */
-  if (network_model_->loopback_ && hierarchy_ == RoutingMode::base) {
+  if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) {
     for (unsigned int i = 0; i < table_size; i++) {
       RouteCreationArgs* route = TO_ROUTE_FULL(i, i);
       if (not route) {
         route = new RouteCreationArgs();
-        route->link_list.push_back(network_model_->loopback_);
+        route->link_list.push_back(get_network_model()->loopback_);
         TO_ROUTE_FULL(i, i) = route;
       }
     }
index 9c6f3c0..6ae49f1 100644 (file)
@@ -7,6 +7,9 @@
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
+#include "src/kernel/EngineImpl.hpp"
+#include "src/kernel/resource/DiskImpl.hpp"
+#include "src/surf/HostImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
 #include "src/surf/xml/platf_private.hpp"
@@ -24,7 +27,15 @@ NetZoneImpl::NetZoneImpl(NetZoneImpl* father, const std::string& name, resource:
   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, father_);
+  netpoint_     = new NetPoint(name_, NetPoint::Type::NetZone, father_);
+  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());
 }
 
@@ -65,10 +76,17 @@ int NetZoneImpl::get_host_count() const
   return count;
 }
 
+s4u::Disk* NetZoneImpl::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
+{
+  auto* l = disk_model_->create_disk(name, read_bandwidth, write_bandwidth);
+
+  return l->get_iface();
+}
+
 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();
 }
@@ -82,7 +100,7 @@ s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<d
   auto* res = new s4u::Host(name);
   res->set_netpoint(new NetPoint(name, NetPoint::Type::Host, this));
 
-  surf_cpu_model_pm->create_cpu(res, speed_per_pstate)->set_core_count(core_amount)->seal();
+  cpu_model_pm_->create_cpu(res, speed_per_pstate)->set_core_count(core_amount)->seal();
 
   return res;
 }
@@ -296,14 +314,14 @@ bool NetZoneImpl::get_bypass_route(NetPoint* src, NetPoint* dst,
   for (int max = 0; max <= max_index && not bypassedRoute; max++) {
     for (int i = 0; i < max && not bypassedRoute; i++) {
       if (i <= max_index_src && max <= max_index_dst) {
-        key = {path_src.at(i)->netpoint_, path_dst.at(max)->netpoint_};
+        key      = {path_src.at(i)->netpoint_, path_dst.at(max)->netpoint_};
         auto bpr = bypass_routes_.find(key);
         if (bpr != bypass_routes_.end()) {
           bypassedRoute = bpr->second;
         }
       }
       if (not bypassedRoute && max <= max_index_src && i <= max_index_dst) {
-        key = {path_src.at(max)->netpoint_, path_dst.at(i)->netpoint_};
+        key      = {path_src.at(max)->netpoint_, path_dst.at(i)->netpoint_};
         auto bpr = bypass_routes_.find(key);
         if (bpr != bypass_routes_.end()) {
           bypassedRoute = bpr->second;
@@ -312,7 +330,7 @@ bool NetZoneImpl::get_bypass_route(NetPoint* src, NetPoint* dst,
     }
 
     if (not bypassedRoute && max <= max_index_src && max <= max_index_dst) {
-      key = {path_src.at(max)->netpoint_, path_dst.at(max)->netpoint_};
+      key      = {path_src.at(max)->netpoint_, path_dst.at(max)->netpoint_};
       auto bpr = bypass_routes_.find(key);
       if (bpr != bypass_routes_.end()) {
         bypassedRoute = bpr->second;
@@ -348,9 +366,9 @@ void NetZoneImpl::get_global_route(NetPoint* src, NetPoint* dst,
   XBT_DEBUG("Resolve route from '%s' to '%s'", src->get_cname(), dst->get_cname());
 
   /* Find how src and dst are interconnected */
-  NetZoneImpl *common_ancestor;
-  NetZoneImpl *src_ancestor;
-  NetZoneImpl *dst_ancestor;
+  NetZoneImplcommon_ancestor;
+  NetZoneImplsrc_ancestor;
+  NetZoneImpldst_ancestor;
   find_common_ancestors(src, dst, &common_ancestor, &src_ancestor, &dst_ancestor);
   XBT_DEBUG("elements_father: common ancestor '%s' src ancestor '%s' dst ancestor '%s'", common_ancestor->get_cname(),
             src_ancestor->get_cname(), dst_ancestor->get_cname());
index 4b392c5..05c2463 100644 (file)
@@ -76,10 +76,10 @@ void VivaldiZone::set_peer_link(NetPoint* netpoint, double bw_in, double bw_out,
   std::string link_up      = "link_" + netpoint->get_name() + "_UP";
   std::string link_down    = "link_" + netpoint->get_name() + "_DOWN";
   resource::LinkImpl* linkUp =
-      network_model_->create_link(link_up, std::vector<double>(1, bw_out), s4u::Link::SharingPolicy::SHARED);
+      get_network_model()->create_link(link_up, std::vector<double>(1, bw_out), s4u::Link::SharingPolicy::SHARED);
   linkUp->seal();
   resource::LinkImpl* linkDown =
-      network_model_->create_link(link_down, std::vector<double>(1, bw_in), s4u::Link::SharingPolicy::SHARED);
+      get_network_model()->create_link(link_down, std::vector<double>(1, bw_in), s4u::Link::SharingPolicy::SHARED);
   linkDown->seal();
   private_links_.insert({netpoint->id(), {linkUp, linkDown}});
 }
index eefe1e5..371bff4 100644 (file)
@@ -7,16 +7,16 @@
 #include "simgrid/Exception.hpp"
 #include "simgrid/s4u/Exec.hpp"
 #include "src/include/surf/surf.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/activity/ExecImpl.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_vm, ker_resource, "Virtual Machines, containing actors and mobile accross hosts");
 
-simgrid::vm::VMModel* surf_vm_model = nullptr;
-
 void surf_vm_model_init_HL13()
 {
-  if (surf_cpu_model_vm != nullptr)
-    surf_vm_model = new simgrid::vm::VMModel();
+  auto vm_model = std::make_unique<simgrid::vm::VMModel>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::VM,
+                                                         std::move(vm_model), true);
 }
 
 namespace simgrid {
@@ -85,7 +85,7 @@ static void add_active_activity(kernel::activity::ActivityImpl const& act)
 {
   const s4u::VirtualMachine* vm = get_vm_from_activity(act);
   if (vm != nullptr) {
-    VirtualMachineImpl *vm_impl = vm->get_impl();
+    VirtualMachineImplvm_impl = vm->get_impl();
     vm_impl->add_active_exec();
     vm_impl->update_action_weight();
   }
@@ -95,7 +95,7 @@ static void remove_active_activity(kernel::activity::ActivityImpl const& act)
 {
   const s4u::VirtualMachine* vm = get_vm_from_activity(act);
   if (vm != nullptr) {
-    VirtualMachineImpl *vm_impl = vm->get_impl();
+    VirtualMachineImplvm_impl = vm->get_impl();
     vm_impl->remove_active_exec();
     vm_impl->update_action_weight();
   }
@@ -103,7 +103,6 @@ static void remove_active_activity(kernel::activity::ActivityImpl const& act)
 
 VMModel::VMModel()
 {
-  all_existing_models.push_back(this);
   s4u::Host::on_state_change.connect(host_state_change);
   s4u::Exec::on_start.connect(add_active_exec);
   s4u::Exec::on_completion.connect(remove_active_exec);
@@ -148,13 +147,12 @@ double VMModel::next_occurring_event(double now)
     double solved_value = ws_vm->get_impl()->get_action()->get_variable()->get_value();
     XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->get_cname(), ws_vm->get_pm()->get_cname());
 
-    xbt_assert(cpu->get_model() == surf_cpu_model_vm);
     kernel::lmm::System* vcpu_system = cpu->get_model()->get_maxmin_system();
     vcpu_system->update_constraint_bound(cpu->get_constraint(), virt_overhead * solved_value);
   }
 
-  /* 2. Ready. Get the next occurring event */
-  return surf_cpu_model_vm->next_occurring_event(now);
+  /* actual next occurring event is determined by VM CPU model at surf_solve */
+  return -1.0;
 }
 
 /************
@@ -324,7 +322,8 @@ void VirtualMachineImpl::set_bound(double bound)
   update_action_weight();
 }
 
-void VirtualMachineImpl::update_action_weight(){
+void VirtualMachineImpl::update_action_weight()
+{
   /* The impact of the VM over its PM is the min between its vCPU amount and the amount of tasks it contains */
   int impact = std::min(active_execs_, get_core_amount());
 
@@ -338,5 +337,5 @@ void VirtualMachineImpl::update_action_weight(){
   action_->set_bound(std::min(impact * physical_host_->get_speed(), user_bound_));
 }
 
-}
-}
+} // namespace vm
+} // namespace simgrid
index a6c8206..899922b 100644 (file)
@@ -103,6 +103,4 @@ public:
 }
 }
 
-XBT_PUBLIC_DATA simgrid::vm::VMModel* surf_vm_model;
-
 #endif /* VM_INTERFACE_HPP_ */
index c8046e0..3b412c8 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/Exception.hpp"
+#include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/s4u/Actor.hpp"
 #include "simgrid/vm.h"
 #include "src/include/surf/surf.hpp"
@@ -41,7 +42,7 @@ VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host
   for (int i = 0; i < physical_host->get_pstate_count(); i++)
     speeds.push_back(physical_host->get_pstate_speed(i));
 
-  surf_cpu_model_vm->create_cpu(this, speeds)->set_core_count(core_amount)->seal();
+  physical_host->get_netpoint()->get_englobing_zone()->get_cpu_vm_model()->create_cpu(this, speeds)->set_core_count(core_amount)->seal();
   if (physical_host->get_pstate() != 0)
     set_pstate(physical_host->get_pstate());
 
index 1036f39..b9e8c8b 100644 (file)
@@ -275,7 +275,9 @@ std::vector<Disk*> Host::get_disks() const
 
 Disk* Host::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
 {
-  return surf_disk_model->create_disk(name, read_bandwidth, write_bandwidth)->set_host(this)->get_iface();
+  auto disk =
+      this->get_netpoint()->get_englobing_zone()->get_disk_model()->create_disk(name, read_bandwidth, write_bandwidth);
+  return disk->set_host(this)->get_iface();
 }
 
 void Host::add_disk(const Disk* disk)
@@ -319,7 +321,8 @@ size_t sg_host_count()
 sg_host_t* sg_host_list()
 {
   const simgrid::s4u::Engine* e = simgrid::s4u::Engine::get_instance();
-  size_t host_count       = e->get_host_count();
+  size_t host_count             = e->get_host_count();
+
   xbt_assert(host_count > 0, "There is no host!");
   std::vector<simgrid::s4u::Host*> hosts = e->get_all_hosts();
 
@@ -512,8 +515,9 @@ int sg_host_is_on(const_sg_host_t host)
 /** @brief Get the properties of a host */
 xbt_dict_t sg_host_get_properties(const_sg_host_t host)
 {
-  xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
   const std::unordered_map<std::string, std::string>* props = host->get_properties();
+  xbt_dict_t as_dict                                        = xbt_dict_new_homogeneous(xbt_free_f);
+
   if (props == nullptr)
     return nullptr;
   for (auto const& elm : *props) {
index 5a9e822..0670d25 100644 (file)
@@ -8,6 +8,7 @@
 #include "simgrid/kernel/resource/Model.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/surf/surf_interface.hpp"
 
 #include <array>
 XBT_LOG_NEW_CATEGORY(sd, "Logging specific to SimDag");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_kernel, sd, "Logging specific to SimDag (kernel)");
 
-simgrid::sd::Global *sd_global = nullptr;
+simgrid::sd::Globalsd_global = nullptr;
 
-namespace simgrid{
-namespace sd{
+namespace simgrid {
+namespace sd {
 
-std::set<SD_task_t>* simulate(double how_long){
+std::set<SD_task_t>* simulate(double how_long)
+{
   XBT_VERB("Run simulation for %f seconds", how_long);
 
   sd_global->watch_point_reached = false;
@@ -31,19 +33,19 @@ std::set<SD_task_t>* simulate(double how_long){
     SD_task_run(*(sd_global->runnable_tasks.begin()));
 
   double elapsed_time = 0.0;
-  double total_time = 0.0;
+  double total_time   = 0.0;
   /* main loop */
   while (elapsed_time >= 0 && (how_long < 0 || 0.00001 < (how_long - total_time)) &&
          not sd_global->watch_point_reached) {
     XBT_DEBUG("Total time: %f", total_time);
 
-    elapsed_time = surf_solve(how_long > 0 ? surf_get_clock() + how_long - total_time: -1.0);
+    elapsed_time = surf_solve(how_long > 0 ? surf_get_clock() + how_long - total_time : -1.0);
     XBT_DEBUG("surf_solve() returns %f", elapsed_time);
     if (elapsed_time > 0.0)
       total_time += elapsed_time;
 
     /* let's see which tasks are done */
-    for (auto const& model : all_existing_models) {
+    for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) {
       const simgrid::kernel::resource::Action* action = model->extract_done_action();
       while (action != nullptr && action->get_data() != nullptr) {
         auto* task = static_cast<SD_task_t>(action->get_data());
@@ -58,7 +60,7 @@ std::set<SD_task_t>* simulate(double how_long){
           succ->predecessors->erase(task);
           succ->inputs->erase(task);
           XBT_DEBUG("Release dependency on %s: %zu remain(s). Becomes schedulable if %zu=0", SD_task_get_name(succ),
-              succ->predecessors->size()+succ->inputs->size(), succ->predecessors->size());
+                    succ->predecessors->size() + succ->inputs->size(), succ->predecessors->size());
 
           if (SD_task_get_state(succ) == SD_NOT_SCHEDULED && succ->predecessors->empty())
             SD_task_set_state(succ, SD_SCHEDULABLE);
@@ -75,14 +77,14 @@ std::set<SD_task_t>* simulate(double how_long){
           output->start_time = task->finish_time;
           output->predecessors->erase(task);
           if (SD_task_get_state(output) == SD_SCHEDULED)
-             SD_task_set_state(output, SD_RUNNABLE);
+            SD_task_set_state(output, SD_RUNNABLE);
           else
-             SD_task_set_state(output, SD_SCHEDULABLE);
+            SD_task_set_state(output, SD_SCHEDULABLE);
 
           SD_task_t comm_dst = *(output->successors->begin());
-          if (SD_task_get_state(comm_dst) == SD_NOT_SCHEDULED && comm_dst->predecessors->empty()){
-            XBT_DEBUG("%s is a transfer, %s may be ready now if %zu=0",
-                SD_task_get_name(output), SD_task_get_name(comm_dst), comm_dst->predecessors->size());
+          if (SD_task_get_state(comm_dst) == SD_NOT_SCHEDULED && comm_dst->predecessors->empty()) {
+            XBT_DEBUG("%s is a transfer, %s may be ready now if %zu=0", SD_task_get_name(output),
+                      SD_task_get_name(comm_dst), comm_dst->predecessors->size());
             SD_task_set_state(comm_dst, SD_SCHEDULABLE);
           }
           if (SD_task_get_state(output) == SD_RUNNABLE && not sd_global->watch_point_reached)
@@ -110,21 +112,22 @@ std::set<SD_task_t>* simulate(double how_long){
       XBT_WARN("%s is in %s state", SD_task_get_name(t), __get_state_name(SD_task_get_state(t)));
   }
 
-  XBT_DEBUG("elapsed_time = %f, total_time = %f, watch_point_reached = %d",
-             elapsed_time, total_time, sd_global->watch_point_reached);
+  XBT_DEBUG("elapsed_time = %f, total_time = %f, watch_point_reached = %d", elapsed_time, total_time,
+            sd_global->watch_point_reached);
   XBT_DEBUG("current time = %f", surf_get_clock());
 
   return &sd_global->return_set;
 }
-}
-}
+} // namespace sd
+} // namespace simgrid
 
 /**
  * @brief helper for pretty printing of task state
  * @param state the state of a task
  * @return the equivalent as a readable string
  */
-const char *__get_state_name(e_SD_task_state_t state){
+const char* __get_state_name(e_SD_task_state_t state)
+{
   static constexpr std::array<const char*, 7> state_names{
       {"not scheduled", "schedulable", "scheduled", "runnable", "running", "done", "failed"}};
   return state_names.at(static_cast<int>(log2(static_cast<double>(state))));
@@ -139,7 +142,7 @@ const char *__get_state_name(e_SD_task_state_t state){
  * @param argv argument list
  * @see SD_create_environment(), SD_exit()
  */
-void SD_init_nocheck(int *argc, char **argv)
+void SD_init_nocheck(int* argc, char** argv)
 {
   xbt_assert(sd_global == nullptr, "SD_init() already called");
 
@@ -159,8 +162,9 @@ void SD_init_nocheck(int *argc, char **argv)
  *
  * Example: SD_config("host/model","default")
  */
-void SD_config(const char *key, const char *value){
-  xbt_assert(sd_global,"ERROR: Please call SD_init() before using SD_config()");
+void SD_config(const char* key, const char* value)
+{
+  xbt_assert(sd_global, "ERROR: Please call SD_init() before using SD_config()");
   simgrid::config::set_as_string(key, value);
 }
 
@@ -181,7 +185,7 @@ void SD_config(const char *key, const char *value){
  *
  *     @include small_platform.xml
  */
-void SD_create_environment(const char *platform_file)
+void SD_create_environment(const charplatform_file)
 {
   simgrid::s4u::Engine::get_instance()->load_platform(platform_file);
 
@@ -190,7 +194,7 @@ void SD_create_environment(const char *platform_file)
   jedule_sd_init();
 #endif
   XBT_VERB("Starting simulation...");
-  surf_presolve();            /* Takes traces into account */
+  surf_presolve(); /* Takes traces into account */
 }
 
 /**
@@ -220,7 +224,8 @@ void SD_simulate_with_update(double how_long, xbt_dynar_t changed_tasks_dynar)
 }
 
 /** @brief Returns the current clock, in seconds */
-double SD_get_clock() {
+double SD_get_clock()
+{
   return surf_get_clock();
 }
 
index 4680e5e..1c78fa2 100644 (file)
@@ -5,6 +5,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simdag_private.hpp"
+#include "simgrid/kernel/routing/NetPoint.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/surf_interface.hpp"
 #include <algorithm>
@@ -33,36 +34,36 @@ static void __SD_task_destroy_scheduling_data(SD_task_t task)
  * @return the new task
  * @see SD_task_destroy()
  */
-SD_task_t SD_task_create(const char *name, void *data, double amount)
+SD_task_t SD_task_create(const char* name, void* data, double amount)
 {
   SD_task_t task = xbt_new0(s_SD_task_t, 1);
-  task->kind = SD_TASK_NOT_TYPED;
-  task->state= SD_NOT_SCHEDULED;
+  task->kind     = SD_TASK_NOT_TYPED;
+  task->state    = SD_NOT_SCHEDULED;
   sd_global->initial_tasks.insert(task);
 
   task->marked       = false;
-  task->start_time = -1.0;
-  task->finish_time = -1.0;
-  task->surf_action = nullptr;
+  task->start_time   = -1.0;
+  task->finish_time  = -1.0;
+  task->surf_action  = nullptr;
   task->watch_points = 0;
 
-  task->inputs = new std::set<SD_task_t>();
-  task->outputs = new std::set<SD_task_t>();
+  task->inputs       = new std::set<SD_task_t>();
+  task->outputs      = new std::set<SD_task_t>();
   task->predecessors = new std::set<SD_task_t>();
-  task->successors = new std::set<SD_task_t>();
+  task->successors   = new std::set<SD_task_t>();
 
-  task->data = data;
-  task->name = xbt_strdup(name);
-  task->amount = amount;
+  task->data       = data;
+  task->name       = xbt_strdup(name);
+  task->amount     = amount;
   task->allocation = new std::vector<sg_host_t>();
-  task->rate = -1;
+  task->rate       = -1;
   return task;
 }
 
-static inline SD_task_t SD_task_create_sized(const char *name, void *data, double amount, int count)
+static inline SD_task_t SD_task_create_sized(const char* name, void* data, double amount, int count)
 {
-  SD_task_t task = SD_task_create(name, data, amount);
-  task->bytes_amount = xbt_new0(double, count * count);
+  SD_task_t task     = SD_task_create(name, data, amount);
+  task->bytes_amount = xbt_new0(double, count* count);
   task->flops_amount = xbt_new0(double, count);
   return task;
 }
@@ -76,11 +77,11 @@ static inline SD_task_t SD_task_create_sized(const char *name, void *data, doubl
  * A end-to-end communication must be scheduled on 2 hosts, and the amount specified at creation is sent from hosts[0]
  * to hosts[1].
  */
-SD_task_t SD_task_create_comm_e2e(const char *name, void *data, double amount)
+SD_task_t SD_task_create_comm_e2e(const char* name, void* data, double amount)
 {
-  SD_task_t res = SD_task_create_sized(name, data, amount, 2);
+  SD_task_t res        = SD_task_create_sized(name, data, amount, 2);
   res->bytes_amount[2] = amount;
-  res->kind = SD_TASK_COMM_E2E;
+  res->kind            = SD_TASK_COMM_E2E;
 
   return res;
 }
@@ -98,11 +99,11 @@ SD_task_t SD_task_create_comm_e2e(const char *name, void *data, double amount)
  * @param flops_amount amount of compute work to be done by the task
  * @return the new SD_TASK_COMP_SEQ typed task
  */
-SD_task_t SD_task_create_comp_seq(const char *name, void *data, double flops_amount)
+SD_task_t SD_task_create_comp_seq(const char* name, void* data, double flops_amount)
 {
-  SD_task_t res = SD_task_create_sized(name, data, flops_amount, 1);
+  SD_task_t res        = SD_task_create_sized(name, data, flops_amount, 1);
   res->flops_amount[0] = flops_amount;
-  res->kind = SD_TASK_COMP_SEQ;
+  res->kind            = SD_TASK_COMP_SEQ;
 
   return res;
 }
@@ -122,13 +123,13 @@ SD_task_t SD_task_create_comp_seq(const char *name, void *data, double flops_amo
  * @param alpha purely serial fraction of the work to be done (in [0.;1.[)
  * @return the new task
  */
-SD_task_t SD_task_create_comp_par_amdahl(const char *name, void *data, double flops_amount, double alpha)
+SD_task_t SD_task_create_comp_par_amdahl(const char* name, void* data, double flops_amount, double alpha)
 {
   xbt_assert(alpha < 1. && alpha >= 0., "Invalid parameter: alpha must be in [0.;1.[");
 
   SD_task_t res = SD_task_create(name, data, flops_amount);
-  res->alpha = alpha;
-  res->kind = SD_TASK_COMP_PAR_AMDAHL;
+  res->alpha    = alpha;
+  res->kind     = SD_TASK_COMP_PAR_AMDAHL;
 
   return res;
 }
@@ -147,10 +148,10 @@ SD_task_t SD_task_create_comp_par_amdahl(const char *name, void *data, double fl
  * @param amount amount of data to redistribute by the task
  * @return the new task
  */
-SD_task_t SD_task_create_comm_par_mxn_1d_block(const char *name, void *data, double amount)
+SD_task_t SD_task_create_comm_par_mxn_1d_block(const char* name, void* data, double amount)
 {
   SD_task_t res = SD_task_create(name, data, amount);
-  res->kind = SD_TASK_COMM_PAR_MXN_1D_BLOCK;
+  res->kind     = SD_TASK_COMM_PAR_MXN_1D_BLOCK;
 
   return res;
 }
@@ -218,7 +219,7 @@ void* SD_task_get_data(const_SD_task_t task)
  * @param data the new data you want to associate with this task
  * @see SD_task_get_data()
  */
-void SD_task_set_data(SD_task_t task, void *data)
+void SD_task_set_data(SD_task_t task, voiddata)
 {
   task->data = data;
 }
@@ -239,7 +240,7 @@ void SD_task_set_data(SD_task_t task, void *data)
 void SD_task_set_rate(SD_task_t task, double rate)
 {
   xbt_assert(task->kind == SD_TASK_COMM_E2E, "The rate can be modified for end-to-end communications only.");
-  if(task->state < SD_RUNNING) {
+  if (task->state < SD_RUNNING) {
     task->rate = rate;
   } else {
     XBT_WARN("Task %p has started. Changing rate is ineffective.", task);
@@ -265,17 +266,17 @@ void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state)
 {
   std::set<SD_task_t>::iterator idx;
   XBT_DEBUG("Set state of '%s' to %d", task->name, new_state);
-  if ((new_state == SD_NOT_SCHEDULED || new_state == SD_SCHEDULABLE) && task->state == SD_FAILED){
+  if ((new_state == SD_NOT_SCHEDULED || new_state == SD_SCHEDULABLE) && task->state == SD_FAILED) {
     sd_global->completed_tasks.erase(task);
     sd_global->initial_tasks.insert(task);
   }
 
-  if (new_state == SD_SCHEDULED && task->state == SD_RUNNABLE){
+  if (new_state == SD_SCHEDULED && task->state == SD_RUNNABLE) {
     sd_global->initial_tasks.insert(task);
     sd_global->runnable_tasks.erase(task);
   }
 
-  if (new_state == SD_RUNNABLE){
+  if (new_state == SD_RUNNABLE) {
     idx = sd_global->initial_tasks.find(task);
     if (idx != sd_global->initial_tasks.end()) {
       sd_global->runnable_tasks.insert(*idx);
@@ -286,10 +287,10 @@ void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state)
   if (new_state == SD_RUNNING)
     sd_global->runnable_tasks.erase(task);
 
-  if (new_state == SD_DONE || new_state == SD_FAILED){
+  if (new_state == SD_DONE || new_state == SD_FAILED) {
     sd_global->completed_tasks.insert(task);
     task->start_time = task->surf_action->get_start_time();
-    if (new_state == SD_DONE){
+    if (new_state == SD_DONE) {
       task->finish_time = task->surf_action->get_finish_time();
 #if SIMGRID_HAVE_JEDULE
       jedule_log_sd_event(task);
@@ -306,7 +307,7 @@ void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state)
   if (task->watch_points & new_state) {
     XBT_VERB("Watch point reached with task '%s'!", task->name);
     sd_global->watch_point_reached = true;
-    SD_task_unwatch(task, new_state);   /* remove the watch point */
+    SD_task_unwatch(task, new_state); /* remove the watch point */
   }
 }
 
@@ -322,7 +323,7 @@ const char* SD_task_get_name(const_SD_task_t task)
 }
 
 /** @brief Allows to change the name of a task */
-void SD_task_set_name(SD_task_t task, const char *name)
+void SD_task_set_name(SD_task_t task, const charname)
 {
   xbt_free(task->name);
   task->name = xbt_strdup(name);
@@ -459,28 +460,28 @@ void SD_task_dump(const_SD_task_t task)
 
   if (task->kind != 0) {
     switch (task->kind) {
-    case SD_TASK_COMM_E2E:
-      XBT_INFO("  - kind: end-to-end communication");
-      break;
-    case SD_TASK_COMP_SEQ:
-      XBT_INFO("  - kind: sequential computation");
-      break;
-    case SD_TASK_COMP_PAR_AMDAHL:
-      XBT_INFO("  - kind: parallel computation following Amdahl's law");
-      break;
-    case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
-      XBT_INFO("  - kind: MxN data redistribution assuming 1D block distribution");
-      break;
-    default:
-      XBT_INFO("  - (unknown kind %d)", task->kind);
+      case SD_TASK_COMM_E2E:
+        XBT_INFO("  - kind: end-to-end communication");
+        break;
+      case SD_TASK_COMP_SEQ:
+        XBT_INFO("  - kind: sequential computation");
+        break;
+      case SD_TASK_COMP_PAR_AMDAHL:
+        XBT_INFO("  - kind: parallel computation following Amdahl's law");
+        break;
+      case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
+        XBT_INFO("  - kind: MxN data redistribution assuming 1D block distribution");
+        break;
+      default:
+        XBT_INFO("  - (unknown kind %d)", task->kind);
     }
   }
 
   XBT_INFO("  - amount: %.0f", SD_task_get_amount(task));
   if (task->kind == SD_TASK_COMP_PAR_AMDAHL)
     XBT_INFO("  - alpha: %.2f", task->alpha);
-  XBT_INFO("  - Dependencies to satisfy: %zu", task->inputs->size()+ task->predecessors->size());
-  if ((task->inputs->size()+ task->predecessors->size()) > 0) {
+  XBT_INFO("  - Dependencies to satisfy: %zu", task->inputs->size() + task->predecessors->size());
+  if ((task->inputs->size() + task->predecessors->size()) > 0) {
     XBT_INFO("  - pre-dependencies:");
     for (auto const& it : *task->predecessors)
       XBT_INFO("    %s", it->name);
@@ -504,16 +505,16 @@ void SD_task_dotty(const_SD_task_t task, void* out)
   auto* fout = static_cast<FILE*>(out);
   fprintf(fout, "  T%p [label=\"%.20s\"", task, task->name);
   switch (task->kind) {
-  case SD_TASK_COMM_E2E:
-  case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
-    fprintf(fout, ", shape=box");
-    break;
-  case SD_TASK_COMP_SEQ:
-  case SD_TASK_COMP_PAR_AMDAHL:
-    fprintf(fout, ", shape=circle");
-    break;
-  default:
-    xbt_die("Unknown task type!");
+    case SD_TASK_COMM_E2E:
+    case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
+      fprintf(fout, ", shape=box");
+      break;
+    case SD_TASK_COMP_SEQ:
+    case SD_TASK_COMP_PAR_AMDAHL:
+      fprintf(fout, ", shape=circle");
+      break;
+    default:
+      xbt_die("Unknown task type!");
   }
   fprintf(fout, "];\n");
   for (auto const& it : *task->predecessors)
@@ -553,14 +554,14 @@ void SD_task_dependency_add(SD_task_t src, SD_task_t dst)
 
   XBT_DEBUG("SD_task_dependency_add: src = %s, dst = %s", src->name, dst->name);
 
-  if (src->kind == SD_TASK_COMM_E2E || src->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){
+  if (src->kind == SD_TASK_COMM_E2E || src->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK) {
     if (dst->kind == SD_TASK_COMP_SEQ || dst->kind == SD_TASK_COMP_PAR_AMDAHL)
-        dst->inputs->insert(src);
+      dst->inputs->insert(src);
     else
       dst->predecessors->insert(src);
     src->successors->insert(dst);
   } else {
-    if (dst->kind == SD_TASK_COMM_E2E|| dst->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK)
+    if (dst->kind == SD_TASK_COMM_E2E || dst->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK)
       src->outputs->insert(dst);
     else
       src->successors->insert(dst);
@@ -614,14 +615,14 @@ void SD_task_dependency_remove(SD_task_t src, SD_task_t dst)
         "No dependency found between task '%s' and '%s': task '%s' is not a successor of task '%s'", src->name,
         dst->name, dst->name, src->name));
 
-  if (src->kind == SD_TASK_COMM_E2E || src->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){
+  if (src->kind == SD_TASK_COMM_E2E || src->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK) {
     if (dst->kind == SD_TASK_COMP_SEQ || dst->kind == SD_TASK_COMP_PAR_AMDAHL)
       dst->inputs->erase(src);
     else
       dst->predecessors->erase(src);
     src->successors->erase(dst);
   } else {
-    if (dst->kind == SD_TASK_COMM_E2E|| dst->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK)
+    if (dst->kind == SD_TASK_COMM_E2E || dst->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK)
       src->outputs->erase(dst);
     else
       src->successors->erase(dst);
@@ -726,8 +727,8 @@ static inline void SD_task_do_schedule(SD_task_t task)
  * @param rate task execution speed rate
  * @see SD_task_unschedule()
  */
-void SD_task_schedule(SD_task_t task, int host_count, const sg_host_t * host_list,
-                      const double *flops_amount, const double *bytes_amount, double rate)
+void SD_task_schedule(SD_task_t task, int host_count, const sg_host_t* host_list, const double* flops_amount,
+                      const doublebytes_amount, double rate)
 {
   xbt_assert(host_count > 0, "host_count must be positive");
 
@@ -750,7 +751,7 @@ void SD_task_schedule(SD_task_t task, int host_count, const sg_host_t * host_lis
     task->bytes_amount = nullptr;
   }
 
-  for(int i =0; i<host_count; i++)
+  for (int i = 0; i < host_count; i++)
     task->allocation->push_back(host_list[i]);
 
   SD_task_do_schedule(task);
@@ -795,14 +796,16 @@ void SD_task_unschedule(SD_task_t task)
 /* Runs a task. */
 void SD_task_run(SD_task_t task)
 {
-  xbt_assert(task->state == SD_RUNNABLE, "Task '%s' is not runnable! Task state: %d", task->name, (int) task->state);
+  xbt_assert(task->state == SD_RUNNABLE, "Task '%s' is not runnable! Task state: %d", task->name, (int)task->state);
   xbt_assert(task->allocation != nullptr, "Task '%s': host_list is nullptr!", task->name);
 
   XBT_VERB("Executing task '%s'", task->name);
 
   /* Beware! The scheduling data are now used by the surf action directly! no copy was done */
+  // FIXME[donassolo]: verify if all hosts belongs to the same netZone?
+  auto host_model = (*task->allocation).front()->get_netpoint()->get_englobing_zone()->get_host_model();
   task->surf_action =
-      surf_host_model->execute_parallel(*task->allocation, task->flops_amount, task->bytes_amount, task->rate);
+      host_model->execute_parallel(*task->allocation, task->flops_amount, task->bytes_amount, task->rate);
 
   task->surf_action->set_data(task);
 
@@ -840,7 +843,7 @@ double SD_task_get_start_time(const_SD_task_t task)
  */
 double SD_task_get_finish_time(const_SD_task_t task)
 {
-  if (task->surf_action)        /* should never happen as actions are destroyed right after their completion */
+  if (task->surf_action) /* should never happen as actions are destroyed right after their completion */
     return task->surf_action->get_finish_time();
   else
     return task->finish_time;
@@ -848,34 +851,39 @@ double SD_task_get_finish_time(const_SD_task_t task)
 
 void SD_task_distribute_comp_amdahl(SD_task_t task, int count)
 {
-  xbt_assert(task->kind == SD_TASK_COMP_PAR_AMDAHL, "Task %s is not a SD_TASK_COMP_PAR_AMDAHL typed task."
-              "Cannot use this function.", task->name);
+  xbt_assert(task->kind == SD_TASK_COMP_PAR_AMDAHL,
+             "Task %s is not a SD_TASK_COMP_PAR_AMDAHL typed task."
+             "Cannot use this function.",
+             task->name);
   task->flops_amount = xbt_new0(double, count);
-  task->bytes_amount = xbt_new0(double, count * count);
+  task->bytes_amount = xbt_new0(double, count* count);
 
-  for (int i=0; i<count; i++){
-    task->flops_amount[i] = (task->alpha + (1 - task->alpha)/count) * task->amount;
+  for (int i = 0; i < count; i++) {
+    task->flops_amount[i] = (task->alpha + (1 - task->alpha) / count) * task->amount;
   }
 }
 
-void SD_task_build_MxN_1D_block_matrix(SD_task_t task, int src_nb, int dst_nb){
-  xbt_assert(task->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK, "Task %s is not a SD_TASK_COMM_PAR_MXN_1D_BLOCK typed task."
-              "Cannot use this function.", task->name);
+void SD_task_build_MxN_1D_block_matrix(SD_task_t task, int src_nb, int dst_nb)
+{
+  xbt_assert(task->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK,
+             "Task %s is not a SD_TASK_COMM_PAR_MXN_1D_BLOCK typed task."
+             "Cannot use this function.",
+             task->name);
   xbt_free(task->bytes_amount);
-  task->bytes_amount = xbt_new0(double,task->allocation->size() * task->allocation->size());
-
-  for (int i=0; i<src_nb; i++) {
-    double src_start = i*task->amount/src_nb;
-    double src_end = src_start + task->amount/src_nb;
-    for (int j=0; j<dst_nb; j++) {
-      double dst_start = j*task->amount/dst_nb;
-      double dst_end = dst_start + task->amount/dst_nb;
+  task->bytes_amount = xbt_new0(double, task->allocation->size() * task->allocation->size());
+
+  for (int i = 0; i < src_nb; i++) {
+    double src_start = i * task->amount / src_nb;
+    double src_end   = src_start + task->amount / src_nb;
+    for (int j = 0; j < dst_nb; j++) {
+      double dst_start = j * task->amount / dst_nb;
+      double dst_end   = dst_start + task->amount / dst_nb;
       XBT_VERB("(%d->%d): (%.2f, %.2f)-> (%.2f, %.2f)", i, j, src_start, src_end, dst_start, dst_end);
-      task->bytes_amount[i*(src_nb+dst_nb)+src_nb+j]=0.0;
+      task->bytes_amount[i * (src_nb + dst_nb) + src_nb + j] = 0.0;
       if ((src_end > dst_start) && (dst_end > src_start)) { /* There is something to send */
         task->bytes_amount[i * (src_nb + dst_nb) + src_nb + j] =
             std::min(src_end, dst_end) - std::max(src_start, dst_start);
-        XBT_VERB("==> %.2f", task->bytes_amount[i*(src_nb+dst_nb)+src_nb+j]);
+        XBT_VERB("==> %.2f", task->bytes_amount[i * (src_nb + dst_nb) + src_nb + j]);
       }
     }
   }
@@ -889,19 +897,19 @@ void SD_task_build_MxN_1D_block_matrix(SD_task_t task, int src_nb, int dst_nb){
  *
  * To be auto-schedulable, a task must be a typed computation SD_TASK_COMP_SEQ or SD_TASK_COMP_PAR_AMDAHL.
  */
-void SD_task_schedulev(SD_task_t task, int count, const sg_host_t * list)
+void SD_task_schedulev(SD_task_t task, int count, const sg_host_t* list)
 {
   xbt_assert(task->kind == SD_TASK_COMP_SEQ || task->kind == SD_TASK_COMP_PAR_AMDAHL,
-      "Task %s is not typed. Cannot automatically schedule it.", SD_task_get_name(task));
+             "Task %s is not typed. Cannot automatically schedule it.", SD_task_get_name(task));
 
-  for(int i =0; i<count; i++)
+  for (int i = 0; i < count; i++)
     task->allocation->push_back(list[i]);
 
   XBT_VERB("Schedule computation task %s on %zu host(s)", task->name, task->allocation->size());
 
   if (task->kind == SD_TASK_COMP_SEQ) {
     if (not task->flops_amount) { /*This task has failed and is rescheduled. Reset the flops_amount*/
-      task->flops_amount = xbt_new0(double, 1);
+      task->flops_amount    = xbt_new0(double, 1);
       task->flops_amount[0] = task->amount;
     }
     XBT_VERB("It costs %.f flops", task->flops_amount[0]);
@@ -921,16 +929,16 @@ void SD_task_schedulev(SD_task_t task, int count, const sg_host_t * list)
     if (input->allocation->empty())
       XBT_VERB("Sender side of '%s' not scheduled. Set receiver side to '%s''s allocation", input->name, task->name);
 
-    for (int i=0; i<count;i++)
+    for (int i = 0; i < count; i++)
       input->allocation->push_back(task->allocation->at(i));
 
-    if (input->allocation->size () > task->allocation->size()) {
+    if (input->allocation->size() > task->allocation->size()) {
       if (task->kind == SD_TASK_COMP_PAR_AMDAHL)
         SD_task_build_MxN_1D_block_matrix(input, src_nb, dst_nb);
 
       SD_task_do_schedule(input);
-      XBT_VERB ("Auto-Schedule Communication task '%s'. Send %.f bytes from %d hosts to %d hosts.",
-          input->name,input->amount, src_nb, dst_nb);
+      XBT_VERB("Auto-Schedule Communication task '%s'. Send %.f bytes from %d hosts to %d hosts.", input->name,
+               input->amount, src_nb, dst_nb);
     }
   }
 
@@ -940,16 +948,16 @@ void SD_task_schedulev(SD_task_t task, int count, const sg_host_t * list)
     if (output->allocation->empty())
       XBT_VERB("Receiver side of '%s' not scheduled. Set sender side to '%s''s allocation", output->name, task->name);
 
-    for (int i=0; i<count;i++)
-      output->allocation->insert(output->allocation->begin()+i, task->allocation->at(i));
+    for (int i = 0; i < count; i++)
+      output->allocation->insert(output->allocation->begin() + i, task->allocation->at(i));
 
-    if (output->allocation->size () > task->allocation->size()) {
+    if (output->allocation->size() > task->allocation->size()) {
       if (task->kind == SD_TASK_COMP_PAR_AMDAHL)
         SD_task_build_MxN_1D_block_matrix(output, src_nb, dst_nb);
 
       SD_task_do_schedule(output);
-      XBT_VERB ("Auto-Schedule Communication task %s. Send %.f bytes from %d hosts to %d hosts.",
-                output->name, output->amount, src_nb, dst_nb);
+      XBT_VERB("Auto-Schedule Communication task %s. Send %.f bytes from %d hosts to %d hosts.", output->name,
+               output->amount, src_nb, dst_nb);
     }
   }
 }
@@ -964,7 +972,7 @@ void SD_task_schedulel(SD_task_t task, int count, ...)
   va_list ap;
   std::vector<sg_host_t> list(count);
   va_start(ap, count);
-  for (int i=0; i<count; i++)
+  for (int i = 0; i < count; i++)
     list[i] = va_arg(ap, sg_host_t);
 
   va_end(ap);
index 3d2ec1d..50fb970 100644 (file)
@@ -9,6 +9,7 @@
 #include "src/smpi/include/smpi_actor.hpp"
 
 #include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/activity/ExecImpl.hpp"
 #include "src/kernel/activity/IoImpl.hpp"
 #include "src/kernel/activity/MailboxImpl.hpp"
@@ -36,9 +37,7 @@ void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr) = nullptr;
 
 namespace simgrid {
 namespace simix {
-config::Flag<bool> cfg_verbose_exit{"debug/verbose-exit",
-                                    "Display the actor status at exit",
-                                    true};
+config::Flag<bool> cfg_verbose_exit{"debug/verbose-exit", "Display the actor status at exit", true};
 } // namespace simix
 } // namespace simgrid
 
@@ -48,8 +47,7 @@ XBT_ATTRIB_NORETURN static void inthandler(int)
     XBT_INFO("CTRL-C pressed. The current status will be displayed before exit (disable that behavior with option "
              "'debug/verbose-exit').");
     simix_global->display_all_actor_status();
-  }
-  else {
+  } else {
     XBT_INFO("CTRL-C pressed, exiting. Hiding the current process status since 'debug/verbose-exit' is set to false.");
   }
   exit(1);
@@ -73,7 +71,7 @@ static void segvhandler(int signum, siginfo_t* siginfo, void* /*context*/)
             "Minimal Working Example (MWE) reproducing your problem and a full backtrace\n"
             "of the fault captured with gdb or valgrind.\n",
             smx_context_stack_size / 1024);
-  } else  if (siginfo->si_signo == SIGSEGV) {
+  } else if (siginfo->si_signo == SIGSEGV) {
     fprintf(stderr, "Segmentation fault.\n");
 #if HAVE_SMPI
     if (smpi_enabled() && smpi_cfg_privatization() == SmpiPrivStrategies::NONE) {
@@ -109,7 +107,7 @@ static void install_segvhandler()
   struct sigaction action;
   struct sigaction old_action;
   action.sa_sigaction = &segvhandler;
-  action.sa_flags = SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
+  action.sa_flags     = SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
   sigemptyset(&action.sa_mask);
 
   /* Linux tend to raise only SIGSEGV where other systems also raise SIGBUS on severe error */
@@ -198,7 +196,7 @@ void Global::run_all_actors()
 /** Wake up all actors waiting for a Surf action to finish */
 void Global::wake_all_waiting_actors() const
 {
-  for (auto const& model : all_existing_models) {
+  for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) {
     kernel::resource::Action* action;
 
     XBT_DEBUG("Handling the failed actions (if any)");
@@ -255,8 +253,7 @@ void Global::display_all_actor_status() const
 }
 
 config::Flag<double> cfg_breakpoint{"debug/breakpoint",
-                                    "When non-negative, raise a SIGTRAP after given (simulated) time",
-                                    -1.0};
+                                    "When non-negative, raise a SIGTRAP after given (simulated) time", -1.0};
 } // namespace simix
 } // namespace simgrid
 
@@ -264,7 +261,8 @@ static simgrid::kernel::actor::ActorCode maestro_code;
 void SIMIX_set_maestro(void (*code)(void*), void* data)
 {
 #ifdef _WIN32
-  XBT_INFO("WARNING, SIMIX_set_maestro is believed to not work on windows. Please help us investigating this issue if you need that feature");
+  XBT_INFO("WARNING, SIMIX_set_maestro is believed to not work on windows. Please help us investigating this issue if "
+           "you need that feature");
 #endif
   maestro_code = std::bind(code, data);
 }
@@ -273,7 +271,7 @@ void SIMIX_set_maestro(void (*code)(void*), void* data)
  * @ingroup SIMIX_API
  * @brief Initialize SIMIX internal data.
  */
-void SIMIX_global_init(int *argc, char **argv)
+void SIMIX_global_init(int* argc, char** argv)
 {
 #if SIMGRID_HAVE_MC
   // The communication initialization is done ASAP.
@@ -330,9 +328,9 @@ void SIMIX_clean()
 
 #if HAVE_SMPI
   if (not simix_global->process_list.empty()) {
-    if(smpi_process()->initialized()){
+    if (smpi_process()->initialized()) {
       xbt_die("Process exited without calling MPI_Finalize - Killing simulation");
-    }else{
+    } else {
       XBT_WARN("Process called exit when leaving - Skipping cleanups");
       return;
     }
@@ -382,9 +380,9 @@ void SIMIX_clean()
  */
 double SIMIX_get_clock()
 {
-  if(MC_is_active() || MC_record_replay_is_active()){
+  if (MC_is_active() || MC_record_replay_is_active()) {
     return MC_process_clock_get(SIMIX_process_self());
-  }else{
+  } else {
     return surf_get_clock();
   }
 }
index fc80431..d6547d5 100644 (file)
@@ -10,8 +10,6 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_host, ker_resource, "Host resources agregate CPU, networking and I/O features");
 
-simgrid::surf::HostModel *surf_host_model = nullptr;
-
 /*************
  * Callbacks *t
  *************/
index dfe6045..b7e70d6 100644 (file)
@@ -81,6 +81,4 @@ public:
 }
 }
 
-XBT_PUBLIC_DATA simgrid::surf::HostModel* surf_host_model;
-
 #endif /* SURF_HOST_INTERFACE_HPP */
index ee3430c..56e70a7 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "cpu_cas01.hpp"
 #include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
 #include "src/surf/cpu_ti.hpp"
 #include "src/surf/surf_interface.hpp"
@@ -36,9 +37,6 @@ static simgrid::config::Flag<std::string>
  *********/
 void surf_cpu_model_init_Cas01()
 {
-  xbt_assert(surf_cpu_model_pm == nullptr, "CPU model already initialized. This should not happen.");
-  xbt_assert(surf_cpu_model_vm == nullptr, "CPU model already initialized. This should not happen.");
-
   if (cpu_optim_opt == "TI") {
     simgrid::kernel::resource::CpuTiModel::create_pm_vm_models();
     return;
@@ -50,8 +48,12 @@ void surf_cpu_model_init_Cas01()
   else
     algo = simgrid::kernel::resource::Model::UpdateAlgo::FULL;
 
-  surf_cpu_model_pm = new simgrid::kernel::resource::CpuCas01Model(algo);
-  surf_cpu_model_vm = new simgrid::kernel::resource::CpuCas01Model(algo);
+  auto cpu_model_pm = std::make_unique<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);
+  auto cpu_model_vm = std::make_unique<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);
 }
 
 namespace simgrid {
@@ -60,8 +62,6 @@ namespace resource {
 
 CpuCas01Model::CpuCas01Model(Model::UpdateAlgo algo) : CpuModel(algo)
 {
-  all_existing_models.push_back(this);
-
   bool select = config::get_value<bool>("cpu/maxmin-selective-update");
 
   if (is_update_lazy()) {
@@ -73,10 +73,7 @@ CpuCas01Model::CpuCas01Model(Model::UpdateAlgo algo) : CpuModel(algo)
   set_maxmin_system(new lmm::System(select));
 }
 
-CpuCas01Model::~CpuCas01Model()
-{
-  surf_cpu_model_pm = nullptr;
-}
+CpuCas01Model::~CpuCas01Model() {}
 
 Cpu* CpuCas01Model::create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
 {
@@ -210,7 +207,7 @@ int CpuCas01Action::requested_core() const
   return requested_core_;
 }
 
-CpuCas01Action::~CpuCas01Action()=default;
+CpuCas01Action::~CpuCas01Action() = default;
 
 } // namespace resource
 } // namespace kernel
index eafa003..b07f84f 100644 (file)
@@ -11,9 +11,6 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_cpu, ker_resource, "CPU resource, fueling execution activites");
 
-simgrid::kernel::resource::CpuModel* surf_cpu_model_pm;
-simgrid::kernel::resource::CpuModel* surf_cpu_model_vm;
-
 namespace simgrid {
 namespace kernel {
 namespace resource {
index 89cc142..5c24e9a 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "cpu_ti.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
 #include "src/kernel/resource/profile/Profile.hpp"
 #include "src/surf/surf_interface.hpp"
@@ -26,8 +27,8 @@ namespace resource {
 
 CpuTiProfile::CpuTiProfile(const profile::Profile* profile)
 {
-  double integral = 0;
-  double time = 0;
+  double integral    = 0;
+  double time        = 0;
   unsigned nb_points = profile->event_list.size() + 1;
   time_points_.reserve(nb_points);
   integral_.reserve(nb_points);
@@ -55,7 +56,8 @@ double CpuTiTmgr::integrate(double a, double b) const
 {
   if ((a < 0.0) || (a > b)) {
     xbt_die("Error, invalid integration interval [%.2f,%.2f]. "
-        "You probably have a task executing with negative computation amount. Check your code.", a, b);
+            "You probably have a task executing with negative computation amount. Check your code.",
+            a, b);
   }
   if (fabs(a - b) < EPSILON)
     return 0.0;
@@ -71,7 +73,7 @@ double CpuTiTmgr::integrate(double a, double b) const
     a_index = ceil(a / last_time_);
   double b_index = floor(b / last_time_);
 
-  if (a_index > b_index) {      /* Same chunk */
+  if (a_index > b_index) { /* Same chunk */
     return profile_->integrate_simple(a - (a_index - 1) * last_time_, b - b_index * last_time_);
   }
 
@@ -102,7 +104,7 @@ double CpuTiProfile::integrate_simple(double a, double b) const
 double CpuTiProfile::integrate_simple_point(double a) const
 {
   double integral = 0;
-  double a_aux = a;
+  double a_aux    = a;
   int ind         = binary_search(time_points_, a);
   integral += integral_[ind];
 
@@ -138,8 +140,9 @@ double CpuTiTmgr::solve(double a, double amount) const
 
   /* Sanity checks */
   if ((a < 0.0) || (amount < 0.0)) {
-    XBT_CRITICAL ("Error, invalid parameters [a = %.2f, amount = %.2f]. "
-        "You probably have a task executing with negative computation amount. Check your code.", a, amount);
+    XBT_CRITICAL("Error, invalid parameters [a = %.2f, amount = %.2f]. "
+                 "You probably have a task executing with negative computation amount. Check your code.",
+                 a, amount);
     xbt_abort();
   }
 
@@ -202,7 +205,7 @@ double CpuTiProfile::solve_simple(double a, double amount) const
  */
 double CpuTiTmgr::get_power_scale(double a) const
 {
-  double reduced_a          = a - floor(a / last_time_) * last_time_;
+  double reduced_a                = a - floor(a / last_time_) * last_time_;
   int point                       = CpuTiProfile::binary_search(profile_->time_points_, reduced_a);
   kernel::profile::DatedValue val = speed_profile_->event_list.at(point);
   return val.value_;
@@ -267,22 +270,19 @@ int CpuTiProfile::binary_search(const std::vector<double>& array, double a)
 
 void CpuTiModel::create_pm_vm_models()
 {
-  xbt_assert(surf_cpu_model_pm == nullptr, "CPU model already initialized. This should not happen.");
-  xbt_assert(surf_cpu_model_vm == nullptr, "CPU model already initialized. This should not happen.");
-
-  surf_cpu_model_pm = new CpuTiModel();
-  surf_cpu_model_vm = new CpuTiModel();
+  auto cpu_model_pm = std::make_unique<CpuTiModel>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM,
+                                                         std::move(cpu_model_pm), true);
+  auto cpu_model_vm = std::make_unique<CpuTiModel>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM,
+                                                         std::move(cpu_model_vm), true);
 }
 
 CpuTiModel::CpuTiModel() : CpuModel(Model::UpdateAlgo::FULL)
 {
-  all_existing_models.push_back(this);
 }
 
-CpuTiModel::~CpuTiModel()
-{
-  surf_cpu_model_pm = nullptr;
-}
+CpuTiModel::~CpuTiModel() {}
 
 Cpu* CpuTiModel::create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
 {
@@ -405,7 +405,7 @@ void CpuTi::update_actions_finish_time(double now)
   sum_priority_ = 0.0;
   for (CpuTiAction const& action : action_set_) {
     /* action not running, skip it */
-    if (action.get_state_set() != surf_cpu_model_pm->get_started_action_set())
+    if (action.get_state_set() != get_model()->get_started_action_set())
       continue;
 
     /* bogus priority, skip it */
@@ -422,7 +422,7 @@ void CpuTi::update_actions_finish_time(double now)
   for (CpuTiAction& action : action_set_) {
     double min_finish = -1;
     /* action not running, skip it */
-    if (action.get_state_set() != surf_cpu_model_pm->get_started_action_set())
+    if (action.get_state_set() != get_model()->get_started_action_set())
       continue;
 
     /* verify if the action is really running on cpu */
index 11eb89f..12722e7 100644 (file)
@@ -7,6 +7,7 @@
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/lmm/maxmin.hpp"
 #include "src/surf/xml/platf.hpp"
 #include "surf/surf.hpp"
@@ -19,7 +20,9 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_disk);
 
 void surf_disk_model_init_default()
 {
-  surf_disk_model = new simgrid::kernel::resource::DiskS19Model();
+  auto disk_model = std::make_unique<simgrid::kernel::resource::DiskS19Model>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::DISK,
+                                                         std::move(disk_model), true);
 }
 
 namespace simgrid {
@@ -28,7 +31,6 @@ namespace resource {
 
 DiskS19Model::DiskS19Model()
 {
-  all_existing_models.push_back(this);
 }
 
 DiskImpl* DiskS19Model::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
index 0e232e6..c9bb4c5 100644 (file)
@@ -4,50 +4,41 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/surf/host_clm03.hpp"
+#include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "surf/surf.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_host);
 
 void surf_host_model_init_current_default()
 {
-  surf_host_model = new simgrid::surf::HostCLM03Model();
+  auto host_model = std::make_unique<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);
   surf_cpu_model_init_Cas01();
   surf_network_model_init_LegrandVelho();
 }
 
 void surf_host_model_init_compound()
 {
-  xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!");
-  xbt_assert(surf_network_model, "No network model defined yet!");
-  surf_host_model = new simgrid::surf::HostCLM03Model();
+  auto host_model = std::make_unique<simgrid::surf::HostCLM03Model>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
+                                                         std::move(host_model), true);
 }
 
 namespace simgrid {
 namespace surf {
 HostCLM03Model::HostCLM03Model()
 {
-  all_existing_models.push_back(this);
 }
 
 double HostCLM03Model::next_occurring_event(double now)
 {
-  double min_by_cpu = surf_cpu_model_pm->next_occurring_event(now);
-  double min_by_net =
-      surf_network_model->next_occurring_event_is_idempotent() ? surf_network_model->next_occurring_event(now) : -1;
-  double min_by_dsk = surf_disk_model->next_occurring_event(now);
-
-  XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_dsk %f", this,
-            typeid(surf_cpu_model_pm).name(), min_by_cpu, typeid(surf_network_model).name(), min_by_net,
-            typeid(surf_disk_model).name(), min_by_dsk);
-
-  double res = min_by_cpu;
-  if (res < 0 || (min_by_net >= 0.0 && min_by_net < res))
-    res = min_by_net;
-  if (res < 0 || (min_by_dsk >= 0.0 && min_by_dsk < res))
-    res = min_by_dsk;
-  return res;
+  /* nothing specific to be done here
+   * surf_solve already calls all the models next_occuring_event properly */
+  return -1.0;
 }
 
 void HostCLM03Model::update_actions_state(double /*now*/, double /*delta*/)
@@ -68,10 +59,14 @@ kernel::resource::Action* HostCLM03Model::execute_parallel(const std::vector<s4u
                                                            double rate)
 {
   kernel::resource::Action* action = nullptr;
+  /* 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();
   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)) {
-    action = surf_network_model->communicate(host_list[0], host_list[0], bytes_amount[0], rate);
+    action = net_model->communicate(host_list[0], host_list[0], bytes_amount[0], rate);
   } else if ((host_list.size() == 2) && (has_cost(flops_amount, 0) <= 0) && (has_cost(flops_amount, 1) <= 0)) {
     int nb       = 0;
     double value = 0.0;
@@ -83,7 +78,7 @@ kernel::resource::Action* HostCLM03Model::execute_parallel(const std::vector<s4u
       }
     }
     if (nb == 1) {
-      action = surf_network_model->communicate(host_list[0], host_list[1], value, rate);
+      action = net_model->communicate(host_list[0], host_list[1], value, rate);
     } else if (nb == 0) {
       xbt_die("Cannot have a communication with no flop to exchange in this model. You should consider using the "
               "ptask model");
index cc15742..57600ae 100644 (file)
@@ -6,6 +6,7 @@
 #include "src/surf/network_cm02.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
 #include "src/surf/network_wifi.hpp"
 #include "src/surf/surf_interface.hpp"
@@ -16,9 +17,9 @@
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
 
-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 */
+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 */
 
 /************************************************************************/
 /* New model based on optimizations discussed during Pedro Velho's thesis*/
@@ -36,9 +37,9 @@ double sg_weight_S_parameter = 0.0;     /* default value; can be set by model or
 /*  } */
 void surf_network_model_init_LegrandVelho()
 {
-  xbt_assert(surf_network_model == nullptr, "Cannot set the network model twice");
-
-  surf_network_model = new simgrid::kernel::resource::NetworkCm02Model();
+  auto net_model = std::make_unique<simgrid::kernel::resource::NetworkCm02Model>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+                                                         std::move(net_model), true);
 
   simgrid::config::set_default<double>("network/latency-factor", 13.01);
   simgrid::config::set_default<double>("network/bandwidth-factor", 0.97);
@@ -58,13 +59,13 @@ void surf_network_model_init_LegrandVelho()
 /* } */
 void surf_network_model_init_CM02()
 {
-  xbt_assert(surf_network_model == nullptr, "Cannot set the network model twice");
-
   simgrid::config::set_default<double>("network/latency-factor", 1.0);
   simgrid::config::set_default<double>("network/bandwidth-factor", 1.0);
   simgrid::config::set_default<double>("network/weight-S", 0.0);
 
-  surf_network_model = new simgrid::kernel::resource::NetworkCm02Model();
+  auto net_model = std::make_unique<simgrid::kernel::resource::NetworkCm02Model>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+                                                         std::move(net_model), true);
 }
 
 namespace simgrid {
@@ -75,8 +76,6 @@ NetworkCm02Model::NetworkCm02Model()
     : NetworkModel(config::get_value<std::string>("network/optim") == "Full" ? Model::UpdateAlgo::FULL
                                                                              : Model::UpdateAlgo::LAZY)
 {
-  all_existing_models.push_back(this);
-
   std::string optim = config::get_value<std::string>("network/optim");
   bool select       = config::get_value<bool>("network/maxmin-selective-update");
 
@@ -97,11 +96,16 @@ NetworkCm02Model::NetworkCm02Model()
 LinkImpl* NetworkCm02Model::create_link(const std::string& name, const std::vector<double>& bandwidths,
                                         s4u::Link::SharingPolicy policy)
 {
-  if (policy == s4u::Link::SharingPolicy::WIFI)
-    return (new NetworkWifiLink(name, bandwidths, get_maxmin_system()))->set_model(this);
+  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], policy, get_maxmin_system()))->set_model(this);
+  link->set_model(this);
+  return link;
 }
 
 void NetworkCm02Model::update_actions_state_lazy(double now, double /*delta*/)
@@ -216,8 +220,8 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz
     action = new NetworkCm02Action(this, *src, *dst, size, failed);
   else
     action = new NetworkWifiAction(this, *src, *dst, size, failed, src_wifi_link, dst_wifi_link);
-  action->sharing_penalty_  = latency;
-  action->latency_ = latency;
+  action->sharing_penalty_ = latency;
+  action->latency_         = latency;
   action->set_user_bound(rate);
 
   if (is_update_lazy()) {
@@ -361,7 +365,7 @@ void NetworkCm02Link::set_bandwidth(double value)
     const kernel::lmm::Variable* var;
     const kernel::lmm::Element* elem     = nullptr;
     const kernel::lmm::Element* nextelem = nullptr;
-    int numelem                  = 0;
+    int numelem                          = 0;
     while ((var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
       auto* action = static_cast<NetworkCm02Action*>(var->get_id());
       action->sharing_penalty_ += delta;
@@ -375,14 +379,14 @@ LinkImpl* NetworkCm02Link::set_latency(double value)
 {
   latency_check(value);
 
-  double delta                 = value - latency_.peak;
+  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;
+  int numelem                          = 0;
 
   latency_.scale = 1.0;
-  latency_.peak = value;
+  latency_.peak  = value;
 
   while ((var = get_constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
     auto* action = static_cast<NetworkCm02Action*>(var->get_id());
index 37dc9be..7c879c8 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "network_constant.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/surf/surf_interface.hpp"
 #include "surf/surf.hpp"
 
@@ -14,8 +15,9 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
  *********/
 void surf_network_model_init_Constant()
 {
-  xbt_assert(surf_network_model == nullptr);
-  surf_network_model = new simgrid::kernel::resource::NetworkConstantModel();
+  auto net_model = std::make_unique<simgrid::kernel::resource::NetworkConstantModel>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+                                                         std::move(net_model), true);
 }
 
 namespace simgrid {
@@ -24,7 +26,6 @@ namespace resource {
 
 NetworkConstantModel::NetworkConstantModel() : NetworkModel(Model::UpdateAlgo::FULL)
 {
-  all_existing_models.push_back(this);
 }
 
 LinkImpl* NetworkConstantModel::create_link(const std::string& name, const std::vector<double>& /*bandwidth*/,
index 9653b66..eedd459 100644 (file)
@@ -4,7 +4,9 @@
  * 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/kernel/EngineImpl.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/xml/platf.hpp"
 #include "surf/surf.hpp"
@@ -19,9 +21,9 @@ static void IB_create_host_callback(simgrid::s4u::Host const& host)
   using simgrid::kernel::resource::IBNode;
   using simgrid::kernel::resource::NetworkIBModel;
 
-  static int id=0;
-
-  ((NetworkIBModel*)surf_network_model)->active_nodes.emplace(host.get_name(), IBNode(id));
+  static int id = 0;
+  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 +31,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());
 
@@ -67,9 +69,10 @@ static void IB_action_init_callback(simgrid::kernel::resource::NetworkAction& ac
 /*  } */
 void surf_network_model_init_IB()
 {
-  xbt_assert(surf_network_model == nullptr, "Cannot set the network model twice");
+  auto net_model = std::make_unique<simgrid::kernel::resource::NetworkIBModel>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+                                                         std::move(net_model), true);
 
-  surf_network_model = new simgrid::kernel::resource::NetworkIBModel();
   simgrid::s4u::Link::on_communication_state_change.connect(IB_action_state_changed_callback);
   simgrid::s4u::Link::on_communicate.connect(IB_action_init_callback);
   simgrid::s4u::Host::on_creation.connect(IB_create_host_callback);
@@ -82,8 +85,6 @@ namespace resource {
 
 NetworkIBModel::NetworkIBModel() : NetworkSmpiModel()
 {
-  /* Do not add this into all_existing_models: our ancestor already does so */
-
   std::string IB_factors_string = config::get_value<std::string>("smpi/IB-penalty-factors");
   std::vector<std::string> radical_elements;
   boost::split(radical_elements, IB_factors_string, boost::is_any_of(";"));
index f33fe69..c87e5e0 100644 (file)
@@ -19,8 +19,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_network, ker_resource, "Network resources, t
  * Model *
  *********/
 
-simgrid::kernel::resource::NetworkModel* surf_network_model = nullptr;
-
 namespace simgrid {
 namespace kernel {
 namespace resource {
@@ -155,6 +153,7 @@ void LinkImpl::turn_off()
 
 void LinkImpl::seal()
 {
+  xbt_assert(this->get_model(), "Cannot seal Link(%s) without setting the Network model first", this->get_cname());
   Resource::seal();
   simgrid::s4u::Link::on_creation(*get_iface());
 }
index a109c14..ea4880a 100644 (file)
@@ -210,11 +210,6 @@ public:
 } // namespace kernel
 } // namespace simgrid
 
-/** @ingroup SURF_models
- *  @brief The network model
- */
-XBT_PUBLIC_DATA simgrid::kernel::resource::NetworkModel* surf_network_model;
-
 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
 
 
index 569b6c6..8ba3f2e 100644 (file)
 #include "xbt/string.hpp"
 #include "xbt/utility.hpp"
 
+#include <ns3/application-container.h>
 #include <ns3/core-module.h>
 #include <ns3/csma-helper.h>
+#include <ns3/event-id.h>
 #include <ns3/global-route-manager.h>
 #include <ns3/internet-stack-helper.h>
 #include <ns3/ipv4-address-helper.h>
 #include <ns3/packet-sink-helper.h>
 #include <ns3/point-to-point-helper.h>
-#include <ns3/application-container.h>
-#include <ns3/event-id.h>
 
 #include "ns3/mobility-module.h"
 #include "ns3/wifi-module.h"
@@ -33,6 +33,7 @@
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/NetZone.hpp"
 #include "src/instr/instr_private.hpp" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
+#include "src/kernel/EngineImpl.hpp"
 #include "src/surf/surf_interface.hpp"
 #include "src/surf/xml/platf_private.hpp"
 #include "surf/surf.hpp"
@@ -48,7 +49,7 @@ extern std::map<std::string, ns3::ApplicationContainer, std::less<>> sink_from_s
 
 static ns3::InternetStackHelper stack;
 
-static int number_of_links = 1;
+static int number_of_links    = 1;
 static int number_of_networks = 1;
 
 /* wifi globals */
@@ -85,99 +86,98 @@ static void resumeWifiDevice(ns3::Ptr<ns3::WifiNetDevice> device)
  * Callbacks *
  *************/
 
-static void zoneCreation_cb(simgrid::s4u::NetZone const& zone) {
-    simgrid::kernel::routing::WifiZone* wifizone = dynamic_cast<simgrid::kernel::routing::WifiZone*> (zone.get_impl());
-    if (wifizone == nullptr) return;
+static void zoneCreation_cb(simgrid::s4u::NetZone const& zone)
+{
+  simgrid::kernel::routing::WifiZone* wifizone = dynamic_cast<simgrid::kernel::routing::WifiZone*>(zone.get_impl());
+  if (wifizone == nullptr)
+    return;
 
 #if NS3_MINOR_VERSION < 32
-    wifi.SetStandard(ns3::WIFI_PHY_STANDARD_80211n_5GHZ);
+  wifi.SetStandard(ns3::WIFI_PHY_STANDARD_80211n_5GHZ);
 #else
-    wifi.SetStandard(ns3::WIFI_STANDARD_80211n_5GHZ);
+  wifi.SetStandard(ns3::WIFI_STANDARD_80211n_5GHZ);
 #endif
 
-    std::string ssid = wifizone->get_name();
-    const char* mcs = wifizone->get_property("mcs");
-    const char* nss = wifizone->get_property("nss");
-    int mcs_value = mcs ? atoi(mcs) : 3;
-    int nss_value = nss ? atoi(nss) : 1;
+  std::string ssid = wifizone->get_name();
+  const char* mcs  = wifizone->get_property("mcs");
+  const char* nss  = wifizone->get_property("nss");
+  int mcs_value    = mcs ? atoi(mcs) : 3;
+  int nss_value    = nss ? atoi(nss) : 1;
 #if NS3_MINOR_VERSION < 30
-    if(nss_value != 1+(mcs_value/8))
-      xbt_die("On NS3 < 3.30, NSS value has to satisfy NSS == 1+(MCS/8) constraint. Bailing out");
+  if (nss_value != 1 + (mcs_value / 8))
+    xbt_die("On NS3 < 3.30, NSS value has to satisfy NSS == 1+(MCS/8) constraint. Bailing out");
 #endif
-    wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
-                                 "ControlMode", ns3::StringValue("HtMcs0"),
-                                 "DataMode", ns3::StringValue("HtMcs" + std::to_string(mcs_value)));
-    wifiPhy.SetChannel(wifiChannel.Create());
-    wifiPhy.Set("Antennas", ns3::UintegerValue(nss_value));
-    wifiPhy.Set("MaxSupportedTxSpatialStreams", ns3::UintegerValue(nss_value));
-    wifiPhy.Set("MaxSupportedRxSpatialStreams", ns3::UintegerValue(nss_value));
-    wifiMac.SetType("ns3::ApWifiMac",
-                    "Ssid", ns3::SsidValue(ssid));
-
-    mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
-    ns3::Ptr<ns3::ListPositionAllocator> positionAllocS = ns3::CreateObject<ns3::ListPositionAllocator>();
-    positionAllocS->Add(ns3::Vector(0, 0, 255 * 100 * number_of_networks + 100 * number_of_links));
-
-    ns3::NetDeviceContainer netDevices;
-    NetPointNs3* access_point_netpoint_ns3 = wifizone->get_access_point()->extension<NetPointNs3>();
-
-    ns3::Ptr<ns3::Node> access_point_ns3_node = access_point_netpoint_ns3->ns3_node_;
-    ns3::NodeContainer nodes = {access_point_ns3_node};
-    std::vector<NetPointNs3*> hosts_netpoints = {access_point_netpoint_ns3};
-    netDevices.Add(wifi.Install(wifiPhy, wifiMac,access_point_ns3_node));
-
-    wifiMac.SetType ("ns3::StaWifiMac",
-                     "Ssid", ns3::SsidValue(ssid),
-                     "ActiveProbing", ns3::BooleanValue(false));
-
-    NetPointNs3* station_netpoint_ns3 = nullptr;
-    ns3::Ptr<ns3::Node> station_ns3_node = nullptr;
-    double distance;
-    double angle = 0;
-    int nb_stations = wifizone->get_all_hosts().size() - 1;
-    double step = 2 * M_PI / nb_stations;
-    for (auto station_host : wifizone->get_all_hosts()) {
-        station_netpoint_ns3 = station_host->get_netpoint()->extension<NetPointNs3>();
-        if (station_netpoint_ns3 == access_point_netpoint_ns3)
-            continue;
-        hosts_netpoints.push_back(station_netpoint_ns3);
-        distance = station_host->get_property("wifi_distance") ? atof(station_host->get_property("wifi_distance")) : 10.0;
-        positionAllocS->Add(ns3::Vector(distance * std::cos(angle), distance * std::sin(angle), 255 * 100 * number_of_networks + 100 * number_of_links));
-        angle += step;
-        station_ns3_node = station_netpoint_ns3->ns3_node_;
-        nodes.Add(station_ns3_node);
-        netDevices.Add(wifi.Install(wifiPhy, wifiMac, station_ns3_node));
-    }
+  wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "ControlMode", ns3::StringValue("HtMcs0"), "DataMode",
+                               ns3::StringValue("HtMcs" + std::to_string(mcs_value)));
+  wifiPhy.SetChannel(wifiChannel.Create());
+  wifiPhy.Set("Antennas", ns3::UintegerValue(nss_value));
+  wifiPhy.Set("MaxSupportedTxSpatialStreams", ns3::UintegerValue(nss_value));
+  wifiPhy.Set("MaxSupportedRxSpatialStreams", ns3::UintegerValue(nss_value));
+  wifiMac.SetType("ns3::ApWifiMac", "Ssid", ns3::SsidValue(ssid));
+
+  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
+  ns3::Ptr<ns3::ListPositionAllocator> positionAllocS = ns3::CreateObject<ns3::ListPositionAllocator>();
+  positionAllocS->Add(ns3::Vector(0, 0, 255 * 100 * number_of_networks + 100 * number_of_links));
+
+  ns3::NetDeviceContainer netDevices;
+  NetPointNs3* access_point_netpoint_ns3 = wifizone->get_access_point()->extension<NetPointNs3>();
+
+  ns3::Ptr<ns3::Node> access_point_ns3_node = access_point_netpoint_ns3->ns3_node_;
+  ns3::NodeContainer nodes                  = {access_point_ns3_node};
+  std::vector<NetPointNs3*> hosts_netpoints = {access_point_netpoint_ns3};
+  netDevices.Add(wifi.Install(wifiPhy, wifiMac, access_point_ns3_node));
+
+  wifiMac.SetType("ns3::StaWifiMac", "Ssid", ns3::SsidValue(ssid), "ActiveProbing", ns3::BooleanValue(false));
+
+  NetPointNs3* station_netpoint_ns3    = nullptr;
+  ns3::Ptr<ns3::Node> station_ns3_node = nullptr;
+  double distance;
+  double angle    = 0;
+  int nb_stations = wifizone->get_all_hosts().size() - 1;
+  double step     = 2 * M_PI / nb_stations;
+  for (auto station_host : wifizone->get_all_hosts()) {
+    station_netpoint_ns3 = station_host->get_netpoint()->extension<NetPointNs3>();
+    if (station_netpoint_ns3 == access_point_netpoint_ns3)
+      continue;
+    hosts_netpoints.push_back(station_netpoint_ns3);
+    distance = station_host->get_property("wifi_distance") ? atof(station_host->get_property("wifi_distance")) : 10.0;
+    positionAllocS->Add(ns3::Vector(distance * std::cos(angle), distance * std::sin(angle),
+                                    255 * 100 * number_of_networks + 100 * number_of_links));
+    angle += step;
+    station_ns3_node = station_netpoint_ns3->ns3_node_;
+    nodes.Add(station_ns3_node);
+    netDevices.Add(wifi.Install(wifiPhy, wifiMac, station_ns3_node));
+  }
 
-    const char* start_time = wifizone->get_property("start_time");
-    int start_time_value = start_time ? atoi(start_time) : 0;
-    for (uint32_t i = 0; i < netDevices.GetN(); i++) {
-      ns3::Ptr<ns3::WifiNetDevice> device = ns3::StaticCast<ns3::WifiNetDevice>(netDevices.Get(i));
-      device->GetPhy()->SetOffMode();
-      ns3::Simulator::Schedule(ns3::Seconds(start_time_value), &resumeWifiDevice, device);
-    }
+  const char* start_time = wifizone->get_property("start_time");
+  int start_time_value   = start_time ? atoi(start_time) : 0;
+  for (uint32_t i = 0; i < netDevices.GetN(); i++) {
+    ns3::Ptr<ns3::WifiNetDevice> device = ns3::StaticCast<ns3::WifiNetDevice>(netDevices.Get(i));
+    device->GetPhy()->SetOffMode();
+    ns3::Simulator::Schedule(ns3::Seconds(start_time_value), &resumeWifiDevice, device);
+  }
 
-    ns3::Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", ns3::UintegerValue(40));
+  ns3::Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", ns3::UintegerValue(40));
 
-    mobility.SetPositionAllocator(positionAllocS);
-    mobility.Install(nodes);
+  mobility.SetPositionAllocator(positionAllocS);
+  mobility.Install(nodes);
 
-    ns3::Ipv4AddressHelper address;
-    std::string addr = simgrid::xbt::string_printf("%d.%d.0.0", number_of_networks, number_of_links);
-    address.SetBase(addr.c_str(), "255.255.0.0");
-    XBT_DEBUG("\tInterface stack '%s'", addr.c_str());
-    ns3::Ipv4InterfaceContainer addresses = address.Assign(netDevices);
-    for (unsigned int i = 0; i < hosts_netpoints.size(); i++) {
-        hosts_netpoints[i]->ipv4_address_ = transformIpv4Address(addresses.GetAddress(i));
-    }
+  ns3::Ipv4AddressHelper address;
+  std::string addr = simgrid::xbt::string_printf("%d.%d.0.0", number_of_networks, number_of_links);
+  address.SetBase(addr.c_str(), "255.255.0.0");
+  XBT_DEBUG("\tInterface stack '%s'", addr.c_str());
+  ns3::Ipv4InterfaceContainer addresses = address.Assign(netDevices);
+  for (unsigned int i = 0; i < hosts_netpoints.size(); i++) {
+    hosts_netpoints[i]->ipv4_address_ = transformIpv4Address(addresses.GetAddress(i));
+  }
 
-    if (number_of_links == 255) {
-      xbt_assert(number_of_networks < 255, "Number of links and networks exceed 255*255");
-      number_of_links = 1;
-      number_of_networks++;
-    } else {
-      number_of_links++;
-    }
+  if (number_of_links == 255) {
+    xbt_assert(number_of_networks < 255, "Number of links and networks exceed 255*255");
+    number_of_links = 1;
+    number_of_networks++;
+  } else {
+    number_of_links++;
+  }
 }
 
 static void clusterCreation_cb(simgrid::kernel::routing::ClusterCreationArgs const& cluster)
@@ -259,9 +259,9 @@ static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoin
  *********/
 void surf_network_model_init_NS3()
 {
-  xbt_assert(surf_network_model == nullptr, "Cannot set the network model twice");
-
-  surf_network_model = new simgrid::kernel::resource::NetworkNS3Model();
+  auto net_model = std::make_unique<simgrid::kernel::resource::NetworkNS3Model>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+                                                         std::move(net_model), true);
 }
 
 static simgrid::config::Flag<std::string>
@@ -293,8 +293,6 @@ NetworkNS3Model::NetworkNS3Model() : NetworkModel(Model::UpdateAlgo::FULL)
   xbt_assert(not sg_link_energy_is_inited(),
              "LinkEnergy plugin and ns-3 network models are not compatible. Are you looking for Ecofen, maybe?");
 
-  all_existing_models.push_back(this);
-
   NetPointNs3::EXTENSION_ID = routing::NetPoint::extension_create<NetPointNs3>();
 
   ns3::Config::SetDefault("ns3::TcpSocket::SegmentSize", ns3::UintegerValue(1000));
@@ -332,7 +330,9 @@ LinkImpl* NetworkNS3Model::create_link(const std::string& name, const std::vecto
                                        s4u::Link::SharingPolicy policy)
 {
   xbt_assert(bandwidths.size() == 1, "ns-3 links must use only 1 bandwidth.");
-  return new LinkNS3(name, bandwidths[0], policy);
+  auto link = new LinkNS3(name, bandwidths[0], policy);
+  link->set_model(this);
+  return link;
 }
 
 Action* NetworkNS3Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
@@ -348,7 +348,7 @@ double NetworkNS3Model::next_occurring_event(double now)
   double time_to_next_flow_completion = 0.0;
   XBT_DEBUG("ns3_next_occurring_event");
 
-  //get the first relevant value from the running_actions list
+  // get the first relevant value from the running_actions list
 
   // If there is no comms in NS-3, then we do not move it forward.
   // We will synchronize NS-3 with SimGrid when starting a new communication.
@@ -362,7 +362,7 @@ double NetworkNS3Model::next_occurring_event(double now)
   // NS-3 stops as soon as a flow ends,
   // but it does not process the other flows that may finish at the same (simulated) time.
   // If another flow ends at the same time, time_to_next_flow_completion = 0
-  if(double_equals(time_to_next_flow_completion, 0, sg_surf_precision))
+  if (double_equals(time_to_next_flow_completion, 0, sg_surf_precision))
     time_to_next_flow_completion = 0.0;
 
   XBT_DEBUG("min       : %f", now);
@@ -379,16 +379,16 @@ void NetworkNS3Model::update_actions_state(double now, double delta)
 
   std::string ns3_socket;
   for (const auto& elm : flow_from_sock) {
-    ns3_socket                = elm.first;
-    SgFlow* sgFlow            = elm.second;
-    NetworkNS3Action * action = sgFlow->action_;
+    ns3_socket               = elm.first;
+    SgFlow* sgFlow           = elm.second;
+    NetworkNS3Action* action = sgFlow->action_;
     XBT_DEBUG("Processing flow %p (socket %s, action %p)", sgFlow, ns3_socket.c_str(), action);
     // Because NS3 stops as soon as a flow is finished, the other flows that ends at the same time may remains in an
     // inconsistent state (i.e. remains_ == 0 but finished_ == false).
     // However, SimGrid considers sometimes that an action with remains_ == 0 is finished.
     // Thus, to avoid inconsistencies between SimGrid and NS3, set remains to 0 only when the flow is finished in NS3
     int remains = action->get_cost() - sgFlow->sent_bytes_;
-    if(remains > 0)
+    if (remains > 0)
       action->set_remains(remains);
 
     if (TRACE_is_enabled() && action->get_state() == kernel::resource::Action::State::STARTED) {
@@ -404,7 +404,8 @@ void NetworkNS3Model::update_actions_state(double now, double delta)
       action->last_sent_ = sgFlow->sent_bytes_;
     }
 
-    if ((sgFlow->finished_) && (remains <= 0)) { // finished_ should not become true before remains gets to 0, but it sometimes does. Let's play safe, here.
+    if ((sgFlow->finished_) && (remains <= 0)) { // finished_ should not become true before remains gets to 0, but it
+                                                 // sometimes does. Let's play safe, here.
       socket_to_destroy.push_back(ns3_socket);
       XBT_DEBUG("Destroy socket %s of action %p", ns3_socket.c_str(), action);
       action->set_remains(0);
@@ -475,9 +476,10 @@ NetworkNS3Action::NetworkNS3Action(Model* model, double totalBytes, s4u::Host* s
   }
 
   // If there is no other started actions, we need to move NS-3 forward to be sync with SimGrid
-  if (model->get_started_action_set()->size()==1){
-    while(double_positive(surf_get_clock() - ns3::Simulator::Now().GetSeconds(), sg_surf_precision)){
-      XBT_DEBUG("Synchronizing NS-3 (time %f) with SimGrid (time %f)", ns3::Simulator::Now().GetSeconds(), surf_get_clock());
+  if (model->get_started_action_set()->size() == 1) {
+    while (double_positive(surf_get_clock() - ns3::Simulator::Now().GetSeconds(), sg_surf_precision)) {
+      XBT_DEBUG("Synchronizing NS-3 (time %f) with SimGrid (time %f)", ns3::Simulator::Now().GetSeconds(),
+                surf_get_clock());
       ns3_simulator(surf_get_clock() - ns3::Simulator::Now().GetSeconds());
     }
   }
@@ -512,11 +514,13 @@ NetworkNS3Action::NetworkNS3Action(Model* model, double totalBytes, s4u::Host* s
   s4u::Link::on_communicate(*this);
 }
 
-void NetworkNS3Action::suspend() {
+void NetworkNS3Action::suspend()
+{
   THROW_UNIMPLEMENTED;
 }
 
-void NetworkNS3Action::resume() {
+void NetworkNS3Action::resume()
+{
   THROW_UNIMPLEMENTED;
 }
 
@@ -540,10 +544,10 @@ void ns3_simulator(double maxSeconds)
     id = ns3::Simulator::Schedule(ns3::Seconds(maxSeconds), &ns3::Simulator::Stop);
 
   XBT_DEBUG("Start simulator for at most %fs (current time: %f)", maxSeconds, surf_get_clock());
-  ns3::Simulator::Run ();
+  ns3::Simulator::Run();
   XBT_DEBUG("Simulator stopped at %fs", ns3::Simulator::Now().GetSeconds());
 
-  if(maxSeconds > 0.0)
+  if (maxSeconds > 0.0)
     id.Cancel();
 }
 
@@ -561,7 +565,7 @@ void ns3_add_direct_route(simgrid::kernel::routing::NetPoint* src, simgrid::kern
   xbt_assert(host_dst != nullptr, "Network element %s does not seem to be ns-3-ready", dst->get_cname());
 
   if (policy == simgrid::s4u::Link::SharingPolicy::WIFI) {
-      xbt_die("The wifi sharing policy is not supported for links. You want to use a wifi zone (see documentation).");
+    xbt_die("The wifi sharing policy is not supported for links. You want to use a wifi zone (see documentation).");
   } else {
     ns3::PointToPointHelper pointToPoint;
 
index 3ec527e..0b03bd9 100644 (file)
@@ -6,6 +6,7 @@
 #include "network_smpi.hpp"
 #include "simgrid/sg_config.hpp"
 #include "smpi_utils.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/surf/surf_interface.hpp"
 #include "surf/surf.hpp"
 
@@ -22,7 +23,8 @@ std::vector<s_smpi_factor_t> smpi_lat_factor;
 /* New model based on LV08 and experimental results of MPI ping-pongs   */
 /************************************************************************/
 /* @Inproceedings{smpi_ipdps, */
-/*  author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */
+/*  author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and
+ * Martin Quinson}, */
 /*  title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
 /*  booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
 /*  address={Anchorage (Alaska) USA}, */
@@ -31,9 +33,9 @@ std::vector<s_smpi_factor_t> smpi_lat_factor;
 /*  } */
 void surf_network_model_init_SMPI()
 {
-  if (surf_network_model)
-    return;
-  surf_network_model = new simgrid::kernel::resource::NetworkSmpiModel();
+  auto net_model = std::make_unique<simgrid::kernel::resource::NetworkSmpiModel>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+                                                         std::move(net_model), true);
 
   simgrid::config::set_default<double>("network/weight-S", 8775);
 }
@@ -44,7 +46,6 @@ namespace resource {
 
 NetworkSmpiModel::NetworkSmpiModel() : NetworkCm02Model()
 {
-  /* Do not add this into all_existing_models: our ancestor already does so */
 }
 
 double NetworkSmpiModel::get_bandwidth_factor(double size)
index c55755f..de75a27 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "ptask_L07.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
 #include "surf/surf.hpp"
 #include "xbt/config.hpp"
@@ -18,30 +19,31 @@ XBT_LOG_EXTERNAL_CATEGORY(xbt_cfg);
 /**************************************/
 void surf_host_model_init_ptask_L07()
 {
-  XBT_CINFO(xbt_cfg,"Switching to the L07 model to handle parallel tasks.");
-  xbt_assert(not surf_cpu_model_pm, "Cannot switch to ptasks: CPU model already defined");
-  xbt_assert(not surf_network_model, "Cannot switch to ptasks: network model already defined");
+  XBT_CINFO(xbt_cfg, "Switching to the L07 model to handle parallel tasks.");
 
-  surf_host_model = new simgrid::surf::HostL07Model();
-  all_existing_models.push_back(surf_host_model);
+  auto host_model = std::make_unique<simgrid::surf::HostL07Model>();
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
+                                                         std::move(host_model), true);
 }
 
 namespace simgrid {
 namespace surf {
 
-HostL07Model::HostL07Model() : HostModel() {
+HostL07Model::HostL07Model() : HostModel()
+{
   auto* maxmin_system = new simgrid::kernel::lmm::FairBottleneck(true /* selective update */);
   set_maxmin_system(maxmin_system);
-  surf_network_model = new NetworkL07Model(this, maxmin_system);
-  surf_cpu_model_pm  = new CpuL07Model(this, maxmin_system);
-}
 
-HostL07Model::~HostL07Model()
-{
-  delete surf_network_model;
-  delete surf_cpu_model_pm;
+  net_model_  = std::make_unique<NetworkL07Model>(this, maxmin_system);
+  auto engine = simgrid::kernel::EngineImpl::get_instance();
+  engine->add_model_ptask(simgrid::kernel::resource::Model::Type::NETWORK, net_model_.get(), true);
+
+  cpu_model_ = std::make_unique<CpuL07Model>(this, maxmin_system);
+  engine->add_model_ptask(simgrid::kernel::resource::Model::Type::CPU_PM, cpu_model_.get(), true);
 }
 
+HostL07Model::~HostL07Model() {}
+
 CpuL07Model::CpuL07Model(HostL07Model* hmodel, kernel::lmm::System* sys)
     : CpuModel(Model::UpdateAlgo::FULL), hostModel_(hmodel)
 {
@@ -57,9 +59,10 @@ NetworkL07Model::NetworkL07Model(HostL07Model* hmodel, kernel::lmm::System* sys)
     : NetworkModel(Model::UpdateAlgo::FULL), hostModel_(hmodel)
 {
   set_maxmin_system(sys);
-  loopback_ = NetworkL07Model::create_link("__loopback__", 
-                                            std::vector<double>{simgrid::config::get_value<double>("network/loopback-bw")},
-                                            s4u::Link::SharingPolicy::FATPIPE)->set_latency(simgrid::config::get_value<double>("network/loopback-lat"));
+  loopback_ = NetworkL07Model::create_link(
+                  "__loopback__", std::vector<double>{simgrid::config::get_value<double>("network/loopback-bw")},
+                  s4u::Link::SharingPolicy::FATPIPE)
+                  ->set_latency(simgrid::config::get_value<double>("network/loopback-lat"));
   loopback_->seal();
 }
 
@@ -120,7 +123,7 @@ void HostL07Model::update_actions_state(double /*now*/, double delta)
     }
 
     /* Need to check that none of the model has failed */
-    int i                         = 0;
+    int i                               = 0;
     const kernel::lmm::Constraint* cnst = action.get_variable()->get_constraint(i);
     while (cnst != nullptr) {
       i++;
@@ -148,7 +151,7 @@ L07Action::L07Action(kernel::resource::Model* model, const std::vector<s4u::Host
 {
   size_t link_nb      = 0;
   size_t used_host_nb = 0; /* Only the hosts with something to compute (>0 flops) are counted) */
-  double latency = 0.0;
+  double latency      = 0.0;
   this->set_last_update();
 
   hostList_.insert(hostList_.end(), host_list.begin(), host_list.end());
@@ -157,7 +160,7 @@ L07Action::L07Action(kernel::resource::Model* model, const std::vector<s4u::Host
     used_host_nb += std::count_if(flops_amount, flops_amount + host_list.size(), [](double x) { return x > 0.0; });
 
   /* Compute the number of affected resources... */
-  if(bytes_amount != nullptr) {
+  if (bytes_amount != nullptr) {
     std::unordered_set<const char*> affected_links;
 
     for (size_t k = 0; k < host_list.size() * host_list.size(); k++) {
@@ -238,7 +241,9 @@ kernel::resource::LinkImpl* NetworkL07Model::create_link(const std::string& name
                                                          s4u::Link::SharingPolicy policy)
 {
   xbt_assert(bandwidths.size() == 1, "Non WIFI link must have only 1 bandwidth.");
-  return new LinkL07(name, bandwidths[0], policy, get_maxmin_system());
+  auto link = new LinkL07(name, bandwidths[0], policy, get_maxmin_system());
+  link->set_model(this);
+  return link;
 }
 
 /************
@@ -250,7 +255,7 @@ kernel::resource::CpuAction* CpuL07::execution_start(double size)
   std::vector<s4u::Host*> host_list = {get_iface()};
 
   auto* flops_amount = new double[host_list.size()]();
-  flops_amount[0] = size;
+  flops_amount[0]    = size;
 
   kernel::resource::CpuAction* res =
       static_cast<CpuL07Model*>(get_model())->hostModel_->execute_parallel(host_list, flops_amount, nullptr, -1);
@@ -363,7 +368,7 @@ kernel::resource::LinkImpl* LinkL07::set_latency(double value)
 {
   latency_check(value);
   const kernel::lmm::Variable* var;
-  L07Action *action;
+  L07Actionaction;
   const kernel::lmm::Element* elem = nullptr;
 
   latency_.peak = value;
index a38cb2d..fe5fe36 100644 (file)
@@ -3,10 +3,10 @@
 /* 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. */
 
+#include "src/surf/HostImpl.hpp"
 #include <cstdlib>
 #include <vector>
 #include <xbt/base.h>
-#include "src/surf/HostImpl.hpp"
 
 #ifndef HOST_L07_HPP_
 #define HOST_L07_HPP_
@@ -44,6 +44,10 @@ public:
   void update_actions_state(double now, double delta) override;
   kernel::resource::CpuAction* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
                                                 const double* bytes_amount, double rate) override;
+
+private:
+  std::unique_ptr<NetworkL07Model> net_model_;
+  std::unique_ptr<CpuL07Model> cpu_model_;
 };
 
 class CpuL07Model : public kernel::resource::CpuModel {
@@ -54,7 +58,7 @@ public:
   ~CpuL07Model() override;
 
   kernel::resource::Cpu* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
-  HostL07Model *hostModel_;
+  HostL07ModelhostModel_;
 };
 
 class NetworkL07Model : public kernel::resource::NetworkModel {
@@ -68,7 +72,7 @@ public:
 
   kernel::resource::Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
 
-  HostL07Model *hostModel_;
+  HostL07ModelhostModel_;
 };
 
 /************
index 68165eb..867b0d2 100644 (file)
@@ -54,7 +54,8 @@ void sg_platf_init()
 }
 
 /** Module management function: frees all internal data structures */
-void sg_platf_exit() {
+void sg_platf_exit()
+{
   simgrid::kernel::routing::on_cluster_creation.disconnect_slots();
   simgrid::s4u::Engine::on_platform_created.disconnect_slots();
 
@@ -106,7 +107,6 @@ simgrid::kernel::routing::NetPoint* sg_platf_new_router(const std::string& name,
   if (coords && strcmp(coords, ""))
     new simgrid::kernel::routing::vivaldi::Coords(netpoint, coords);
 
-
   return netpoint;
 }
 
@@ -148,7 +148,7 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
   using simgrid::kernel::routing::FatTreeZone;
   using simgrid::kernel::routing::TorusZone;
 
-  int rankId=0;
+  int rankId = 0;
 
   // What an inventive way of initializing the AS that I have as ancestor :-(
   simgrid::kernel::routing::ZoneCreationArgs zone;
@@ -174,12 +174,12 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
     for (auto const& elm : *cluster->properties)
       current_as->get_iface()->set_property(elm.first, elm.second);
 
-  if(cluster->loopback_bw > 0 || cluster->loopback_lat > 0){
+  if (cluster->loopback_bw > 0 || cluster->loopback_lat > 0) {
     current_as->num_links_per_node_++;
     current_as->has_loopback_ = true;
   }
 
-  if(cluster->limiter_link > 0){
+  if (cluster->limiter_link > 0) {
     current_as->num_links_per_node_++;
     current_as->has_limiter_ = true;
   }
@@ -200,9 +200,9 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
     }
 
     host.speed_per_pstate = cluster->speeds;
-    host.pstate = 0;
-    host.core_amount = cluster->core_amount;
-    host.coord = "";
+    host.pstate           = 0;
+    host.core_amount      = cluster->core_amount;
+    host.coord            = "";
     sg_platf_new_host(&host);
     XBT_DEBUG("</host>");
 
@@ -214,18 +214,18 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
     // the second column may store a limiter link if p_has_limiter is set
     // other columns are to store one or more link for the node
 
-    //add a loopback link
+    // add a loopback link
     const simgrid::s4u::Link* linkUp   = nullptr;
     const simgrid::s4u::Link* linkDown = nullptr;
-    if(cluster->loopback_bw > 0 || cluster->loopback_lat > 0){
+    if (cluster->loopback_bw > 0 || cluster->loopback_lat > 0) {
       std::string tmp_link = link_id + "_loopback";
       XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link.c_str(), cluster->loopback_bw);
 
       simgrid::kernel::routing::LinkCreationArgs link;
-      link.id        = tmp_link;
+      link.id = tmp_link;
       link.bandwidths.push_back(cluster->loopback_bw);
-      link.latency   = cluster->loopback_lat;
-      link.policy    = simgrid::s4u::Link::SharingPolicy::FATPIPE;
+      link.latency = cluster->loopback_lat;
+      link.policy  = simgrid::s4u::Link::SharingPolicy::FATPIPE;
       sg_platf_new_link(&link);
       linkUp   = simgrid::s4u::Link::by_name_or_null(tmp_link);
       linkDown = simgrid::s4u::Link::by_name_or_null(tmp_link);
@@ -234,18 +234,18 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
       as_cluster->private_links_.insert({as_cluster->node_pos(rankId), {linkUp->get_impl(), linkDown->get_impl()}});
     }
 
-    //add a limiter link (shared link to account for maximal bandwidth of the node)
+    // add a limiter link (shared link to account for maximal bandwidth of the node)
     linkUp   = nullptr;
     linkDown = nullptr;
-    if(cluster->limiter_link > 0){
+    if (cluster->limiter_link > 0) {
       std::string tmp_link = std::string(link_id) + "_limiter";
       XBT_DEBUG("<limiter\tid=\"%s\"\tbw=\"%f\"/>", tmp_link.c_str(), cluster->limiter_link);
 
       simgrid::kernel::routing::LinkCreationArgs link;
-      link.id        = tmp_link;
+      link.id = tmp_link;
       link.bandwidths.push_back(cluster->limiter_link);
       link.latency = 0;
-      link.policy    = simgrid::s4u::Link::SharingPolicy::SHARED;
+      link.policy  = simgrid::s4u::Link::SharingPolicy::SHARED;
       sg_platf_new_link(&link);
       linkDown = simgrid::s4u::Link::by_name_or_null(tmp_link);
       linkUp   = linkDown;
@@ -253,7 +253,7 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
           {current_as->node_pos_with_loopback(rankId), {linkUp->get_impl(), linkDown->get_impl()}});
     }
 
-    //call the cluster function that adds the others links
+    // call the cluster function that adds the others links
     if (cluster->topology == simgrid::kernel::routing::ClusterTopology::FAT_TREE) {
       static_cast<FatTreeZone*>(current_as)->add_processing_node(i);
     } else {
@@ -270,13 +270,13 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
     cluster->router_id = std::string(cluster->prefix) + cluster->id + "_router" + cluster->suffix;
   current_as->router_ = sg_platf_new_router(cluster->router_id, nullptr);
 
-  //Make the backbone
+  // Make the backbone
   if ((cluster->bb_bw > 0) || (cluster->bb_lat > 0)) {
     simgrid::kernel::routing::LinkCreationArgs link;
-    link.id        = std::string(cluster->id)+ "_backbone";
+    link.id = std::string(cluster->id) + "_backbone";
     link.bandwidths.push_back(cluster->bb_bw);
-    link.latency   = cluster->bb_lat;
-    link.policy    = cluster->bb_sharing_policy;
+    link.latency = cluster->bb_lat;
+    link.policy  = cluster->bb_sharing_policy;
 
     XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link.id.c_str(), cluster->bb_bw, cluster->bb_lat);
     sg_platf_new_link(&link);
@@ -307,17 +307,17 @@ void sg_platf_new_cabinet(const simgrid::kernel::routing::CabinetCreationArgs* c
   for (int const& radical : *cabinet->radicals) {
     std::string hostname = cabinet->prefix + std::to_string(radical) + cabinet->suffix;
     simgrid::kernel::routing::HostCreationArgs host;
-    host.pstate           = 0;
-    host.core_amount      = 1;
-    host.id               = hostname;
+    host.pstate      = 0;
+    host.core_amount = 1;
+    host.id          = hostname;
     host.speed_per_pstate.push_back(cabinet->speed);
     sg_platf_new_host(&host);
 
     simgrid::kernel::routing::LinkCreationArgs link;
-    link.policy    = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
-    link.latency   = cabinet->lat;
+    link.policy  = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
+    link.latency = cabinet->lat;
     link.bandwidths.push_back(cabinet->bw);
-    link.id        = "link_" + hostname;
+    link.id = "link_" + hostname;
     sg_platf_new_link(&link);
 
     simgrid::kernel::routing::HostLinkCreationArgs host_link;
@@ -331,7 +331,8 @@ void sg_platf_new_cabinet(const simgrid::kernel::routing::CabinetCreationArgs* c
 
 simgrid::kernel::resource::DiskImpl* sg_platf_new_disk(const simgrid::kernel::routing::DiskCreationArgs* disk)
 {
-  simgrid::kernel::resource::DiskImpl* pimpl = surf_disk_model->create_disk(disk->id, disk->read_bw, disk->write_bw);
+  simgrid::kernel::resource::DiskImpl* pimpl =
+      routing_get_current()->create_disk(disk->id, disk->read_bw, disk->write_bw)->get_impl();
 
   if (disk->properties) {
     pimpl->set_properties(*disk->properties);
@@ -384,7 +385,7 @@ void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor)
   double kill_time  = actor->kill_time;
   bool auto_restart = actor->restart_on_failure;
 
-  std::string actor_name     = actor->args[0];
+  std::string actor_name                 = actor->args[0];
   simgrid::kernel::actor::ActorCode code = factory(std::move(actor->args));
   std::shared_ptr<std::unordered_map<std::string, std::string>> properties(actor->properties);
 
@@ -406,7 +407,7 @@ void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor)
         new_actor->set_auto_restart(auto_restart);
       delete arg;
     });
-  } else {                      // start_time <= SIMIX_get_clock()
+  } else { // start_time <= SIMIX_get_clock()
     XBT_DEBUG("Starting Process %s(%s) right now", arg->name.c_str(), host->get_cname());
 
     try {
@@ -514,27 +515,31 @@ simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::ke
   /* search the routing model */
   simgrid::kernel::routing::NetZoneImpl* new_zone = nullptr;
   simgrid::kernel::resource::NetworkModel* netmodel =
-      current_routing == nullptr ? surf_network_model : current_routing->network_model_;
+      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(current_routing, zone->id, netmodel);
-  } else if (strcasecmp(zone->routing.c_str(),"ClusterDragonfly") == 0) {
-      new_zone = new simgrid::kernel::routing::DragonflyZone(current_routing, zone->id, netmodel);
-  } else if (strcasecmp(zone->routing.c_str(),"ClusterTorus") == 0) {
-      new_zone = new simgrid::kernel::routing::TorusZone(current_routing, zone->id, netmodel);
-  } else if (strcasecmp(zone->routing.c_str(),"ClusterFatTree") == 0) {
-      new_zone = new simgrid::kernel::routing::FatTreeZone(current_routing, zone->id, netmodel);
-  } else if (strcasecmp(zone->routing.c_str(),"Dijkstra") == 0) {
-      new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, netmodel, false);
-  } else if (strcasecmp(zone->routing.c_str(),"DijkstraCache") == 0) {
-      new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, netmodel, true);
-  } else if (strcasecmp(zone->routing.c_str(),"Floyd") == 0) {
-      new_zone = new simgrid::kernel::routing::FloydZone(current_routing, zone->id, netmodel);
-  } else if (strcasecmp(zone->routing.c_str(),"Full") == 0) {
-      new_zone = new simgrid::kernel::routing::FullZone(current_routing, zone->id, netmodel);
-  } else if (strcasecmp(zone->routing.c_str(),"None") == 0) {
-      new_zone = new simgrid::kernel::routing::EmptyZone(current_routing, zone->id, netmodel);
-  } else if (strcasecmp(zone->routing.c_str(),"Vivaldi") == 0) {
-      new_zone = new simgrid::kernel::routing::VivaldiZone(current_routing, zone->id, netmodel);
+    new_zone = new simgrid::kernel::routing::ClusterZone(current_routing, zone->id, netmodel);
+  } else if (strcasecmp(zone->routing.c_str(), "ClusterDragonfly") == 0) {
+    new_zone = new simgrid::kernel::routing::DragonflyZone(current_routing, zone->id, netmodel);
+  } else if (strcasecmp(zone->routing.c_str(), "ClusterTorus") == 0) {
+    new_zone = new simgrid::kernel::routing::TorusZone(current_routing, zone->id, netmodel);
+  } else if (strcasecmp(zone->routing.c_str(), "ClusterFatTree") == 0) {
+    new_zone = new simgrid::kernel::routing::FatTreeZone(current_routing, zone->id, netmodel);
+  } else if (strcasecmp(zone->routing.c_str(), "Dijkstra") == 0) {
+    new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, netmodel, false);
+  } else if (strcasecmp(zone->routing.c_str(), "DijkstraCache") == 0) {
+    new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, netmodel, true);
+  } else if (strcasecmp(zone->routing.c_str(), "Floyd") == 0) {
+    new_zone = new simgrid::kernel::routing::FloydZone(current_routing, zone->id, netmodel);
+  } else if (strcasecmp(zone->routing.c_str(), "Full") == 0) {
+    new_zone = new simgrid::kernel::routing::FullZone(current_routing, zone->id, netmodel);
+  } else if (strcasecmp(zone->routing.c_str(), "None") == 0) {
+    new_zone = new simgrid::kernel::routing::EmptyZone(current_routing, zone->id, netmodel);
+  } else if (strcasecmp(zone->routing.c_str(), "Vivaldi") == 0) {
+    new_zone = new simgrid::kernel::routing::VivaldiZone(current_routing, zone->id, netmodel);
   } else if (strcasecmp(zone->routing.c_str(), "Wifi") == 0) {
     new_zone = new simgrid::kernel::routing::WifiZone(current_routing, zone->id, netmodel);
   } else {
index 66144a7..097f218 100644 (file)
@@ -6,6 +6,7 @@
 #include "simgrid/s4u/Engine.hpp"
 #include "src/include/surf/surf.hpp"
 #include "src/instr/instr_private.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/DiskImpl.hpp"
 #include "src/kernel/resource/profile/FutureEvtSet.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
@@ -22,7 +23,7 @@ extern double NOW;
 
 void surf_presolve()
 {
-  XBT_DEBUG ("Consume all trace events occurring before the starting time.");
+  XBT_DEBUG("Consume all trace events occurring before the starting time.");
   double next_event_date;
   while ((next_event_date = simgrid::kernel::profile::future_evt_set.next_date()) != -1.0) {
     if (next_event_date > NOW)
@@ -37,15 +38,34 @@ void surf_presolve()
     }
   }
 
-  XBT_DEBUG ("Set every models in the right state by updating them to 0.");
-  for (auto const& model : all_existing_models)
+  XBT_DEBUG("Set every models in the right state by updating them to 0.");
+  for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models())
     model->update_actions_state(NOW, 0.0);
 }
 
+/**
+ * @brief Auxiliary function to get next event from a list of models
+ *
+ * @param models list of models to explore (cpu, host, vm) (IN)
+ * @param time_delta delta for the next event (IN/OUT)
+ */
+static void surf_update_next_event(std::vector<simgrid::kernel::resource::Model*> const& models, double& time_delta)
+{
+  for (auto* model : models) {
+    if (not model->next_occurring_event_is_idempotent()) {
+      continue;
+    }
+    double next_event = model->next_occurring_event(NOW);
+    if ((time_delta < 0.0 || next_event < time_delta) && next_event >= 0.0) {
+      time_delta = next_event;
+    }
+  }
+}
+
 double surf_solve(double max_date)
 {
-  double time_delta = -1.0; /* duration */
-  double value = -1.0;
+  double time_delta                             = -1.0; /* duration */
+  double value                                  = -1.0;
   simgrid::kernel::resource::Resource* resource = nullptr;
   simgrid::kernel::profile::Event* event        = nullptr;
 
@@ -57,25 +77,21 @@ double surf_solve(double max_date)
 
   /* Physical models MUST be resolved first */
   XBT_DEBUG("Looking for next event in physical models");
-  double next_event_phy = surf_host_model->next_occurring_event(NOW);
-  if ((time_delta < 0.0 || next_event_phy < time_delta) && next_event_phy >= 0.0) {
-    time_delta = next_event_phy;
-  }
-  if (surf_vm_model != nullptr) {
-    XBT_DEBUG("Looking for next event in virtual models");
-    double next_event_virt = surf_vm_model->next_occurring_event(NOW);
-    if ((time_delta < 0.0 || next_event_virt < time_delta) && next_event_virt >= 0.0)
-      time_delta = next_event_virt;
-  }
+  auto engine = simgrid::kernel::EngineImpl::get_instance();
+  surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::HOST), time_delta);
 
-  for (auto const& model : all_existing_models) {
-    if (model != surf_host_model && model != surf_vm_model && model != surf_network_model &&
-        model != surf_disk_model) {
-      double next_event_model = model->next_occurring_event(NOW);
-      if ((time_delta < 0.0 || next_event_model < time_delta) && next_event_model >= 0.0)
-        time_delta = next_event_model;
-    }
-  }
+  // following the order it was done in HostCLM03Model->next_occurring_event
+  XBT_DEBUG("Looking for next event in CPU models");
+  surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::CPU_PM), time_delta);
+
+  XBT_DEBUG("Looking for next event in network models");
+  surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::NETWORK), time_delta);
+  XBT_DEBUG("Looking for next event in disk models");
+  surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::DISK), time_delta);
+
+  XBT_DEBUG("Looking for next event in virtual models");
+  surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::VM), time_delta);
+  surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::CPU_VM), time_delta);
 
   XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", time_delta);
 
@@ -85,7 +101,11 @@ double surf_solve(double max_date)
     double next_event_date = simgrid::kernel::profile::future_evt_set.next_date();
     XBT_DEBUG("Next TRACE event: %f", next_event_date);
 
-    if (not surf_network_model->next_occurring_event_is_idempotent()) { // NS3, I see you
+    for (auto* model : engine->get_model_list(simgrid::kernel::resource::Model::Type::NETWORK)) {
+      if (model->next_occurring_event_is_idempotent())
+        continue;
+
+      // NS3, I see you
       if (next_event_date != -1.0) {
         time_delta = std::min(next_event_date - NOW, time_delta);
       } else {
@@ -94,7 +114,7 @@ double surf_solve(double max_date)
 
       XBT_DEBUG("Run the NS3 network at most %fs", time_delta);
       // run until min or next flow
-      double model_next_action_end = surf_network_model->next_occurring_event(time_delta);
+      double model_next_action_end = model->next_occurring_event(time_delta);
 
       XBT_DEBUG("Min for network : %f", model_next_action_end);
       if (model_next_action_end >= 0.0)
@@ -115,9 +135,10 @@ double surf_solve(double max_date)
         XBT_DEBUG("This event invalidates the next_occurring_event() computation of models. Next event set to %f",
                   time_delta);
       }
-      // FIXME: I'm too lame to update NOW live, so I change it and restore it so that the real update with surf_min will work
+      // FIXME: I'm too lame to update NOW live, so I change it and restore it so that the real update with surf_min
+      // will work
       double round_start = NOW;
-      NOW = next_event_date;
+      NOW                = next_event_date;
       /* update state of the corresponding resource to the new value. Does not touch lmm.
          It will be modified if needed when updating actions */
       XBT_DEBUG("Calling update_resource_state for resource %s", resource->get_cname());
@@ -126,9 +147,11 @@ double surf_solve(double max_date)
     }
   }
 
-  /* FIXME: Moved this test to here to avoid stopping simulation if there are actions running on cpus and all cpus are with availability = 0.
-   * This may cause an infinite loop if one cpu has a trace with periodicity = 0 and the other a trace with periodicity > 0.
-   * The options are: all traces with same periodicity(0 or >0) or we need to change the way how the events are managed */
+  /* FIXME: Moved this test to here to avoid stopping simulation if there are actions running on cpus and all cpus are
+   * with availability = 0. This may cause an infinite loop if one cpu has a trace with periodicity = 0 and the other a
+   * trace with periodicity > 0.
+   * The options are: all traces with same periodicity(0 or >0) or we need to change the way how the events are managed
+   */
   if (time_delta < 0) {
     XBT_DEBUG("No next event at all. Bail out now.");
     return -1.0;
@@ -140,7 +163,7 @@ double surf_solve(double max_date)
   NOW = NOW + time_delta;
 
   // Inform the models of the date change
-  for (auto const& model : all_existing_models)
+  for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models())
     model->update_actions_state(NOW, time_delta);
 
   simgrid::s4u::Engine::on_time_advance(time_delta);
index 2ff3eb3..ba953e9 100644 (file)
@@ -29,8 +29,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (ke
  * Utils *
  *********/
 
-std::vector<simgrid::kernel::resource::Model*> all_existing_models; /* to destroy models correctly */
-
 simgrid::kernel::profile::FutureEvtSet future_evt_set;
 std::vector<std::string> surf_path;
 
@@ -73,16 +71,19 @@ const std::vector<surf_model_description_t> surf_network_model_description = {
      &surf_network_model_init_NS3},
 };
 
-#if ! HAVE_SMPI
-void surf_network_model_init_SMPI() {
+#if !HAVE_SMPI
+void surf_network_model_init_SMPI()
+{
   xbt_die("Please activate SMPI support in cmake to use the SMPI network model.");
 }
-void surf_network_model_init_IB() {
+void surf_network_model_init_IB()
+{
   xbt_die("Please activate SMPI support in cmake to use the IB network model.");
 }
 #endif
 #if !SIMGRID_HAVE_NS3
-void surf_network_model_init_NS3() {
+void surf_network_model_init_NS3()
+{
   xbt_die("Please activate ns-3 support in cmake and install the dependencies to use the NS3 network model.");
 }
 #endif
@@ -102,8 +103,9 @@ const std::vector<surf_model_description_t> surf_host_model_description = {
 
 const std::vector<surf_model_description_t> surf_optimization_mode_description = {
     {"Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr},
-    {"TI", "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
-           "model for now).",
+    {"TI",
+     "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
+     "model for now).",
      nullptr},
     {"Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr},
 };
@@ -161,7 +163,7 @@ std::ifstream* surf_ifsopen(const std::string& name)
 
 FILE* surf_fopen(const std::string& name, const char* mode)
 {
-  FILE *file = nullptr;
+  FILEfile = nullptr;
 
   if (is_absolute_file_path(name)) /* don't mess with absolute file names */
     return fopen(name.c_str(), mode);
@@ -206,8 +208,7 @@ int find_model_description(const std::vector<surf_model_description_t>& table, c
   return -1;
 }
 
-
-void surf_init(int *argc, char **argv)
+void surf_init(int* argc, char** argv)
 {
   if (xbt_initialized > 0)
     return;
@@ -221,11 +222,8 @@ void surf_exit()
 {
   simgrid::s4u::Engine::shutdown();
 
-  for (auto const& model : all_existing_models)
-    delete model;
-
   tmgr_finalize();
   sg_platf_exit();
 
-  NOW = 0;                      /* Just in case the user plans to restart the simulation afterward */
+  NOW = 0; /* Just in case the user plans to restart the simulation afterward */
 }
index 0efbc75..9e43b7b 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"
@@ -31,17 +33,21 @@ static const char* string_action(simgrid::kernel::resource::Action::State state)
   }
 }
 
-int main(int argc, char **argv)
+int main(int argc, char** argv)
 {
-  surf_init(&argc, argv);       /* Initialize some common structures */
+  surf_init(&argc, argv); /* Initialize some common structures */
   simgrid::config::set_parse("cpu/model:Cas01");
   simgrid::config::set_parse("network/model:CM02");
 
   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
   parse_platform_file(argv[1]);
 
-  XBT_DEBUG("CPU model: %p", surf_cpu_model_pm);
-  XBT_DEBUG("Network model: %p", surf_network_model);
+  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();
+
+  XBT_DEBUG("CPU model: %p", cpu_model_pm);
+  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");
 
@@ -59,16 +65,15 @@ int main(int argc, char **argv)
   XBT_INFO("actionB state: %s", string_action(stateActionB));
   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 {
     XBT_INFO("Next Event : %g", surf_get_clock());
     XBT_DEBUG("\t CPU actions");
 
-    simgrid::kernel::resource::Action::StateSet* action_list = surf_cpu_model_pm->get_failed_action_set();
+    simgrid::kernel::resource::Action::StateSet* action_list = cpu_model_pm->get_failed_action_set();
     while (not action_list->empty()) {
       simgrid::kernel::resource::Action& action = action_list->front();
       XBT_INFO("   CPU Failed action");
@@ -76,7 +81,7 @@ int main(int argc, char **argv)
       action.unref();
     }
 
-    action_list = surf_cpu_model_pm->get_finished_action_set();
+    action_list = cpu_model_pm->get_finished_action_set();
     while (not action_list->empty()) {
       simgrid::kernel::resource::Action& action = action_list->front();
       XBT_INFO("   CPU Done action");
@@ -84,7 +89,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");
@@ -92,16 +97,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() || cpu_model_pm->get_started_action_set()->size()) &&
+           surf_solve(-1.0) >= 0.0);
 
   XBT_DEBUG("Simulation Terminated");
 
index 916767f..27a6e78 100644 (file)
@@ -6,6 +6,9 @@
  * 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/kernel/EngineImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
 #include "src/surf/surf_interface.hpp"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
 
-int main(int argc, char **argv)
+int main(int argc, char** argv)
 {
   int running;
 
-  surf_init(&argc, argv);       /* Initialize some common structures */
+  surf_init(&argc, argv); /* Initialize some common structures */
 
   simgrid::config::set_parse("network/model:CM02");
   simgrid::config::set_parse("cpu/model:Cas01");
@@ -35,17 +38,19 @@ 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 */
+  surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */
   do {
     simgrid::kernel::resource::Action* action = nullptr;
-    running = 0;
+    running                                   = 0;
 
     double now = surf_get_clock();
     XBT_INFO("Next Event : %g", now);
 
-    for (auto const& model : all_existing_models) {
+    for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) {
       if (model->get_started_action_set()->size() != 0) {
         XBT_DEBUG("\t Running that model");
         running = 1;
@@ -60,7 +65,7 @@ int main(int argc, char **argv)
       }
 
       action = model->extract_done_action();
-      while (action != nullptr){
+      while (action != nullptr) {
         XBT_INFO("   * Done Action");
         XBT_DEBUG("\t * Done Action: %p", action);
         action->unref();