Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a test for SMPI versions of gettimeofday, clock_gettime and nano/u/sleep
authordegomme <augustin.degomme@unibas.ch>
Sat, 18 Jun 2016 23:52:12 +0000 (01:52 +0200)
committerdegomme <augustin.degomme@unibas.ch>
Sat, 18 Jun 2016 23:52:12 +0000 (01:52 +0200)
include/smpi/mpi.h
teshsuite/smpi/CMakeLists.txt
teshsuite/smpi/timers/timers.c [new file with mode: 0644]
teshsuite/smpi/timers/timers.tesh [new file with mode: 0644]

index 8129fda..7adc4b4 100644 (file)
@@ -10,9 +10,6 @@
 #define SEED 221238
 
 #define sleep(x) smpi_sleep(x)
-#if _POSIX_TIMERS > 0
-#define nanosleep(x, y) smpi_nanosleep(x, y)
-#endif
 #define usleep(x) smpi_usleep(x)
 
 #include <smpi/smpi.h>
@@ -24,6 +21,7 @@
 #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 > 0
+#define nanosleep(x, y) smpi_nanosleep(x, y)
 #define clock_gettime(x, y) smpi_clock_gettime(x, y)
 #endif
 #if HAVE_MC
index fda7127..30ff3c6 100644 (file)
@@ -8,7 +8,7 @@ if(enable_smpi)
   include_directories(BEFORE "${CMAKE_HOME_DIRECTORY}/include/smpi")
   foreach(x coll-allgather coll-allgatherv coll-allreduce coll-alltoall coll-alltoallv coll-barrier coll-bcast 
             coll-gather coll-reduce coll-reduce-scatter coll-scatter macro-sample pt2pt-dsend pt2pt-pingpong 
-            type-hvector type-indexed type-struct type-vector bug-17132)
+            type-hvector type-indexed type-struct type-vector bug-17132 timers)
     add_executable       (${x}  ${x}/${x}.c)
     target_link_libraries(${x}  simgrid)
     set_target_properties(${x}  PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x})
@@ -43,7 +43,7 @@ if(enable_smpi)
 
   foreach(x coll-allgather coll-allgatherv coll-allreduce coll-alltoall coll-alltoallv coll-barrier coll-bcast 
             coll-gather coll-reduce coll-reduce-scatter coll-scatter macro-sample pt2pt-dsend pt2pt-pingpong 
-            type-hvector type-indexed type-struct type-vector bug-17132)
+            type-hvector type-indexed type-struct type-vector bug-17132 timers)
     ADD_TESH_FACTORIES(tesh-smpi-${x} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/smpi/${x} --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/${x} ${x}.tesh)
   endforeach()
 
diff --git a/teshsuite/smpi/timers/timers.c b/teshsuite/smpi/timers/timers.c
new file mode 100644 (file)
index 0000000..3d7dcbb
--- /dev/null
@@ -0,0 +1,66 @@
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <unistd.h>
+#include <sys/time.h>
+#if _POSIX_TIMERS > 0
+#include <time.h>
+#endif
+
+
+//Test if we correctly intercept gettimeofday and clock_gettime, and sleeps
+
+int main( int argc, char *argv[] )
+{
+    MPI_Init( &argc, &argv );
+
+    //gettimeofday - First test that two consecutive calls will return the same
+    //time, as computing power is set to -1
+
+    struct timeval tv1, tv2;
+    gettimeofday (&tv1, NULL);
+    gettimeofday (&tv2, NULL);
+    if ((tv1.tv_sec != tv2.tv_sec) || (tv1.tv_usec != tv2.tv_usec))
+      printf("Error, two consecutive calls to gettimeofday did not return same time (with cpu_threshold set to 0)\n");
+
+    //sleep one 1 second
+    gettimeofday (&tv1, NULL);
+    sleep(1);
+    gettimeofday (&tv2, NULL);
+    long res = ((tv2.tv_sec * 1000000 + tv2.tv_usec)) - ((tv1.tv_sec * 1000000 + tv1.tv_usec));
+    if (res < 999998 || res > 1000002)
+      printf("Error, sleep(1) did not exactly slept 1s\n");
+
+    //usleep 100 us
+    gettimeofday (&tv1, NULL);
+    usleep(100);
+    gettimeofday (&tv2, NULL);
+    res = ((tv2.tv_sec * 1000000 + tv2.tv_usec)) - ((tv1.tv_sec * 1000000 + tv1.tv_usec));
+    if (res <98 || res > 102)
+      printf("Error, usleep did not really sleep 100us, but %ld\n", res);
+
+
+    // clock_gettime, only if available
+#if _POSIX_TIMERS > 0
+    struct timespec tp1, tp2, tpsleep;
+    clock_gettime (CLOCK_REALTIME, &tp1);
+    clock_gettime (CLOCK_REALTIME, &tp2);
+    if ((tp1.tv_sec != tp2.tv_sec) || (tp1.tv_nsec != tp2.tv_nsec))
+      printf("Error, two consecutive calls to gettimeofday did not return same time (with running power to 0)\n");
+
+    //nanosleep for 100ns
+    clock_gettime (CLOCK_REALTIME, &tp1);
+    tpsleep.tv_sec=0;
+    tpsleep.tv_nsec=100;
+    nanosleep(&tpsleep, NULL);
+    clock_gettime (CLOCK_REALTIME, &tp2);
+    res = ((tp2.tv_sec * 1000000000 + tp2.tv_nsec)) - ((tp1.tv_sec * 1000000000 + tp1.tv_nsec));
+    if (res <98 || res > 102)
+      printf("Error, nanosleep did not really sleep 100ns, but %ld\n", res);
+
+#endif
+
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/timers/timers.tesh b/teshsuite/smpi/timers/timers.tesh
new file mode 100644 (file)
index 0000000..e37f03c
--- /dev/null
@@ -0,0 +1,10 @@
+p Test timers
+! setenv LD_LIBRARY_PATH=../../lib
+$ ${bindir:=.}/../../../bin/smpirun -map -hostfile ../hostfile -platform ../../../examples/platforms/small_platform.xml -np 1 ${bindir:=.}/timers -q --log=smpi_kernel.thres:warning --cfg=smpi/cpu-threshold:-1 --cfg=smpi/running-power:100000
+> [rank 0] -> Tremblay
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'surf/precision' to '1e-9'
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'SMPI'
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/TCP-gamma' to '4194304'
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'smpi/cpu-threshold' to '-1'
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'smpi/running-power' to '100000'
+