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.
11 #ifdef HAVE_SYS_TIME_H
17 /* FIXME: What is this test supposed to accomplish? */
19 #define LARGE_BUF (256 * 1024)
20 /* FIXME: MAX_BUF is too large */
21 #define MAX_BUF (32 * 1024 * 1024)
24 int *recvcounts, *displs;
26 /* #define dprintf printf */
36 void comm_tests(MPI_Comm comm);
37 double run_test(long long msg_size, MPI_Comm comm, test_t test_type, double *max_time);
38 int main(int argc, char **argv)
40 int comm_size, comm_rank;
42 MTest_Init(&argc, &argv);
43 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
44 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
46 fprintf(stderr, "At least 3 processes required\n");
47 MPI_Abort(MPI_COMM_WORLD, 1);
49 if (LARGE_BUF * comm_size > MAX_BUF)
51 sbuf = (void *) calloc(MAX_BUF, 1);
52 rbuf = (void *) calloc(MAX_BUF, 1);
54 recvcounts = (void *) malloc(comm_size * sizeof(int));
55 displs = (void *) malloc(comm_size * sizeof(int));
56 if (!recvcounts || !displs || !sbuf || !rbuf) {
57 fprintf(stderr, "Unable to allocate memory:\n");
59 fprintf(stderr, "\tsbuf of %d bytes\n", MAX_BUF);
61 fprintf(stderr, "\trbuf of %d bytes\n", MAX_BUF);
63 fprintf(stderr, "\trecvcounts of %zd bytes\n", comm_size * sizeof(int));
65 fprintf(stderr, "\tdispls of %zd bytes\n", comm_size * sizeof(int));
67 MPI_Abort(MPI_COMM_WORLD, -1);
70 dprintf("Message Range: (%d, %d); System size: %d\n", START_BUF, LARGE_BUF, comm_size);
73 /* COMM_WORLD tests */
75 dprintf("\n\n==========================================================\n");
76 dprintf(" MPI_COMM_WORLD\n");
77 dprintf("==========================================================\n");
79 comm_tests(MPI_COMM_WORLD);
80 /* non-COMM_WORLD tests */
82 dprintf("\n\n==========================================================\n");
83 dprintf(" non-COMM_WORLD\n");
84 dprintf("==========================================================\n");
86 MPI_Comm_split(MPI_COMM_WORLD, (comm_rank == comm_size - 1) ? 0 : 1, 0, &comm);
87 if (comm_rank < comm_size - 1)
90 /* Randomized communicator tests */
92 dprintf("\n\n==========================================================\n");
93 dprintf(" Randomized Communicator\n");
94 dprintf("==========================================================\n");
96 MPI_Comm_split(MPI_COMM_WORLD, 0, rand(), &comm);
104 MTest_Finalize(errs);
108 void comm_tests(MPI_Comm comm)
110 int comm_size, comm_rank;
111 double rtime, max_time;
113 MPI_Comm_size(comm, &comm_size);
114 MPI_Comm_rank(comm, &comm_rank);
115 for (msg_size = START_BUF; msg_size <= LARGE_BUF; msg_size *= 2) {
117 dprintf("\n====> MSG_SIZE: %d\n", (int) msg_size);
120 rtime = run_test(msg_size, comm, REGULAR, &max_time);
122 dprintf("REGULAR:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
125 rtime = run_test(msg_size, comm, BCAST, &max_time);
127 dprintf("BCAST:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
130 rtime = run_test(msg_size, comm, SPIKE, &max_time);
132 dprintf("SPIKE:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
135 rtime = run_test(msg_size, comm, HALF_FULL, &max_time);
137 dprintf("HALF_FULL:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
140 rtime = run_test(msg_size, comm, LINEAR_DECREASE, &max_time);
142 dprintf("LINEAR_DECREASE:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
145 rtime = run_test(msg_size, comm, BELL_CURVE, &max_time);
147 dprintf("BELL_CURVE:\tAVG: %.3f\tMAX: %.3f\n", rtime, max_time);
152 double run_test(long long msg_size, MPI_Comm comm, test_t test_type, double *max_time)
155 int comm_size, comm_rank;
157 double total_time, avg_time;
159 MPI_Comm_size(comm, &comm_size);
160 MPI_Comm_rank(comm, &comm_rank);
162 for (i = 0; i < comm_size; i++) {
163 if (test_type == REGULAR)
164 recvcounts[i] = msg_size;
165 else if (test_type == BCAST)
166 recvcounts[i] = (!i) ? msg_size : 0;
167 else if (test_type == SPIKE)
168 recvcounts[i] = (!i) ? (msg_size / 2) : (msg_size / (2 * (comm_size - 1)));
169 else if (test_type == HALF_FULL)
170 recvcounts[i] = (i < (comm_size / 2)) ? (2 * msg_size) : 0;
171 else if (test_type == LINEAR_DECREASE) {
172 tmp = 2 * msg_size * (comm_size - 1 - i) / (comm_size - 1);
173 if (tmp != (int) tmp) {
174 fprintf(stderr, "Integer overflow in variable tmp\n");
175 MPI_Abort(MPI_COMM_WORLD, 1);
177 recvcounts[i] = (int) tmp;
178 /* If the maximum message size is too large, don't run */
182 else if (test_type == BELL_CURVE) {
183 for (j = 0; j < i; j++) {
184 if (i - 1 + j >= comm_size)
186 tmp = msg_size * comm_size / (log(comm_size) * i);
187 recvcounts[i - 1 + j] = (int) tmp;
188 displs[i - 1 + j] = 0;
189 /* If the maximum message size is too large, don't run */
194 if (i < comm_size - 1)
195 displs[i + 1] = displs[i] + recvcounts[i];
198 * 1: sbuf is large enough
199 * 2: rbuf is large enough
200 * 3: There were no failures (e.g., tmp nowhere > rbuf size
204 for (i = 0; i < LOOPS; i++) {
205 MPI_Allgatherv(sbuf, recvcounts[comm_rank], MPI_CHAR,
206 rbuf, recvcounts, displs, MPI_CHAR, comm);
210 /* Convert to microseconds (why?) */
211 total_time = 1.0e6 * (end - start);
212 MPI_Reduce(&total_time, &avg_time, 1, MPI_DOUBLE, MPI_SUM, 0, comm);
213 MPI_Reduce(&total_time, max_time, 1, MPI_DOUBLE, MPI_MAX, 0, comm);
214 return (avg_time / (LOOPS * comm_size));