1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
12 #ifdef HAVE_SYS_TIME_H
19 /* FIXME: What is this test supposed to accomplish? */
22 #define LARGE_BUF (256 * 1024)
24 /* FIXME: MAX_BUF is too large */
25 #define MAX_BUF (32 * 1024 * 1024)
28 SMPI_VARINIT_GLOBAL(sbuf, char*);
29 SMPI_VARINIT_GLOBAL(rbuf, char*);
30 SMPI_VARINIT_GLOBAL(recvcounts, int*);
31 SMPI_VARINIT_GLOBAL(displs, int*);
32 SMPI_VARINIT_GLOBAL_AND_SET(errs, int, 0);
34 /* #define dprintf printf */
46 void comm_tests(MPI_Comm comm);
47 double run_test(long long msg_size, MPI_Comm comm, test_t test_type, double * max_time);
49 int main(int argc, char ** argv)
51 int comm_size, comm_rank;
54 MTest_Init(&argc, &argv);
55 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
56 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
58 if (LARGE_BUF * comm_size > MAX_BUF)
61 SMPI_VARGET_GLOBAL(sbuf) = (void *) calloc(MAX_BUF, 1);
62 SMPI_VARGET_GLOBAL(rbuf) = (void *) calloc(MAX_BUF, 1);
66 SMPI_VARGET_GLOBAL(recvcounts) = (void *) malloc(comm_size * sizeof(int));
67 SMPI_VARGET_GLOBAL(displs) = (void *) malloc(comm_size * sizeof(int));
68 if (!SMPI_VARGET_GLOBAL(recvcounts) || !SMPI_VARGET_GLOBAL(displs) || !SMPI_VARGET_GLOBAL(sbuf) || !SMPI_VARGET_GLOBAL(rbuf)) {
69 fprintf(stderr, "Unable to allocate memory:\n");
70 if (!SMPI_VARGET_GLOBAL(sbuf))
71 fprintf(stderr,"\tsbuf of %d bytes\n", MAX_BUF );
72 if (!SMPI_VARGET_GLOBAL(rbuf))
73 fprintf(stderr,"\trbuf of %d bytes\n", MAX_BUF );
74 if (!SMPI_VARGET_GLOBAL(recvcounts))
75 fprintf(stderr,"\trecvcounts of %zu bytes\n", comm_size * sizeof(int));
76 if (!SMPI_VARGET_GLOBAL(displs))
77 fprintf(stderr,"\tdispls of %zu bytes\n", comm_size * sizeof(int));
79 MPI_Abort(MPI_COMM_WORLD, -1);
84 dprintf("Message Range: (%d, %d); System size: %d\n", START_BUF, LARGE_BUF, comm_size);
89 /* COMM_WORLD tests */
91 dprintf("\n\n==========================================================\n");
92 dprintf(" MPI_COMM_WORLD\n");
93 dprintf("==========================================================\n");
95 comm_tests(MPI_COMM_WORLD);
97 /* non-COMM_WORLD tests */
99 dprintf("\n\n==========================================================\n");
100 dprintf(" non-COMM_WORLD\n");
101 dprintf("==========================================================\n");
103 MPI_Comm_split(MPI_COMM_WORLD, (comm_rank == comm_size - 1) ? 0 : 1, 0, &comm);
104 if (comm_rank < comm_size - 1)
106 MPI_Comm_free(&comm);
108 /* Randomized communicator tests */
110 dprintf("\n\n==========================================================\n");
111 dprintf(" Randomized Communicator\n");
112 dprintf("==========================================================\n");
114 MPI_Comm_split(MPI_COMM_WORLD, 0, rand(), &comm);
116 MPI_Comm_free(&comm);
118 //free(SMPI_VARGET_GLOBAL(sbuf));
119 //free(SMPI_VARGET_GLOBAL(rbuf));
120 free(SMPI_VARGET_GLOBAL(recvcounts));
121 free(SMPI_VARGET_GLOBAL(displs));
124 MTest_Finalize(SMPI_VARGET_GLOBAL(errs));
130 void comm_tests(MPI_Comm comm)
132 int comm_size, comm_rank;
133 double rtime = rtime; /* stop warning about unused variable */
137 MPI_Comm_size(comm, &comm_size);
138 MPI_Comm_rank(comm, &comm_rank);
140 for (msg_size = START_BUF; msg_size <= LARGE_BUF; msg_size *= 2) {
142 dprintf("\n====> MSG_SIZE: %d\n", (int) msg_size);
146 rtime = run_test(msg_size, comm, REGULAR, &max_time);
148 dprintf("REGULAR:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
152 rtime = run_test(msg_size, comm, BCAST, &max_time);
154 dprintf("BCAST:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
158 rtime = run_test(msg_size, comm, SPIKE, &max_time);
160 dprintf("SPIKE:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
164 rtime = run_test(msg_size, comm, HALF_FULL, &max_time);
166 dprintf("HALF_FULL:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
170 rtime = run_test(msg_size, comm, LINEAR_DECREASE, &max_time);
172 dprintf("LINEAR_DECREASE:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
176 rtime = run_test(msg_size, comm, BELL_CURVE, &max_time);
178 dprintf("BELL_CURVE:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
184 double run_test(long long msg_size, MPI_Comm comm, test_t test_type,
188 int comm_size, comm_rank;
190 double total_time, avg_time;
193 MPI_Comm_size(comm, &comm_size);
194 MPI_Comm_rank(comm, &comm_rank);
196 SMPI_VARGET_GLOBAL(displs)[0] = 0;
197 for (i = 0; i < comm_size; i++) {
198 if (test_type == REGULAR)
199 SMPI_VARGET_GLOBAL(recvcounts)[i] = msg_size;
200 else if (test_type == BCAST)
201 SMPI_VARGET_GLOBAL(recvcounts)[i] = (!i) ? msg_size : 0;
202 else if (test_type == SPIKE)
203 SMPI_VARGET_GLOBAL(recvcounts)[i] = (!i) ? (msg_size / 2) : (msg_size / (2 * (comm_size - 1)));
204 else if (test_type == HALF_FULL)
205 SMPI_VARGET_GLOBAL(recvcounts)[i] = (i < (comm_size / 2)) ? (2 * msg_size) : 0;
206 else if (test_type == LINEAR_DECREASE) {
207 tmp = 2 * msg_size * (comm_size - 1 - i) / (comm_size - 1);
208 if (tmp != (int)tmp) {
209 fprintf( stderr, "Integer overflow in variable tmp\n" );
210 MPI_Abort( MPI_COMM_WORLD, 1 );
213 SMPI_VARGET_GLOBAL(recvcounts)[i] = (int) tmp;
215 /* If the maximum message size is too large, don't run */
216 if (tmp > MAX_BUF) return 0;
218 else if (test_type == BELL_CURVE) {
219 for (j = 0; j < i; j++) {
220 if (i - 1 + j >= comm_size) continue;
221 tmp = msg_size * comm_size / (log(comm_size) * i);
222 SMPI_VARGET_GLOBAL(recvcounts)[i - 1 + j] = (int) tmp;
223 SMPI_VARGET_GLOBAL(displs)[i - 1 + j] = 0;
225 /* If the maximum message size is too large, don't run */
226 if (tmp > MAX_BUF) return 0;
230 if (i < comm_size - 1)
231 SMPI_VARGET_GLOBAL(displs)[i+1] = SMPI_VARGET_GLOBAL(displs)[i] + SMPI_VARGET_GLOBAL(recvcounts)[i];
235 1: sbuf is large enough
236 2: rbuf is large enough
237 3: There were no failures (e.g., tmp nowhere > rbuf size
241 for (i = 0; i < LOOPS; i++) {
242 MPI_Allgatherv(SMPI_VARGET_GLOBAL(sbuf), SMPI_VARGET_GLOBAL(recvcounts)[comm_rank], MPI_CHAR,
243 SMPI_VARGET_GLOBAL(rbuf), SMPI_VARGET_GLOBAL(recvcounts), SMPI_VARGET_GLOBAL(displs), MPI_CHAR, comm);
248 /* Convert to microseconds (why?) */
249 total_time = 1.0e6 * (end - start);
250 MPI_Reduce(&total_time, &avg_time, 1, MPI_DOUBLE, MPI_SUM, 0, comm);
251 MPI_Reduce(&total_time, max_time, 1, MPI_DOUBLE, MPI_MAX, 0, comm);
253 return (avg_time / (LOOPS * comm_size));