Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'coverity_scan' of github.com:mquinson/simgrid
[simgrid.git] / teshsuite / smpi / mpich3-test / perf / timer.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2006 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 /* 
8  * Check that the timer produces monotone nondecreasing times and that
9  * the Tick is reasonable
10  */
11
12 #include "mpi.h"
13 #include <stdio.h>
14 #include "mpitest.h"
15
16 static int verbose = 0;
17
18 #define MAX_TIMER_TEST 5000
19
20 int main(int argc, char* argv[])
21 {
22     double t1[MAX_TIMER_TEST], tick[MAX_TIMER_TEST], tickval;
23     double minDiff, maxDiff, diff;
24     int i, nZeros = 0;
25     int errs = 0;
26
27     MTest_Init(&argc,&argv);
28
29     for (i=0; i<MAX_TIMER_TEST; i++) {
30         t1[i] = MPI_Wtime();
31     }
32
33     for (i=0; i<MAX_TIMER_TEST; i++) {
34         tick[i] = MPI_Wtick();
35     }
36
37     /* Look at the values */
38     /* Look at the tick */
39     tickval = MPI_Wtick();
40     for (i=0; i<MAX_TIMER_TEST; i++) {
41         if (tickval != tick[i]) {
42             fprintf( stderr, "Nonconstant value for MPI_Wtick: %e != %e\n",
43                      tickval, tick[i] );
44             errs ++;
45         }
46     }
47
48     /* Look at the timer */
49     minDiff = 1.e20;
50     maxDiff = -1.0;
51     nZeros  = 0;
52     for (i=1; i<MAX_TIMER_TEST; i++) {
53         diff = t1[i] - t1[i-1];
54         if (diff == 0.0) nZeros++;
55         else if (diff < minDiff) minDiff = diff;
56         if (diff > maxDiff) maxDiff = diff;
57     }
58
59     /* Are the time diff values and tick values consistent */
60     if (verbose) {
61         printf( "Tick = %e, timer range = [%e,%e]\n", tickval, minDiff, 
62                 maxDiff );
63         if (nZeros) printf( "Wtime difference was 0 %d times\n", nZeros );
64     }    
65
66     MTest_Finalize(errs);
67     MPI_Finalize();
68
69     return 0;
70 }