Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix f77 tests
[simgrid.git] / teshsuite / smpi / mpich3-test / perf / allredtrace.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2008 by University of Illinois
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 /*
8  * This code is intended to test the trace overhead when using an
9  * MPI tracing package.  To perform the test, follow these steps:
10  *
11  * 1) Run with the versbose mode selected to determine the delay argument
12  *    to use in subsequent tests:
13  *      mpiexec -n 4096 allredtrace -v
14  *    Assume that the computed delay count is 6237; that value is used in
15  *    the following.
16  *
17  * 2) Run with an explicit delay count, without tracing enabled:
18  *      mpiexec -n 4096 allredtrace -delaycount 6237
19  *
20  * 3) Build allredtrace with tracing enabled, then run:
21  *      mpiexec -n 4096 allredtrace -delaycount 6237
22  *
23  * Compare the total times.  The tracing version should take slightly
24  * longer but no more than, for example, 15%.
25  */
26 #include "mpi.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 static int verbose = 0;
32 static int lCount = 0;
33 void Delay(int);
34 void SetupDelay(double);
35
36 int main(int argc, char *argv[])
37 {
38     double usecPerCall = 100;
39     double t, t1, tsum;
40     int i, nLoop = 100;
41     int rank;
42
43     MPI_Init(&argc, &argv);
44     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
45
46     /* Process arguments.  We allow the delay count to be set from the
47      * command line to ensure reproducibility */
48     for (i = 1; i < argc; i++) {
49         if (strcmp(argv[i], "-delaycount") == 0) {
50             i++;
51             lCount = atoi(argv[i]);
52         }
53         else if (strcmp(argv[i], "-v") == 0) {
54             verbose = 1;
55         }
56         else {
57             fprintf(stderr, "Unrecognized argument %s\n", argv[i]);
58             exit(1);
59         }
60     }
61
62     if (lCount == 0) {
63         SetupDelay(usecPerCall);
64     }
65
66     MPI_Barrier(MPI_COMM_WORLD);
67
68     t = MPI_Wtime();
69     for (i = 0; i < nLoop; i++) {
70         MPI_Allreduce(&t1, &tsum, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
71         Delay(lCount);
72     }
73     t = MPI_Wtime() - t;
74     MPI_Barrier(MPI_COMM_WORLD);
75     if (rank == 0) {
76         printf("For delay count %d, time is %e\n", lCount, t);
77     }
78
79     MPI_Barrier(MPI_COMM_WORLD);
80
81     MPI_Finalize();
82
83     return 0;
84 }
85
86 void SetupDelay(double usec)
87 {
88     double t, tick;
89     double sec = 1.0e-6 * usec;
90     int nLoop, i, direction;
91
92
93     /* Compute the number of times to run the tests to get an accurate
94      * number given the timer resolution. */
95     nLoop = 1;
96     tick = 100 * MPI_Wtick();
97     do {
98         nLoop = 2 * nLoop;
99         t = MPI_Wtime();
100         for (i = 0; i < nLoop; i++) {
101             MPI_Wtime();
102         }
103         t = MPI_Wtime() - t;
104     }
105     while (t < tick && nLoop < 100000);
106
107     if (verbose)
108         printf("nLoop = %d\n", nLoop);
109
110     /* Start with an estimated count */
111     lCount = 128;
112     direction = 0;
113     while (1) {
114         t = MPI_Wtime();
115         for (i = 0; i < nLoop; i++) {
116             Delay(lCount);
117         }
118         t = MPI_Wtime() - t;
119         t = t / nLoop;
120         if (verbose)
121             printf("lCount = %d, time = %e\n", lCount, t);
122         if (t > 10 * tick)
123             nLoop = nLoop / 2;
124
125         /* Compare measured delay */
126         if (t > 2 * sec) {
127             lCount = lCount / 2;
128             if (direction == 1)
129                 break;
130             direction = -1;
131         }
132         else if (t < sec / 2) {
133             lCount = lCount * 2;
134             if (direction == -1)
135                 break;
136             direction = 1;
137         }
138         else if (t < sec) {
139             /* sec/2 <= t < sec , so estimate the lCount to hit sec */
140             lCount = (sec / t) * lCount;
141         }
142         else
143             break;
144     }
145
146     if (verbose)
147         printf("lCount = %d, t = %e\n", lCount, t);
148
149     /* Should coordinate with the other processes - take the max? */
150 }
151
152 volatile double delayCounter = 0;
153 void Delay(int count)
154 {
155     int i;
156
157     delayCounter = 0.0;
158     for (i = 0; i < count; i++) {
159         delayCounter += 2.73;
160     }
161 }