Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Let resource profiles finish their initialization by themselves and kill presolve
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 16 Apr 2023 16:45:59 +0000 (18:45 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 16 Apr 2023 16:45:59 +0000 (18:45 +0200)
src/kernel/EngineImpl.cpp
src/kernel/EngineImpl.hpp
src/kernel/resource/profile/FutureEvtSet.cpp

index 8e794a5..e3e701a 100644 (file)
@@ -194,9 +194,6 @@ void EngineImpl::initialize(int* argc, char** argv)
 
   install_signal_handlers();
 
-  /* register a function to be called after the environment creation */
-  s4u::Engine::on_platform_created_cb([this]() { this->presolve(); });
-
   if (cfg_dbg_clean_atexit)
     atexit(shutdown);
 }
@@ -477,23 +474,6 @@ void EngineImpl::display_all_actor_status() const
   }
 }
 
-void EngineImpl::presolve() const
-{
-  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);
-    }
-  }
-}
-
 double EngineImpl::solve(double max_date) const
 {
   double time_delta            = -1.0; /* duration */
index 6862409..33a12dd 100644 (file)
@@ -152,10 +152,6 @@ 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() const;
   /** @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
index 74a0605..34b4071 100644 (file)
@@ -4,8 +4,10 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/kernel/resource/profile/FutureEvtSet.hpp"
+#include "src/kernel/resource/Resource.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
 #include "src/kernel/resource/profile/Profile.hpp"
+#include <simgrid/s4u/Engine.hpp>
 
 namespace simgrid::kernel::profile {
 
@@ -23,6 +25,23 @@ FutureEvtSet::~FutureEvtSet()
 /** @brief Schedules an event to a future date */
 void FutureEvtSet::add_event(double date, Event* evt)
 {
+  if (heap_.empty())
+    s4u::Engine::on_platform_created_cb([this]() {
+      /* Handle the events of time = 0 right after the platform creation */
+      double next_event_date;
+      while ((next_event_date = this->next_date()) != -1.0) {
+        if (next_event_date > 0)
+          break;
+
+        double value                 = -1.0;
+        resource::Resource* resource = nullptr;
+        while (auto* event = this->pop_leq(next_event_date, &value, &resource)) {
+          if (value >= 0)
+            resource->apply_event(event, value);
+        }
+      }
+    });
+
   heap_.emplace(date, evt);
 }