Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
say bye to simgrid::surf namespace
[simgrid.git] / src / surf / surf_c_bindings.cpp
index c5b9139..59fd67e 100644 (file)
@@ -3,13 +3,14 @@
 /* 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/Engine.hpp"
-#include "src/include/surf/surf.hpp"
+#include <simgrid/s4u/Engine.hpp>
+
 #include "src/instr/instr_private.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/DiskImpl.hpp"
+#include "src/kernel/resource/VirtualMachineImpl.hpp"
 #include "src/kernel/resource/profile/FutureEvtSet.hpp"
-#include "src/plugins/vm/VirtualMachineImpl.hpp"
+#include "surf/surf.hpp"
 
 #include <algorithm>
 
@@ -29,10 +30,9 @@ void surf_presolve()
     if (next_event_date > NOW)
       break;
 
-    simgrid::kernel::profile::Event* event;
     double value                                  = -1.0;
     simgrid::kernel::resource::Resource* resource = nullptr;
-    while ((event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource))) {
+    while (auto* event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource)) {
       if (value >= 0)
         resource->apply_event(event, value);
     }
@@ -43,31 +43,11 @@ void surf_presolve()
     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;
   simgrid::kernel::resource::Resource* resource = nullptr;
-  simgrid::kernel::profile::Event* event        = nullptr;
 
   if (max_date != -1.0) {
     xbt_assert(max_date >= NOW, "You asked to simulate up to %f, but that's in the past already", max_date);
@@ -75,23 +55,17 @@ double surf_solve(double max_date)
     time_delta = max_date - NOW;
   }
 
-  /* Physical models MUST be resolved first */
-  XBT_DEBUG("Looking for next event in physical models");
+  XBT_DEBUG("Looking for next event in all models");
   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(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);
+  for (auto model : engine->get_all_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;
+    }
+  }
 
   XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", time_delta);
 
@@ -101,7 +75,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 : engine->get_model_list(simgrid::kernel::resource::Model::Type::NETWORK)) {
+    for (auto model : engine->get_all_models()) {
       /* Skip all idempotent models, they were already treated above
        * NS3 is the one to handled here */
       if (model->next_occurring_event_is_idempotent())
@@ -130,7 +104,7 @@ double surf_solve(double max_date)
 
     XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)", time_delta, NOW, next_event_date);
 
-    while ((event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource))) {
+    while (auto* event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource)) {
       if (resource->is_used() || (watched_hosts().find(resource->get_cname()) != watched_hosts().end())) {
         time_delta = next_event_date - NOW;
         XBT_DEBUG("This event invalidates the next_occurring_event() computation of models. Next event set to %f",