-/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2007-2022. 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 "smpi_utils.hpp"
#include "src/internal_config.h"
#include "src/mc/mc_replay.hpp"
+#include "src/surf/surf_interface.hpp" // sg_surf_precision
#include "xbt/config.hpp"
#include "xbt/file.hpp"
}
/* Private sleep function used by smpi_sleep(), smpi_usleep() and friends */
-static unsigned int private_sleep(double secs)
+static void private_sleep(double secs)
{
const SmpiBenchGuard suspend_bench;
XBT_DEBUG("Sleep for: %lf secs", secs);
aid_t pid = simgrid::s4u::this_actor::get_pid();
TRACE_smpi_sleeping_in(pid, secs);
-
simgrid::s4u::this_actor::sleep_for(secs);
-
TRACE_smpi_sleeping_out(pid);
-
- return 0;
}
unsigned int smpi_sleep(unsigned int secs)
{
if (not smpi_process())
return sleep(secs);
- return private_sleep(secs);
+ private_sleep(secs);
+ return 0;
}
int smpi_usleep(useconds_t usecs)
{
if (not smpi_process())
return usleep(usecs);
- return static_cast<int>(private_sleep(usecs / 1000000.0));
+ private_sleep(static_cast<double>(usecs) / 1e6);
+ return 0;
}
#if _POSIX_TIMERS > 0
{
if (not smpi_process())
return nanosleep(tp,t);
- return static_cast<int>(private_sleep(tp->tv_sec + tp->tv_nsec / 1000000000.0));
+ private_sleep(static_cast<double>(tp->tv_sec) + static_cast<double>(tp->tv_nsec) / 1e9);
+ return 0;
}
#endif
return gettimeofday(tv, tz);
const SmpiBenchGuard suspend_bench;
- double now = simgrid::s4u::Engine::get_clock();
if (tv) {
- tv->tv_sec = static_cast<time_t>(now);
-#ifdef WIN32
- tv->tv_usec = static_cast<useconds_t>((now - tv->tv_sec) * 1e6);
-#else
- tv->tv_usec = static_cast<suseconds_t>((now - tv->tv_sec) * 1e6);
-#endif
+ double now = simgrid::s4u::Engine::get_clock();
+ double secs = trunc(now);
+ double usecs = (now - secs) * 1e6;
+ tv->tv_sec = static_cast<time_t>(secs);
+ tv->tv_usec = static_cast<decltype(tv->tv_usec)>(usecs); // suseconds_t (or useconds_t on WIN32)
}
if (smpi_wtime_sleep > 0)
simgrid::s4u::this_actor::sleep_for(smpi_wtime_sleep);
return clock_gettime(clk_id, tp);
//there is only one time in SMPI, so clk_id is ignored.
const SmpiBenchGuard suspend_bench;
- double now = simgrid::s4u::Engine::get_clock();
- tp->tv_sec = static_cast<time_t>(now);
- tp->tv_nsec = static_cast<long int>((now - tp->tv_sec) * 1e9);
+ double now = simgrid::s4u::Engine::get_clock();
+ double secs = trunc(now);
+ double nsecs = (now - secs) * 1e9;
+ tp->tv_sec = static_cast<time_t>(secs);
+ tp->tv_nsec = static_cast<long int>(nsecs);
if (smpi_wtime_sleep > 0)
simgrid::s4u::this_actor::sleep_for(smpi_wtime_sleep);
return 0;
return time;
}
-extern double sg_surf_precision;
+// Used by Akypuera (https://github.com/schnorr/akypuera)
unsigned long long smpi_rastro_resolution ()
{
const SmpiBenchGuard suspend_bench;
- double resolution = (1/sg_surf_precision);
- return static_cast<unsigned long long>(resolution);
+ return static_cast<unsigned long long>(1.0 / sg_surf_precision);
}
unsigned long long smpi_rastro_timestamp ()
{
const SmpiBenchGuard suspend_bench;
- double now = simgrid::s4u::Engine::get_clock();
-
- auto sec = static_cast<unsigned long long>(now);
- unsigned long long pre = (now - sec) * smpi_rastro_resolution();
- return sec * smpi_rastro_resolution() + pre;
+ return static_cast<unsigned long long>(simgrid::s4u::Engine::get_clock() / sg_surf_precision);
}
/* ****************************** Functions related to the SMPI_SAMPLE_ macros ************************************/
XBT_DEBUG("No benchmark (either no need, or just ran one): count (%d) >= iter (%d) (or <2) or stderr (%f) < thres (%f), or thresh is negative and ignored. "
"Mean is %f, will be injected %d times",
data.count, data.iters, data.relstderr, data.threshold, data.mean, iter_count);
-
+
//we ended benchmarking, let's inject all the time, now, and fast forward out of the loop.
smpi_process()->set_sampling(0);
smpi_execute(data.mean*iter_count);