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 __thread char * sbuf, * rbuf;
29 __thread int * recvcounts, * displs;
32 /* #define dprintf printf */
44 void comm_tests(MPI_Comm comm);
45 double run_test(long long msg_size, MPI_Comm comm, test_t test_type, double * max_time);
47 int main(int argc, char ** argv)
49 int comm_size, comm_rank;
52 MTest_Init(&argc, &argv);
53 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
54 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
56 if (LARGE_BUF * comm_size > MAX_BUF)
59 sbuf = (void *) calloc(MAX_BUF, 1);
60 rbuf = (void *) calloc(MAX_BUF, 1);
64 recvcounts = (void *) malloc(comm_size * sizeof(int));
65 displs = (void *) malloc(comm_size * sizeof(int));
66 if (!recvcounts || !displs || !sbuf || !rbuf) {
67 fprintf(stderr, "Unable to allocate memory:\n");
68 if (!sbuf) fprintf(stderr,"\tsbuf of %d bytes\n", MAX_BUF );
69 if (!rbuf) fprintf(stderr,"\trbuf of %d bytes\n", MAX_BUF );
70 if (!recvcounts) fprintf(stderr,"\trecvcounts of %zd bytes\n", comm_size * sizeof(int) );
71 if (!displs) fprintf(stderr,"\tdispls of %zd bytes\n", comm_size * sizeof(int) );
73 MPI_Abort(MPI_COMM_WORLD, -1);
78 dprintf("Message Range: (%d, %d); System size: %d\n", START_BUF, LARGE_BUF, comm_size);
83 /* COMM_WORLD tests */
85 dprintf("\n\n==========================================================\n");
86 dprintf(" MPI_COMM_WORLD\n");
87 dprintf("==========================================================\n");
89 comm_tests(MPI_COMM_WORLD);
91 /* non-COMM_WORLD tests */
93 dprintf("\n\n==========================================================\n");
94 dprintf(" non-COMM_WORLD\n");
95 dprintf("==========================================================\n");
97 MPI_Comm_split(MPI_COMM_WORLD, (comm_rank == comm_size - 1) ? 0 : 1, 0, &comm);
98 if (comm_rank < comm_size - 1)
100 MPI_Comm_free(&comm);
102 /* Randomized communicator tests */
104 dprintf("\n\n==========================================================\n");
105 dprintf(" Randomized Communicator\n");
106 dprintf("==========================================================\n");
108 MPI_Comm_split(MPI_COMM_WORLD, 0, rand(), &comm);
110 MPI_Comm_free(&comm);
118 MTest_Finalize(errs);
124 void comm_tests(MPI_Comm comm)
126 int comm_size, comm_rank;
127 double rtime, max_time;
130 MPI_Comm_size(comm, &comm_size);
131 MPI_Comm_rank(comm, &comm_rank);
133 for (msg_size = START_BUF; msg_size <= LARGE_BUF; msg_size *= 2) {
135 dprintf("\n====> MSG_SIZE: %d\n", (int) msg_size);
139 rtime = run_test(msg_size, comm, REGULAR, &max_time);
141 dprintf("REGULAR:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
145 rtime = run_test(msg_size, comm, BCAST, &max_time);
147 dprintf("BCAST:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
151 rtime = run_test(msg_size, comm, SPIKE, &max_time);
153 dprintf("SPIKE:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
157 rtime = run_test(msg_size, comm, HALF_FULL, &max_time);
159 dprintf("HALF_FULL:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
163 rtime = run_test(msg_size, comm, LINEAR_DECREASE, &max_time);
165 dprintf("LINEAR_DECREASE:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
169 rtime = run_test(msg_size, comm, BELL_CURVE, &max_time);
171 dprintf("BELL_CURVE:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
177 double run_test(long long msg_size, MPI_Comm comm, test_t test_type,
181 int comm_size, comm_rank;
183 double total_time, avg_time;
186 MPI_Comm_size(comm, &comm_size);
187 MPI_Comm_rank(comm, &comm_rank);
190 for (i = 0; i < comm_size; i++) {
191 if (test_type == REGULAR)
192 recvcounts[i] = msg_size;
193 else if (test_type == BCAST)
194 recvcounts[i] = (!i) ? msg_size : 0;
195 else if (test_type == SPIKE)
196 recvcounts[i] = (!i) ? (msg_size / 2) : (msg_size / (2 * (comm_size - 1)));
197 else if (test_type == HALF_FULL)
198 recvcounts[i] = (i < (comm_size / 2)) ? (2 * msg_size) : 0;
199 else if (test_type == LINEAR_DECREASE) {
200 tmp = 2 * msg_size * (comm_size - 1 - i) / (comm_size - 1);
201 if (tmp != (int)tmp) {
202 fprintf( stderr, "Integer overflow in variable tmp\n" );
203 MPI_Abort( MPI_COMM_WORLD, 1 );
206 recvcounts[i] = (int) tmp;
208 /* If the maximum message size is too large, don't run */
209 if (tmp > MAX_BUF) return 0;
211 else if (test_type == BELL_CURVE) {
212 for (j = 0; j < i; j++) {
213 if (i - 1 + j >= comm_size) continue;
214 tmp = msg_size * comm_size / (log(comm_size) * i);
215 recvcounts[i - 1 + j] = (int) tmp;
216 displs[i - 1 + j] = 0;
218 /* If the maximum message size is too large, don't run */
219 if (tmp > MAX_BUF) return 0;
223 if (i < comm_size - 1)
224 displs[i+1] = displs[i] + recvcounts[i];
228 1: sbuf is large enough
229 2: rbuf is large enough
230 3: There were no failures (e.g., tmp nowhere > rbuf size
234 for (i = 0; i < LOOPS; i++) {
235 MPI_Allgatherv(sbuf, recvcounts[comm_rank], MPI_CHAR,
236 rbuf, recvcounts, displs, MPI_CHAR, comm);
241 /* Convert to microseconds (why?) */
242 total_time = 1.0e6 * (end - start);
243 MPI_Reduce(&total_time, &avg_time, 1, MPI_DOUBLE, MPI_SUM, 0, comm);
244 MPI_Reduce(&total_time, max_time, 1, MPI_DOUBLE, MPI_MAX, 0, comm);
246 return (avg_time / (LOOPS * comm_size));