Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move surf_presolve, surf_solve, and surf_get_clock to EngineImpl
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Tue, 9 Nov 2021 08:45:43 +0000 (09:45 +0100)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Tue, 9 Nov 2021 08:45:43 +0000 (09:45 +0100)
27 files changed:
MANIFEST.in
doc/doxygen/module-surf.doc
examples/c/platform-failures/platform-failures.tesh
src/include/surf/surf.hpp [deleted file]
src/kernel/EngineImpl.cpp
src/kernel/EngineImpl.hpp
src/kernel/resource/Action.cpp
src/kernel/resource/VirtualMachineImpl.cpp
src/s4u/s4u_Engine.cpp
src/simdag/sd_global.cpp
src/simdag/sd_task.cpp
src/simdag/simdag_private.hpp
src/surf/LinkImpl.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_ti.cpp
src/surf/host_clm03.cpp
src/surf/network_cm02.cpp
src/surf/network_ns3.cpp
src/surf/ptask_L07.hpp
src/surf/sg_platf.cpp
src/surf/surf_c_bindings.cpp [deleted file]
src/surf/surf_interface.cpp
src/surf/xml/platf.hpp
src/surf/xml/surfxml_parseplatf.cpp
teshsuite/surf/surf_usage/surf_usage.cpp
teshsuite/surf/surf_usage2/surf_usage2.cpp
tools/cmake/DefinePackages.cmake

index 0b79ccc..20a3614 100644 (file)
@@ -2193,7 +2193,6 @@ include src/include/catch.hpp
 include src/include/mc/datatypes.h
 include src/include/mc/mc.h
 include src/include/simgrid/sg_config.hpp
-include src/include/surf/surf.hpp
 include src/include/xbt/coverage.h
 include src/include/xbt/mmalloc.h
 include src/include/xbt/parmap.hpp
@@ -2665,7 +2664,6 @@ include src/surf/ns3/ns3_simulator.hpp
 include src/surf/ptask_L07.cpp
 include src/surf/ptask_L07.hpp
 include src/surf/sg_platf.cpp
-include src/surf/surf_c_bindings.cpp
 include src/surf/surf_interface.cpp
 include src/surf/surf_interface.hpp
 include src/surf/surf_private.hpp
index 5482451..1d4aad0 100644 (file)
     a new action that represents the task you have just created.
 
     To execute the actions created with @a execute(), @a communicate() or @a execute_parallel_task(), call
-    surf_solve(). The function surf_solve() is where the simulation takes place. It returns the
+    EngineImpl::solve(). This function is where the simulation takes place. It returns the
     time elapsed to execute the actions. You can know what actions have changed their state thanks
     to the states sets. For example, if your want to know what actions are finished,
     extract them from @a surf_host_model->common_public->states.done_action_set.
-    Depending on these results, you can schedule other tasks and call surf_solve() again.
+    Depending on these results, you can schedule other tasks and call solve() again.
 
     Have a look at the implementation of @ref MSG_API "MSG" and @ref SD_API "Simdag" to see how these module
     interact with SURF. But if you want to create a new API on top of SURF,
index 30cefae..b8be3a4 100644 (file)
@@ -211,7 +211,7 @@ $ ${bindir:=.}/c-platform-failures --log=xbt_cfg.thres:critical --log=no_loc ${p
 > [ 43.774742] (0:maestro@) Simulation time 43.7747
 
 p NOT testing the mixture of failures and CpuTI:
-p This test leads to a deadlock because of a bug somewhere in surf_solve.
+p This test leads to a deadlock because of a bug somewhere in EngineImpl::solve.
 p We should debug this instead of ignoring the issue, but it's utterly
 p   complex with such an integration test. One day, we will setup a set of
 p   unit tests for the surf solver, and such issues will be addressable again.
diff --git a/src/include/surf/surf.hpp b/src/include/surf/surf.hpp
deleted file mode 100644 (file)
index 802e69e..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved.          */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#ifndef SURF_SURF_H
-#define SURF_SURF_H
-
-#include "simgrid/forward.h"
-
-/*** SURF Globals **************************/
-
-/** @ingroup SURF_simulation
- *  @brief Finish simulation initialization
- *
- *  This function must be called before the first call to surf_solve()
- */
-XBT_PUBLIC void surf_presolve();
-
-/** @ingroup SURF_simulation
- *  @brief Performs a part of the simulation
- *  @param max_date Maximum date to update the simulation to, or -1
- *  @return the elapsed time, or -1.0 if no event could be executed
- *
- *  This function execute all possible events, update the action states  and returns the time elapsed.
- *  When you call execute or communicate on a model, the corresponding actions are not executed immediately but only
- *  when you call surf_solve.
- *  Note that the returned elapsed time can be zero.
- */
-XBT_PUBLIC double surf_solve(double max_date);
-
-/** @ingroup SURF_simulation
- *  @brief Return the current time
- *
- *  Return the current time in millisecond.
- */
-XBT_PUBLIC double surf_get_clock();
-
-/* surf parse file related (public because called from a test suite) */
-XBT_PUBLIC void parse_platform_file(const std::string& file);
-
-#endif
index 0d0e039..b449281 100644 (file)
@@ -18,7 +18,6 @@
 #include "src/smpi/include/smpi_actor.hpp"
 #include "src/surf/network_interface.hpp"
 #include "src/surf/xml/platf.hpp"
-#include "surf/surf.hpp"          //surf_presolve() and surf_solve()
 #include "xbt/xbt_modinter.h"     /* whether initialization was already done */
 
 #include <boost/algorithm/string/predicate.hpp>
 #include "src/mc/remote/AppSide.hpp"
 #endif
 
+double NOW = 0;
+
 XBT_LOG_NEW_DEFAULT_CATEGORY(ker_engine, "Logging specific to Engine (kernel)");
+
 namespace simgrid {
 namespace kernel {
 EngineImpl* EngineImpl::instance_ = nullptr; /* That singleton is awful too. */
@@ -236,7 +238,7 @@ void EngineImpl::initialize(int* argc, char** argv)
 
   /* register a function to be called by SURF after the environment creation */
   sg_platf_init();
-  s4u::Engine::on_platform_created.connect(surf_presolve);
+  s4u::Engine::on_platform_created.connect([this]() { this->presolve(); });
 
   if (config::get_value<bool>("debug/clean-atexit"))
     atexit(shutdown);
@@ -547,6 +549,129 @@ void EngineImpl::display_all_actor_status() const
   }
 }
 
+void EngineImpl::presolve()
+{
+  XBT_DEBUG("Consume all trace events occurring before the starting time.");
+  double next_event_date;
+  while ((next_event_date = profile::future_evt_set.next_date()) != -1.0) {
+    if (next_event_date > NOW)
+      break;
+
+    double value                 = -1.0;
+    resource::Resource* resource = nullptr;
+    while (auto* event = profile::future_evt_set.pop_leq(next_event_date, &value, &resource)) {
+      if (value >= 0)
+        resource->apply_event(event, value);
+    }
+  }
+
+  XBT_DEBUG("Set every models in the right state by updating them to 0.");
+  for (auto const& model : models_)
+    model->update_actions_state(NOW, 0.0);
+}
+
+double EngineImpl::solve(double max_date)
+{
+  double time_delta            = -1.0; /* duration */
+  double value                 = -1.0;
+  resource::Resource* resource = 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);
+
+    time_delta = max_date - NOW;
+  }
+
+  XBT_DEBUG("Looking for next event in all models");
+  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;
+    }
+  }
+
+  XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", time_delta);
+
+  XBT_DEBUG("Looking for next trace event");
+
+  while (true) { // Handle next occurring events until none remains
+    double next_event_date = profile::future_evt_set.next_date();
+    XBT_DEBUG("Next TRACE event: %f", next_event_date);
+
+    for (auto model : models_) {
+      /* Skip all idempotent models, they were already treated above
+       * NS3 is the one to handled here */
+      if (model->next_occurring_event_is_idempotent())
+        continue;
+
+      if (next_event_date != -1.0) {
+        time_delta = std::min(next_event_date - NOW, time_delta);
+      } else {
+        time_delta = std::max(next_event_date - NOW, time_delta); // Get the positive component
+      }
+
+      XBT_DEBUG("Run the NS3 network at most %fs", time_delta);
+      // run until min or next flow
+      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)
+        time_delta = model_next_action_end;
+    }
+
+    if (next_event_date < 0.0 || (next_event_date > NOW + time_delta)) {
+      // next event may have already occurred or will after the next resource change, then bail out
+      XBT_DEBUG("no next usable TRACE event. Stop searching for it");
+      break;
+    }
+
+    XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)", time_delta, NOW, next_event_date);
+
+    while (auto* event = 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",
+                  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
+      double round_start = NOW;
+      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());
+      resource->apply_event(event, value);
+      NOW = round_start;
+    }
+  }
+
+  /* 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;
+  }
+
+  XBT_DEBUG("Duration set to %f", time_delta);
+
+  // Bump the time: jump into the future
+  NOW = NOW + time_delta;
+
+  // Inform the models of the date change
+  for (auto const& model : models_)
+    model->update_actions_state(NOW, time_delta);
+
+  s4u::Engine::on_time_advance(time_delta);
+
+  return time_delta;
+}
+
 void EngineImpl::run()
 {
   if (MC_record_replay_is_active()) {
@@ -661,8 +786,8 @@ void EngineImpl::run()
 
     time = timer::Timer::next();
     if (time > -1.0 || not actor_list_.empty()) {
-      XBT_DEBUG("Calling surf_solve");
-      time = surf_solve(time);
+      XBT_DEBUG("Calling solve");
+      time = solve(time);
       XBT_DEBUG("Moving time ahead : %g", time);
     }
 
@@ -705,6 +830,11 @@ void EngineImpl::run()
 
   simgrid::s4u::Engine::on_simulation_end();
 }
+
+double EngineImpl::get_clock()
+{
+  return NOW;
+}
 } // namespace kernel
 } // namespace simgrid
 
index f8f921c..451a8ec 100644 (file)
@@ -187,8 +187,26 @@ public:
   void display_all_actor_status() const;
   void run_all_actors();
 
+  /*  @brief Finish simulation initialization
+   *  This function must be called before the first call to solve()
+   */
+  void presolve();
+  /** @brief Performs a part of the simulation
+   *  @param max_date Maximum date to update the simulation to, or -1
+   *  @return the elapsed time, or -1.0 if no event could be executed
+   *
+   *  This function execute all possible events, update the action states  and returns the time elapsed.
+   *  When you call execute or communicate on a model, the corresponding actions are not executed immediately but only
+   *  when you call solve().
+   *  Note that the returned elapsed time can be zero.
+   */
+  double solve(double max_date);
+
   /** @brief Run the main simulation loop. */
   void run();
+
+  /** @brief Return the current time in milliseconds. */
+  static double get_clock();
 };
 
 } // namespace kernel
index 06ef145..0062953 100644 (file)
@@ -5,9 +5,9 @@
 
 #include "simgrid/kernel/resource/Action.hpp"
 #include "simgrid/kernel/resource/Model.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/lmm/maxmin.hpp"
 #include "src/surf/surf_interface.hpp"
-#include "surf/surf.hpp"
 
 XBT_LOG_NEW_CATEGORY(kernel, "SimGrid internals");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_resource, kernel, "Resources, modeling the platform performance");
@@ -19,7 +19,7 @@ namespace resource {
 Action::Action(Model* model, double cost, bool failed) : Action(model, cost, failed, nullptr) {}
 
 Action::Action(Model* model, double cost, bool failed, lmm::Variable* var)
-    : remains_(cost), start_time_(surf_get_clock()), cost_(cost), model_(model), variable_(var)
+    : remains_(cost), start_time_(EngineImpl::get_clock()), cost_(cost), model_(model), variable_(var)
 {
   if (failed)
     state_set_ = model_->get_failed_action_set();
@@ -44,7 +44,7 @@ Action::~Action()
 
 void Action::finish(Action::State state)
 {
-  finish_time_ = surf_get_clock();
+  finish_time_ = EngineImpl::get_clock();
   set_remains(0);
   set_state(state);
 }
@@ -107,7 +107,7 @@ void Action::set_bound(double bound)
   if (variable_)
     model_->get_maxmin_system()->update_variable_bound(variable_, bound);
 
-  if (model_->is_update_lazy() && get_last_update() != surf_get_clock())
+  if (model_->is_update_lazy() && get_last_update() != EngineImpl::get_clock())
     model_->get_action_heap().remove(this);
   XBT_OUT();
 }
@@ -163,7 +163,7 @@ void Action::suspend()
       model_->get_action_heap().remove(this);
       if (state_set_ == model_->get_started_action_set() && sharing_penalty_ > 0) {
         // If we have a lazy model, we need to update the remaining value accordingly
-        update_remains_lazy(surf_get_clock());
+        update_remains_lazy(EngineImpl::get_clock());
       }
     }
     suspended_ = SuspendStates::SUSPENDED;
@@ -188,7 +188,7 @@ double Action::get_remains()
   XBT_IN("(%p)", this);
   /* update remains before returning it */
   if (model_->is_update_lazy()) /* update remains before return it */
-    update_remains_lazy(surf_get_clock());
+    update_remains_lazy(EngineImpl::get_clock());
   XBT_OUT();
   return remains_;
 }
@@ -206,7 +206,7 @@ void Action::update_remains(double delta)
 
 void Action::set_last_update()
 {
-  last_update_ = surf_get_clock();
+  last_update_ = EngineImpl::get_clock();
 }
 
 double ActionHeap::top_date() const
index d0162ce..054ac5c 100644 (file)
@@ -160,7 +160,7 @@ double VMModel::next_occurring_event(double now)
     lmm::System* vcpu_system = cpu->get_model()->get_maxmin_system();
     vcpu_system->update_constraint_bound(cpu->get_constraint(), virt_overhead * solved_value);
   }
-  /* actual next occurring event is determined by VM CPU model at surf_solve */
+  /* actual next occurring event is determined by VM CPU model at EngineImpl::solve */
   return -1.0;
 }
 
index c4c3b0c..f4531df 100644 (file)
@@ -13,7 +13,6 @@
 #include "src/instr/instr_private.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/mc/mc_replay.hpp"
-#include "surf/surf.hpp"
 
 #include <algorithm>
 #include <string>
@@ -86,7 +85,7 @@ double Engine::get_clock()
   if (MC_is_active() || MC_record_replay_is_active()) {
     return MC_process_clock_get(kernel::actor::ActorImpl::self());
   } else {
-    return surf_get_clock();
+    return kernel::EngineImpl::get_clock();
   }
 }
 
index fa386cd..8c7b9f7 100644 (file)
@@ -24,7 +24,8 @@ namespace sd {
 std::set<SD_task_t>* simulate(double how_long)
 {
   XBT_VERB("Run simulation for %f seconds", how_long);
-
+  auto engine = sd_global->engine_->get_impl();
+  simgrid::kernel::EngineImpl::get_instance();
   sd_global->watch_point_reached = false;
   sd_global->return_set.clear();
 
@@ -39,13 +40,13 @@ std::set<SD_task_t>* simulate(double how_long)
          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);
-    XBT_DEBUG("surf_solve() returns %f", elapsed_time);
+    elapsed_time = engine->solve(how_long > 0 ? simgrid_get_clock() + how_long - total_time : -1.0);
+    XBT_DEBUG("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 : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) {
+    for (auto const& model : engine->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());
@@ -114,7 +115,7 @@ std::set<SD_task_t>* simulate(double how_long)
 
   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());
+  XBT_DEBUG("current time = %f", simgrid_get_clock());
 
   return &sd_global->return_set;
 }
@@ -192,7 +193,7 @@ void SD_create_environment(const char* platform_file)
   jedule_sd_init();
 #endif
   XBT_VERB("Starting simulation...");
-  surf_presolve(); /* Takes traces into account */
+  sd_global->engine_->get_impl()->presolve(); /* Takes traces into account */
 }
 
 /**
@@ -224,7 +225,7 @@ 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()
 {
-  return surf_get_clock();
+  return simgrid_get_clock();
 }
 
 /**
index a00b21f..4d88fa1 100644 (file)
@@ -296,7 +296,7 @@ void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state)
       jedule_log_sd_event(task);
 #endif
     } else
-      task->finish_time = surf_get_clock();
+      task->finish_time = simgrid_get_clock();
     task->surf_action->unref();
     task->surf_action = nullptr;
     task->allocation->clear();
index bb06103..8fcae45 100644 (file)
@@ -5,7 +5,6 @@
 
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/simdag.h"
-#include "surf/surf.hpp"
 #include <set>
 #include <string>
 #include <vector>
index 7724650..a5a34ae 100644 (file)
@@ -3,9 +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 <simgrid/s4u/Engine.hpp>
+
+#include "src/kernel/EngineImpl.hpp"
 #include "src/surf/LinkImpl.hpp"
-#include "simgrid/s4u/Engine.hpp"
-#include "surf/surf.hpp"
 
 #include <numeric>
 
@@ -83,7 +84,7 @@ void LinkImpl::turn_off()
     s4u::Link::on_state_change(piface_);
 
     const kernel::lmm::Element* elem = nullptr;
-    double now                       = surf_get_clock();
+    double now                       = EngineImpl::get_clock();
     while (const auto* var = get_constraint()->get_variable(&elem)) {
       Action* action = var->get_id();
       if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED) {
index 62c30c4..42fd5c1 100644 (file)
@@ -12,7 +12,6 @@
 #include "src/surf/cpu_cas01.hpp"
 #include "src/surf/cpu_ti.hpp"
 #include "src/surf/surf_interface.hpp"
-#include "surf/surf.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(cpu_cas, res_cpu, "CPU resource, CAS01 model (used by default)");
 
@@ -115,7 +114,7 @@ void CpuCas01::apply_event(profile::Event* event, double value)
       }
     } else {
       const lmm::Element* elem = nullptr;
-      double date              = surf_get_clock();
+      double date              = EngineImpl::get_clock();
 
       get_iface()->turn_off();
 
index 53103d0..e484442 100644 (file)
@@ -10,7 +10,6 @@
 #include "src/kernel/resource/profile/Event.hpp"
 #include "src/kernel/resource/profile/Profile.hpp"
 #include "src/surf/surf_interface.hpp"
-#include "surf/surf.hpp"
 
 #include <algorithm>
 #include <memory>
@@ -307,7 +306,7 @@ void CpuTiModel::update_actions_state(double now, double /*delta*/)
     XBT_DEBUG("Action %p: finish", action);
     action->finish(Action::State::FINISHED);
     /* update remaining amount of all actions */
-    action->cpu_->update_remaining_amount(surf_get_clock());
+    action->cpu_->update_remaining_amount(EngineImpl::get_clock());
   }
 }
 
@@ -350,7 +349,7 @@ void CpuTi::apply_event(kernel::profile::Event* event, double value)
     XBT_DEBUG("Speed changed in trace! New fixed value: %f", value);
 
     /* update remaining of actions and put in modified cpu list */
-    update_remaining_amount(surf_get_clock());
+    update_remaining_amount(EngineImpl::get_clock());
 
     set_modified(true);
 
@@ -368,7 +367,7 @@ void CpuTi::apply_event(kernel::profile::Event* event, double value)
       }
     } else {
       get_iface()->turn_off();
-      double date = surf_get_clock();
+      double date = EngineImpl::get_clock();
 
       /* put all action running on cpu to failed */
       for (CpuTiAction& action : action_set_) {
@@ -454,7 +453,7 @@ bool CpuTi::is_used() const
 
 double CpuTi::get_speed_ratio()
 {
-  speed_.scale = speed_integrated_trace_->get_power_scale(surf_get_clock());
+  speed_.scale = speed_integrated_trace_->get_power_scale(EngineImpl::get_clock());
   return CpuImpl::get_speed_ratio();
 }
 
@@ -603,7 +602,7 @@ void CpuTiAction::set_sharing_penalty(double sharing_penalty)
 double CpuTiAction::get_remains()
 {
   XBT_IN("(%p)", this);
-  cpu_->update_remaining_amount(surf_get_clock());
+  cpu_->update_remaining_amount(EngineImpl::get_clock());
   XBT_OUT();
   return get_remains_no_update();
 }
index 3a7b012..d11eeea 100644 (file)
@@ -39,7 +39,7 @@ namespace resource {
 double HostCLM03Model::next_occurring_event(double /*now*/)
 {
   /* nothing specific to be done here
-   * surf_solve already calls all the models next_occurring_event properly */
+   * EngineImpl::solve already calls all the models next_occurring_event properly */
   return -1.0;
 }
 
index 144058e..3dc1bd7 100644 (file)
@@ -12,7 +12,6 @@
 #include "src/kernel/resource/profile/Event.hpp"
 #include "src/surf/network_wifi.hpp"
 #include "src/surf/surf_interface.hpp"
-#include "surf/surf.hpp"
 
 #include <algorithm>
 #include <numeric>
index 4ff24be..04adf6d 100644 (file)
@@ -37,7 +37,6 @@
 #include "src/kernel/EngineImpl.hpp"
 #include "src/surf/surf_interface.hpp"
 #include "src/surf/xml/platf_private.hpp" // ClusterCreationArgs
-#include "surf/surf.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_ns3, res_network, "Network model based on ns-3");
 
@@ -380,7 +379,7 @@ double NetworkNS3Model::next_occurring_event(double now)
 
   XBT_DEBUG("doing a ns3 simulation for a duration of %f", now);
   ns3_simulator(now);
-  time_to_next_flow_completion = ns3::Simulator::Now().GetSeconds() - surf_get_clock();
+  time_to_next_flow_completion = ns3::Simulator::Now().GetSeconds() - EngineImpl::get_clock();
   // 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
@@ -389,7 +388,7 @@ double NetworkNS3Model::next_occurring_event(double now)
 
   XBT_DEBUG("min       : %f", now);
   XBT_DEBUG("ns3  time : %f", ns3::Simulator::Now().GetSeconds());
-  XBT_DEBUG("surf time : %f", surf_get_clock());
+  XBT_DEBUG("surf time : %f", EngineImpl::get_clock());
   XBT_DEBUG("Next completion %f :", time_to_next_flow_completion);
 
   return time_to_next_flow_completion;
@@ -509,10 +508,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)) {
+    while (double_positive(EngineImpl::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());
+                EngineImpl::get_clock());
+      ns3_simulator(EngineImpl::get_clock() - ns3::Simulator::Now().GetSeconds());
     }
   }
 
@@ -573,7 +572,7 @@ void ns3_simulator(double maxSeconds)
   if (maxSeconds > 0.0) // If there is a maximum amount of time to run
     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());
+  XBT_DEBUG("Start simulator for at most %fs (current time: %f)", maxSeconds, EngineImpl::get_clock());
   ns3::Simulator::Run();
   XBT_DEBUG("Simulator stopped at %fs", ns3::Simulator::Now().GetSeconds());
 
index 78dfe83..7187117 100644 (file)
@@ -52,7 +52,7 @@ public:
   void update_actions_state(double /*now*/, double /*delta*/) override{
       /* this action is done by HostL07Model which shares the LMM system with the CPU model
        * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
-       * method in surf_presolve */
+       * method in EngineImpl::presolve */
   };
 
   CpuImpl* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
@@ -72,7 +72,7 @@ public:
   void update_actions_state(double /*now*/, double /*delta*/) override{
       /* this action is done by HostL07Model which shares the LMM system with the CPU model
        * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
-       * method in surf_presolve */
+       * method in EngineImpl::presolve */
   };
 
   HostL07Model* hostModel_;
index 2f89c3a..bf52327 100644 (file)
@@ -25,7 +25,6 @@
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/xml/platf.hpp"
 #include "src/surf/xml/platf_private.hpp"
-#include "surf/surf.hpp"
 
 #include <algorithm>
 #include <string>
diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp
deleted file mode 100644 (file)
index 59fd67e..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved.          */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#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 "surf/surf.hpp"
-
-#include <algorithm>
-
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
-
-/*********
- * TOOLS *
- *********/
-
-extern double NOW;
-
-void surf_presolve()
-{
-  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)
-      break;
-
-    double value                                  = -1.0;
-    simgrid::kernel::resource::Resource* resource = nullptr;
-    while (auto* event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource)) {
-      if (value >= 0)
-        resource->apply_event(event, value);
-    }
-  }
-
-  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);
-}
-
-double surf_solve(double max_date)
-{
-  double time_delta                             = -1.0; /* duration */
-  double value                                  = -1.0;
-  simgrid::kernel::resource::Resource* resource = 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);
-
-    time_delta = max_date - NOW;
-  }
-
-  XBT_DEBUG("Looking for next event in all models");
-  auto engine = simgrid::kernel::EngineImpl::get_instance();
-  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);
-
-  XBT_DEBUG("Looking for next trace event");
-
-  while (true) { // Handle next occurring events until none remains
-    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_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())
-        continue;
-
-      if (next_event_date != -1.0) {
-        time_delta = std::min(next_event_date - NOW, time_delta);
-      } else {
-        time_delta = std::max(next_event_date - NOW, time_delta); // Get the positive component
-      }
-
-      XBT_DEBUG("Run the NS3 network at most %fs", time_delta);
-      // run until min or next flow
-      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)
-        time_delta = model_next_action_end;
-    }
-
-    if (next_event_date < 0.0 || (next_event_date > NOW + time_delta)) {
-      // next event may have already occurred or will after the next resource change, then bail out
-      XBT_DEBUG("no next usable TRACE event. Stop searching for it");
-      break;
-    }
-
-    XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)", time_delta, NOW, next_event_date);
-
-    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",
-                  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
-      double round_start = NOW;
-      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());
-      resource->apply_event(event, value);
-      NOW = round_start;
-    }
-  }
-
-  /* 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;
-  }
-
-  XBT_DEBUG("Duration set to %f", time_delta);
-
-  // Bump the time: jump into the future
-  NOW = NOW + time_delta;
-
-  // Inform the models of the date change
-  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);
-
-  return time_delta;
-}
index 06d25b6..31af4cb 100644 (file)
@@ -12,7 +12,6 @@
 #include "src/kernel/resource/profile/Profile.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/surf_interface.hpp"
-#include "surf/surf.hpp"
 
 #include <fstream>
 #include <string>
@@ -98,13 +97,6 @@ const std::vector<surf_model_description_t> surf_disk_model_description = {
     {"default", "Simplistic disk model.", &surf_disk_model_init_default},
 };
 
-double NOW = 0;
-
-double surf_get_clock()
-{
-  return NOW;
-}
-
 /* returns whether #file_path is an absolute file path. Surprising, isn't it ? */
 static bool is_absolute_file_path(const std::string& file_path)
 {
index 262ffe3..e313880 100644 (file)
@@ -25,5 +25,6 @@ XBT_PUBLIC double surf_parse_get_double(const std::string& s);
 XBT_PUBLIC int surf_parse_get_int(const std::string& s);
 
 XBT_PUBLIC void surf_parse(); /* Entry-point to the parser */
+XBT_PUBLIC void parse_platform_file(const std::string& file);
 
 #endif
index 0992af4..eb876f0 100644 (file)
@@ -10,7 +10,6 @@
 #include "src/surf/surf_interface.hpp"
 #include "src/surf/xml/platf.hpp"
 #include "src/surf/xml/platf_private.hpp"
-#include "surf/surf.hpp"
 
 #include <vector>
 
index 9ec4cd6..32f8006 100644 (file)
@@ -9,9 +9,9 @@
 #include "simgrid/kernel/routing/NetZoneImpl.hpp" // full type for NetZoneImpl object
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/zone.h"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/CpuImpl.hpp"
 #include "src/surf/network_interface.hpp"
-#include "surf/surf.hpp"
 #include "xbt/config.hpp"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
@@ -69,7 +69,7 @@ int main(int argc, char** argv)
   /* Let's do something on it */
   net_model->communicate(hostA, hostB, 150.0, -1.0);
 
-  surf_solve(-1.0);
+  e.get_impl()->solve(-1.0);
   do {
     XBT_INFO("Next Event : %g", simgrid::s4u::Engine::get_clock());
     XBT_DEBUG("\t CPU actions");
@@ -106,7 +106,7 @@ int main(int argc, char** argv)
       action.unref();
     }
   } while ((net_model->get_started_action_set()->size() || cpu_model_pm->get_started_action_set()->size()) &&
-           surf_solve(-1.0) >= 0.0);
+           e.get_impl()->solve(-1.0) >= 0.0);
 
   XBT_DEBUG("Simulation Terminated");
 
index 9634f4f..846a2d7 100644 (file)
@@ -13,7 +13,6 @@
 #include "src/kernel/resource/CpuImpl.hpp"
 #include "src/surf/network_interface.hpp"
 #include "src/surf/surf_interface.hpp"
-#include "surf/surf.hpp"
 #include "xbt/config.hpp"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
@@ -43,7 +42,7 @@ int main(int argc, char** argv)
   auto 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 */
+  e.get_impl()->solve(-1.0); /* Takes traces into account. Returns 0.0 */
   do {
     simgrid::kernel::resource::Action* action = nullptr;
     running                                   = 0;
@@ -73,7 +72,7 @@ int main(int argc, char** argv)
         action = model->extract_done_action();
       }
     }
-  } while (running && surf_solve(-1.0) >= 0.0);
+  } while (running && e.get_impl()->solve(-1.0) >= 0.0);
 
   XBT_INFO("Simulation Terminated");
   return 0;
index 15a8cf1..9b8282b 100644 (file)
@@ -6,7 +6,6 @@ set(EXTRA_DIST
   src/include/mc/datatypes.h
   src/include/mc/mc.h
   src/include/simgrid/sg_config.hpp
-  src/include/surf/surf.hpp
   src/include/xbt/coverage.h
   src/include/xbt/parmap.hpp
   src/include/xbt/mmalloc.h
@@ -359,7 +358,6 @@ set(SURF_SRC
   src/surf/SplitDuplexLinkImpl.cpp
   src/surf/network_wifi.cpp
   src/surf/sg_platf.cpp
-  src/surf/surf_c_bindings.cpp
   src/surf/surf_interface.cpp
   src/surf/xml/platf.hpp
   src/surf/xml/platf_private.hpp