Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move globals to EngineImpl
authorBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 9 Mar 2021 13:31:56 +0000 (14:31 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 9 Mar 2021 14:17:37 +0000 (15:17 +0100)
A step forwards encapsulation.
Still not good for ptask model and its particularities.

27 files changed:
doc/doxygen/inside_extending.doc
doc/doxygen/module-surf.doc
include/simgrid/kernel/resource/Model.hpp
include/simgrid/kernel/routing/NetZoneImpl.hpp
src/kernel/EngineImpl.cpp
src/kernel/EngineImpl.hpp
src/kernel/routing/NetZoneImpl.cpp
src/plugins/vm/VirtualMachineImpl.cpp
src/plugins/vm/s4u_VirtualMachine.cpp
src/simdag/sd_global.cpp
src/simix/smx_global.cpp
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_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_usage2/surf_usage2.cpp

index a8f97d8..fefe0a2 100644 (file)
@@ -36,7 +36,6 @@ For instance, if you want to add a new cup model called `Plop`, create two files
 cpu_plop.hpp and cpu_plop_cpp which contains classes CpuPlopModel, CpuPlop and
 CpuPlopAction implementing respectively the interfaces CpuModel, Cpu and
 CpuAction. You also need to define an initializing function like this:
-FIXME[donassolo]: update doc
 
 ~~~~
 void surf_cpu_model_init_plop()
index fdb4e47..9dc285e 100644 (file)
@@ -43,7 +43,6 @@
        - the CPU resource,
        - the timer resource.
 
-    FIXME[donassolo]: fix doc
     The implementation of these resources depends on the platform
     models you choose.  You can select your model by calling
     #surf_host_model_init_current_default() (which will give you a
index fac93ac..72617af 100644 (file)
@@ -151,15 +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;
-/** @ingroup SURF_models
- *  @brief Map of initialized models by category
- */
-XBT_PUBLIC_DATA
-std::unordered_map<simgrid::kernel::resource::Model::Type, std::vector<simgrid::kernel::resource::Model*>>
-    models_by_type;
-
 #endif
index ffbf67b..b550fc4 100644 (file)
@@ -115,7 +115,6 @@ public:
   /** @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 */
-  // FIXME[donassolo]: why HostModel isn't in resource namespace?
   simgrid::surf::HostModel* get_host_model() const { return host_model_; }
 
   const s4u::NetZone* get_iface() const { return &piface_; }
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 11f4c0d..6ae49f1 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/resource/DiskImpl.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
@@ -26,18 +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_);
-  if (models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].size() > 0) {
-    cpu_model_vm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
-        models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM][0]);
-  }
+  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*>(
-      models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM][0]);
+      simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::CPU_PM));
   disk_model_ = static_cast<simgrid::kernel::resource::DiskModel*>(
-      models_by_type[simgrid::kernel::resource::Model::Type::DISK][0]);
-  // FIXME[donassolo]: we probably need some validation of the coherence among
-  // the different models in each netZone
-  host_model_ = static_cast<simgrid::surf::HostModel*>(models_by_type[simgrid::kernel::resource::Model::Type::HOST][0]);
+      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());
 }
 
index 4c7d7b1..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");
 
 void surf_vm_model_init_HL13()
 {
-  /* FIXME[donassolo]: this smells bad, but works
-   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
-   * We need a manager for these models */
-  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 {
@@ -103,8 +103,6 @@ static void remove_active_activity(kernel::activity::ActivityImpl const& act)
 
 VMModel::VMModel()
 {
-  all_existing_models.push_back(this);
-  models_by_type[simgrid::kernel::resource::Model::Type::VM].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);
index 3647064..3b412c8 100644 (file)
@@ -42,7 +42,6 @@ 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));
 
-  // FIXME[donassolo]: shoud this be done at the Impl class???
   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 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 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 0d56ffe..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"
@@ -47,10 +48,12 @@ void surf_cpu_model_init_Cas01()
   else
     algo = simgrid::kernel::resource::Model::UpdateAlgo::FULL;
 
-  auto cpu_model_pm = new simgrid::kernel::resource::CpuCas01Model(algo);
-  models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(cpu_model_pm);
-  auto cpu_model_vm = new simgrid::kernel::resource::CpuCas01Model(algo);
-  models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].push_back(cpu_model_vm);
+  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 {
@@ -59,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()) {
@@ -72,9 +73,7 @@ CpuCas01Model::CpuCas01Model(Model::UpdateAlgo algo) : CpuModel(algo)
   set_maxmin_system(new lmm::System(select));
 }
 
-CpuCas01Model::~CpuCas01Model()
-{
-}
+CpuCas01Model::~CpuCas01Model() {}
 
 Cpu* CpuCas01Model::create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
 {
index 840c9a8..b07f84f 100644 (file)
@@ -54,7 +54,6 @@ Cpu::Cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
 {
   speed_.scale = 1;
   speed_.peak     = speed_per_pstate_.front();
-  // FIXME[donassolo]: don't set here.. everytime I take half an hour to discover where it comes
   host->pimpl_cpu = this;
 }
 
index f31b334..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"
@@ -269,20 +270,19 @@ int CpuTiProfile::binary_search(const std::vector<double>& array, double a)
 
 void CpuTiModel::create_pm_vm_models()
 {
-  auto cpu_model_pm = new CpuTiModel();
-  models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(cpu_model_pm);
-  auto cpu_model_vm = new CpuTiModel();
-  models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].push_back(cpu_model_vm);
+  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()
-{
-}
+CpuTiModel::~CpuTiModel() {}
 
 Cpu* CpuTiModel::create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
 {
index c1e4bde..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,10 +20,9 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_disk);
 
 void surf_disk_model_init_default()
 {
-  /* FIXME[donassolo]: this smells bad, but works
-   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
-   * We need a manager for these models */
-  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 {
@@ -31,8 +31,6 @@ namespace resource {
 
 DiskS19Model::DiskS19Model()
 {
-  all_existing_models.push_back(this);
-  models_by_type[simgrid::kernel::resource::Model::Type::DISK].push_back(this);
 }
 
 DiskImpl* DiskS19Model::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
index db3a995..c9bb4c5 100644 (file)
@@ -6,35 +6,32 @@
 #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()
 {
-  /* FIXME[donassolo]: this smells bad, but works
-   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
-   * We need a manager for these models */
-  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()
 {
-  /* FIXME[donassolo]: this smells bad, but works
-   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
-   * We need a manager for these models */
-  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);
-  models_by_type[simgrid::kernel::resource::Model::Type::HOST].push_back(this);
 }
 
 double HostCLM03Model::next_occurring_event(double now)
index 5793cf1..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"
@@ -36,10 +37,9 @@ double sg_weight_S_parameter = 0.0; /* default value; can be set by model or fro
 /*  } */
 void surf_network_model_init_LegrandVelho()
 {
-  /* FIXME[donassolo]: this smells bad, but works
-   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
-   * We need a manager for these models */
-  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);
@@ -63,10 +63,9 @@ void surf_network_model_init_CM02()
   simgrid::config::set_default<double>("network/bandwidth-factor", 1.0);
   simgrid::config::set_default<double>("network/weight-S", 0.0);
 
-  /* FIXME[donassolo]: this smells bad, but works
-   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
-   * We need a manager for these models */
-  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 {
@@ -77,9 +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);
-  models_by_type[simgrid::kernel::resource::Model::Type::NETWORK].push_back(this);
-
   std::string optim = config::get_value<std::string>("network/optim");
   bool select       = config::get_value<bool>("network/maxmin-selective-update");
 
index 59e4c81..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,10 +15,9 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
  *********/
 void surf_network_model_init_Constant()
 {
-  /* FIXME[donassolo]: this smells bad, but works
-   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
-   * We need a manager for these models */
-  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 {
@@ -26,8 +26,6 @@ namespace resource {
 
 NetworkConstantModel::NetworkConstantModel() : NetworkModel(Model::UpdateAlgo::FULL)
 {
-  all_existing_models.push_back(this);
-  models_by_type[simgrid::kernel::resource::Model::Type::NETWORK].push_back(this);
 }
 
 LinkImpl* NetworkConstantModel::create_link(const std::string& name, const std::vector<double>& /*bandwidth*/,
index 1fda88f..eedd459 100644 (file)
@@ -6,6 +6,7 @@
 #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"
@@ -68,10 +69,10 @@ static void IB_action_init_callback(simgrid::kernel::resource::NetworkAction& ac
 /*  } */
 void surf_network_model_init_IB()
 {
-  /* FIXME[donassolo]: this smells bad, but works
-   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
-   * We need a manager for these models */
-  new simgrid::kernel::resource::NetworkIBModel();
+  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);
+
   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);
@@ -84,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 80ebc3b..8ba3f2e 100644 (file)
@@ -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"
@@ -258,10 +259,9 @@ static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoin
  *********/
 void surf_network_model_init_NS3()
 {
-  /* FIXME[donassolo]: this smells bad, but works
-   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
-   * We need a manager for these models */
-  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,9 +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);
-  models_by_type[simgrid::kernel::resource::Model::Type::NETWORK].push_back(this);
-
   NetPointNs3::EXTENSION_ID = routing::NetPoint::extension_create<NetPointNs3>();
 
   ns3::Config::SetDefault("ns3::TcpSocket::SegmentSize", ns3::UintegerValue(1000));
index 7410aa2..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,10 +33,9 @@ std::vector<s_smpi_factor_t> smpi_lat_factor;
 /*  } */
 void surf_network_model_init_SMPI()
 {
-  /* FIXME[donassolo]: this smells bad, but works
-   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
-   * We need a manager for these models */
-  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);
 }
@@ -45,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 570e3aa..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"
@@ -20,9 +21,9 @@ void surf_host_model_init_ptask_L07()
 {
   XBT_CINFO(xbt_cfg, "Switching to the L07 model to handle parallel tasks.");
 
-  auto host_model = new simgrid::surf::HostL07Model();
-  all_existing_models.push_back(host_model);
-  models_by_type[simgrid::kernel::resource::Model::Type::HOST].push_back(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 {
@@ -32,10 +33,13 @@ HostL07Model::HostL07Model() : HostModel()
 {
   auto* maxmin_system = new simgrid::kernel::lmm::FairBottleneck(true /* selective update */);
   set_maxmin_system(maxmin_system);
-  network_model_ = std::make_unique<NetworkL07Model>(this, maxmin_system);
-  models_by_type[simgrid::kernel::resource::Model::Type::NETWORK].push_back(network_model_.get());
-  cpu_model_pm_     = std::make_unique<CpuL07Model>(this, maxmin_system);
-  models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(cpu_model_pm_.get());
+
+  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() {}
index adcc812..fe5fe36 100644 (file)
@@ -46,8 +46,8 @@ public:
                                                 const double* bytes_amount, double rate) override;
 
 private:
-  std::unique_ptr<NetworkL07Model> network_model_;
-  std::unique_ptr<CpuL07Model> cpu_model_pm_;
+  std::unique_ptr<NetworkL07Model> net_model_;
+  std::unique_ptr<CpuL07Model> cpu_model_;
 };
 
 class CpuL07Model : public kernel::resource::CpuModel {
index 6d9188d..867b0d2 100644 (file)
@@ -476,8 +476,6 @@ static void surf_config_models_setup()
   surf_host_model_description[host_id].model_init_preparse();
 
   XBT_DEBUG("Call vm_model_init");
-  // FIXME[donassolo]: maybe remove it, find a way to create the object and leave the
-  // dependency with surf_cpu_model_vm explicity
   surf_vm_model_init_HL13();
 
   XBT_DEBUG("Call disk_model_init");
@@ -518,7 +516,8 @@ simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::ke
   simgrid::kernel::routing::NetZoneImpl* new_zone = nullptr;
   simgrid::kernel::resource::NetworkModel* netmodel =
       current_routing == nullptr ? static_cast<simgrid::kernel::resource::NetworkModel*>(
-                                       models_by_type[simgrid::kernel::resource::Model::Type::NETWORK][0])
+                                       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) {
index a47a841..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"
@@ -38,7 +39,7 @@ void surf_presolve()
   }
 
   XBT_DEBUG("Set every models in the right state by updating them to 0.");
-  for (auto const& model : all_existing_models)
+  for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models())
     model->update_actions_state(NOW, 0.0);
 }
 
@@ -76,19 +77,21 @@ double surf_solve(double max_date)
 
   /* Physical models MUST be resolved first */
   XBT_DEBUG("Looking for next event in physical models");
-  surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::HOST], time_delta);
+  auto engine = simgrid::kernel::EngineImpl::get_instance();
+  surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::HOST), time_delta);
 
   // following the order it was done in HostCLM03Model->next_occurring_event
   XBT_DEBUG("Looking for next event in CPU models");
-  surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM], time_delta);
+  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(models_by_type[simgrid::kernel::resource::Model::Type::NETWORK], time_delta);
+  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(models_by_type[simgrid::kernel::resource::Model::Type::DISK], time_delta);
+  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(models_by_type[simgrid::kernel::resource::Model::Type::VM], time_delta);
-  surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM], time_delta);
+  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);
 
@@ -98,7 +101,7 @@ 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);
 
-    for (auto* model : models_by_type[simgrid::kernel::resource::Model::Type::NETWORK]) {
+    for (auto* model : engine->get_model_list(simgrid::kernel::resource::Model::Type::NETWORK)) {
       if (model->next_occurring_event_is_idempotent())
         continue;
 
@@ -160,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 5a9fd87..ba953e9 100644 (file)
@@ -29,10 +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 */
-std::unordered_map<simgrid::kernel::resource::Model::Type, std::vector<simgrid::kernel::resource::Model*>>
-    models_by_type;
-
 simgrid::kernel::profile::FutureEvtSet future_evt_set;
 std::vector<std::string> surf_path;
 
@@ -226,9 +222,6 @@ void surf_exit()
 {
   simgrid::s4u::Engine::shutdown();
 
-  for (auto const& model : all_existing_models)
-    delete model;
-
   tmgr_finalize();
   sg_platf_exit();
 
index 4984d79..27a6e78 100644 (file)
@@ -8,6 +8,7 @@
 #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"
@@ -49,7 +50,7 @@ int main(int argc, char** argv)
     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;