Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
We intercept sleep, usleep and gettimeofday. Add clock_gettime and nanoslepp, also
authordegomme <augustin.degomme@unibas.ch>
Sat, 18 Jun 2016 18:25:15 +0000 (20:25 +0200)
committerdegomme <augustin.degomme@unibas.ch>
Sat, 18 Jun 2016 18:25:15 +0000 (20:25 +0200)
include/smpi/mpi.h
include/smpi/smpi.h
src/smpi/smpi_bench.cpp

index f5ff19f..ee9e433 100644 (file)
 #define SEED 221238
 
 #define sleep(x) smpi_sleep(x)
+#if _POSIX_TIMERS
+#define nanosleep(x,y) smpi_nanosleep(x,NULL)
+#endif
+#define usleep(x) smpi_usleep(x)
 
 #include <smpi/smpi.h>
 #include <xbt/sysdep.h>
@@ -19,7 +23,9 @@
 
 #include <sys/time.h> /* Load it before the define next line to not mess with the system headers */
 #define gettimeofday(x, y) smpi_gettimeofday(x, NULL)
-
+#if _POSIX_TIMERS
+#define clock_gettime(x, y) smpi_clock_gettime(x, y)
+#endif
 #if HAVE_MC
 #undef assert
 #define assert(x) MC_assert(x)
index 3f7245b..73fdb68 100644 (file)
@@ -9,6 +9,9 @@
 
 #include <unistd.h>
 #include <sys/time.h>
+#if _POSIX_TIMERS
+#include <time.h>
+#endif
 
 #include <stddef.h>
 #include <xbt/misc.h>
@@ -803,6 +806,11 @@ XBT_PUBLIC(int)  smpi_get_host_pstate(void);
 XBT_PUBLIC(double) smpi_get_host_consumed_energy(void);
 
 XBT_PUBLIC(int) smpi_usleep(useconds_t usecs);
+#if _POSIX_TIMERS
+
+XBT_PUBLIC(int) smpi_nanosleep(struct timespec *tp, void* t);
+XBT_PUBLIC(int) smpi_clock_gettime(clockid_t clk_id, struct timespec *tp);
+#endif
 XBT_PUBLIC(unsigned int) smpi_sleep(unsigned int secs);
 XBT_PUBLIC(int) smpi_gettimeofday(struct timeval *tv, void* tz);
 XBT_PUBLIC(unsigned long long) smpi_rastro_resolution (void);
index dfc02f1..91be166 100644 (file)
@@ -307,6 +307,13 @@ int smpi_usleep(useconds_t usecs)
   return static_cast<int>(private_sleep(static_cast<double>(usecs) / 1000000.0));
 }
 
+#if _POSIX_TIMERS
+int smpi_nanosleep(struct timespec *tp, void* t)
+{
+  return static_cast<int>(private_sleep(static_cast<double>(tp->tv_sec + tp->tv_nsec / 1000000000.0)));
+}
+#endif
+
 int smpi_gettimeofday(struct timeval *tv, void* tz)
 {
   double now;
@@ -324,6 +331,22 @@ int smpi_gettimeofday(struct timeval *tv, void* tz)
   return 0;
 }
 
+#if _POSIX_TIMERS
+int smpi_clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+  //there is only one time in SMPI, so clk_id is ignored.
+  double now;
+  smpi_bench_end();
+  now = SIMIX_get_clock();
+  if (tp) {
+    tp->tv_sec = static_cast<time_t>(now);
+    tp->tv_nsec = static_cast<long int>((now - tp->tv_sec) * 1e9);
+  }
+  smpi_bench_begin();
+  return 0;
+}
+#endif
+
 extern double sg_surf_precision;
 unsigned long long smpi_rastro_resolution (void)
 {