Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Warn the user if the sleep time is smaller than the numerical precision
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 4 May 2021 15:51:40 +0000 (17:51 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 4 May 2021 17:30:02 +0000 (19:30 +0200)
src/s4u/s4u_Actor.cpp

index 2a640c4..2725b02 100644 (file)
@@ -314,23 +314,35 @@ bool is_maestro()
 void sleep_for(double duration)
 {
   xbt_assert(std::isfinite(duration), "duration is not finite!");
+  static unsigned int warned = 0; // At most 20 such warnings
+
+  if (duration <= 0) /* that's a no-op */
+    return;
+
+  if (duration < sg_surf_precision) {
+    warned++;
+    if (warned <= 20)
+      XBT_INFO("The parameter to sleep_for() is smaller than the SimGrid numerical accuracy (%g < %g). "
+               "Please refer to https://simgrid.org/doc/latest/Configuring_SimGrid.html#numerical-precision",
+               duration, sg_surf_precision);
+    if (warned == 20)
+      XBT_VERB("(further warnings about the numerical accuracy of sleep_for() will be omitted).");
+  }
 
-  if (duration > 0) {
-    kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
-    Actor::on_sleep(*issuer->get_ciface());
-
-    kernel::actor::simcall_blocking([issuer, duration]() {
-      if (MC_is_active() || MC_record_replay_is_active()) {
-        MC_process_clock_add(issuer, duration);
-        issuer->simcall_answer();
-        return;
-      }
-      kernel::activity::ActivityImplPtr sync = issuer->sleep(duration);
-      sync->register_simcall(&issuer->simcall_);
-    });
+  kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
+  Actor::on_sleep(*issuer->get_ciface());
 
-    Actor::on_wake_up(*issuer->get_ciface());
-  }
+  kernel::actor::simcall_blocking([issuer, duration]() {
+    if (MC_is_active() || MC_record_replay_is_active()) {
+      MC_process_clock_add(issuer, duration);
+      issuer->simcall_answer();
+      return;
+    }
+    kernel::activity::ActivityImplPtr sync = issuer->sleep(duration);
+    sync->register_simcall(&issuer->simcall_);
+  });
+
+  Actor::on_wake_up(*issuer->get_ciface());
 }
 
 void yield()