Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich-test / env / timers.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "mpi.h"
4 #include "test.h"
5 #ifdef HAVE_WINDOWS_H
6 #define sleep(a_) Sleep((a_)*1000)
7 #include <windows.h>
8 #endif
9
10 int main( int argc, char **argv )
11 {
12     int    err = 0;
13     double t1, t2;
14     double tick;
15     int    i;
16
17     MPI_Init( &argc, &argv );
18     t1 = MPI_Wtime();
19     t2 = MPI_Wtime();
20     if (t2 - t1 > 0.1 || t2 - t1 < 0.0) {
21         err++;
22         fprintf( stderr, 
23                  "Two successive calls to MPI_Wtime gave strange results: (%f) (%f)\n", 
24                  t1, t2 );
25     }
26 /* Try several times to get a 1 second sleep */
27     for (i = 0; i<10; i++) {
28         t1 = MPI_Wtime();
29         sleep(1);
30         t2 = MPI_Wtime();
31         if (t2 - t1 >= (1.0 - 0.01) && t2 - t1 <= 5.0) break;
32         if (t2 - t1 > 5.0) i = 9;
33     }
34     if (i == 10) {
35         fprintf( stderr, 
36                  "Timer around sleep(1) did not give 1 second; gave %f\n",
37              t2 - t1 );
38         fprintf( stderr, "If the sigchk check shows that SIGALRM is in use, \n\
39 this indicates only that user programs must NOT use any system call or\n\
40 library that uses SIGALRM.  SIGALRM is not used by MPICH but may be used\n\
41 by the software the MPICH uses to implement communication to other \n\
42 processes\n" );
43         err++;
44     } 
45     tick = MPI_Wtick();
46     if (tick > 1.0 || tick <= 0.0) {
47         err++;
48         fprintf( stderr, "MPI_Wtick gave a strange result: (%f)\n", tick );
49     }
50     Test_Waitforall( );
51     MPI_Finalize( );
52     
53     return err;
54 }