Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[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", tickval, tick[i]);
43             errs++;
44         }
45     }
46
47     /* Look at the timer */
48     minDiff = 1.e20;
49     maxDiff = -1.0;
50     nZeros = 0;
51     for (i = 1; i < MAX_TIMER_TEST; i++) {
52         diff = t1[i] - t1[i - 1];
53         if (diff == 0.0)
54             nZeros++;
55         else if (diff < minDiff)
56             minDiff = diff;
57         if (diff > maxDiff)
58             maxDiff = diff;
59     }
60
61     /* Are the time diff values and tick values consistent */
62     if (verbose) {
63         printf("Tick = %e, timer range = [%e,%e]\n", tickval, minDiff, maxDiff);
64         if (nZeros)
65             printf("Wtime difference was 0 %d times\n", nZeros);
66     }
67
68     MTest_Finalize(errs);
69     MPI_Finalize();
70
71     return 0;
72 }