From 9a06c78e036709535b145e06d9c499f87bcd5678 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 4 May 2021 17:51:40 +0200 Subject: [PATCH] Warn the user if the sleep time is smaller than the numerical precision --- src/s4u/s4u_Actor.cpp | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 2a640c44b8..2725b02654 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -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() -- 2.20.1