2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Thu Oct 17 2002 */
3 /* collective-exhaustive-no-error.c -- do some many collective operations */
7 "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/collective-exhaustive-no-error.c,v 1.1 2002/10/24 17:04:54 bronis Exp $";
23 #define RUN_ALLGATHERV
28 #define RUN_REDUCE_SCATTER
57 complex_prod (void *inp, void *inoutp, int *len, MPI_Datatype *dptr)
61 complex_t *in = (complex_t *) inp;
62 complex_t *inout = (complex_t *) inoutp;
64 for (i = 0; i < *len; i++) {
65 c.real = inout->real * in->real - inout->imag * in->imag;
66 c.imag = inout->real * in->imag + inout->imag * in->real;
78 main (int argc, char **argv)
82 MPI_Comm comm = MPI_COMM_WORLD;
83 char processor_name[128];
85 int *buf0, *buf1, *displs, *counts, *rcounts, *alltoallvcounts;
88 complex_t *a, *answer;
93 MPI_Init (&argc, &argv);
94 MPI_Comm_size (comm, &nprocs);
95 MPI_Comm_rank (comm, &rank);
96 MPI_Get_processor_name (processor_name, &namelen);
97 printf ("(%d) is alive on %s\n", rank, processor_name);
100 buf0 = (int *) malloc (buf_size * nprocs * sizeof(int));
102 for (i = 0; i < buf_size * nprocs; i++)
106 alltoallvcounts = (int *) malloc (nprocs * sizeof(int));
107 assert (alltoallvcounts);
108 for (i = 0; i < nprocs; i++)
109 if ((i + rank) < buf_size)
110 alltoallvcounts[i] = i + rank;
112 alltoallvcounts[i] = buf_size;
116 a = (complex_t *) malloc (buf_size * nprocs * sizeof(complex_t));
117 for (i = 0; i < buf_size * nprocs; i++) {
118 a[i].real = ((double) rank)/((double) nprocs);
119 a[i].imag = ((double) (-rank))/((double) nprocs);
122 MPI_Type_contiguous (2, MPI_DOUBLE, &ctype);
123 MPI_Type_commit (&ctype);
125 MPI_Op_create (complex_prod, 1 /* TRUE */, &user_op);
129 buf1 = (int *) malloc (buf_size * nprocs * sizeof(int));
131 for (i = 0; i < buf_size * nprocs; i++)
134 displs = (int *) malloc (nprocs * sizeof(int));
135 counts = (int *) malloc (nprocs * sizeof(int));
136 rcounts = (int *) malloc (nprocs * sizeof(int));
137 assert (displs && counts && rcounts);
138 for (i = 0; i < nprocs; i++) {
139 displs[i] = i * buf_size;
141 rcounts[i] = counts[i] = i;
143 rcounts[i] = counts[i] = buf_size;
147 answer = (complex_t *) malloc (buf_size * nprocs * sizeof(complex_t));
152 for (i = 0; i < OP_COUNT; i++)
157 for (i = 0; i < OP_COUNT; i++)
158 MPI_Bcast (buf0, buf_size, MPI_INT, 0, comm);
162 for (i = 0; i < OP_COUNT; i++)
163 MPI_Gather (&buf0[rank*buf_size], buf_size,
164 MPI_INT, buf1, buf_size, MPI_INT, 0, comm);
168 for (i = 0; i < OP_COUNT; i++)
169 MPI_Scatter (buf1, buf_size, MPI_INT, buf0, buf_size, MPI_INT, 0, comm);
173 for (i = 0; i < OP_COUNT; i++)
174 MPI_Gatherv (&buf0[rank*buf_size],
175 (rank < buf_size) ? rank : buf_size,
176 MPI_INT, buf1, rcounts, displs, MPI_INT, 0, comm);
180 for (i = 0; i < OP_COUNT; i++)
181 MPI_Scatterv (buf1, counts, displs, MPI_INT, buf0,
182 (rank < buf_size) ? rank : buf_size, MPI_INT, 0, comm);
187 for (i = 0; i < OP_COUNT; i++)
188 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_MAX, 0, comm);
192 for (i = 0; i < OP_COUNT; i++)
193 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_MIN, 0, comm);
197 for (i = 0; i < OP_COUNT; i++)
198 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_SUM, 0, comm);
202 for (i = 0; i < OP_COUNT; i++)
203 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_PROD, 0, comm);
207 for (i = 0; i < OP_COUNT; i++)
208 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_LAND, 0, comm);
212 for (i = 0; i < OP_COUNT; i++)
213 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_BAND, 0, comm);
217 for (i = 0; i < OP_COUNT; i++)
218 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_LOR, 0, comm);
222 for (i = 0; i < OP_COUNT; i++)
223 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_BOR, 0, comm);
227 for (i = 0; i < OP_COUNT; i++)
228 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_LXOR, 0, comm);
232 for (i = 0; i < OP_COUNT; i++)
233 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_BXOR, 0, comm);
238 for (i = 0; i < OP_COUNT; i++)
239 MPI_Reduce (buf0, buf1, buf_size, MPI_2INT, MPI_MAXLOC, 0, comm);
241 fprintf (stderr, "Not enough tasks for MAXLOC test\n");
246 for (i = 0; i < OP_COUNT; i++)
247 MPI_Reduce (buf0, buf1, buf_size, MPI_2INT, MPI_MINLOC, 0, comm);
249 fprintf (stderr, "Not enough tasks for MINLOC test\n");
253 for (i = 0; i < OP_COUNT; i++)
254 MPI_Reduce (a, answer, buf_size, ctype, user_op, 0, comm);
259 buf1 = (int *) malloc (buf_size * nprocs * sizeof(int));
261 for (i = 0; i < buf_size * nprocs; i++)
264 displs = (int *) malloc (nprocs * sizeof(int));
265 counts = (int *) malloc (nprocs * sizeof(int));
266 rcounts = (int *) malloc (nprocs * sizeof(int));
267 assert (displs && counts && rcounts);
268 for (i = 0; i < nprocs; i++) {
269 displs[i] = i * buf_size;
271 rcounts[i] = counts[i] = i;
273 rcounts[i] = counts[i] = buf_size;
277 answer = (complex_t *) malloc (buf_size * nprocs * sizeof(complex_t));
282 for (i = 0; i < OP_COUNT; i++)
283 MPI_Allgather (buf0, buf_size, MPI_INT, buf1, buf_size, MPI_INT, comm);
287 for (i = 0; i < OP_COUNT; i++)
288 MPI_Alltoall (buf1, buf_size, MPI_INT, buf0, buf_size, MPI_INT, comm);
291 #ifdef RUN_ALLGATHERV
292 for (i = 0; i < OP_COUNT; i++)
293 MPI_Allgatherv (buf0,
294 (rank < buf_size) ? rank : buf_size,
295 MPI_INT, buf1, rcounts, displs, MPI_INT, comm);
299 for (i = 0; i < OP_COUNT; i++)
300 MPI_Alltoallv (buf1, alltoallvcounts, displs, MPI_INT,
301 buf0, alltoallvcounts, displs, MPI_INT, comm);
306 for (i = 0; i < OP_COUNT; i++)
307 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_MAX, comm);
311 for (i = 0; i < OP_COUNT; i++)
312 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_MIN, comm);
316 for (i = 0; i < OP_COUNT; i++)
317 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_SUM, comm);
321 for (i = 0; i < OP_COUNT; i++)
322 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_PROD, comm);
326 for (i = 0; i < OP_COUNT; i++)
327 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_LAND, comm);
331 for (i = 0; i < OP_COUNT; i++)
332 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_BAND, comm);
336 for (i = 0; i < OP_COUNT; i++)
337 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_LOR, comm);
341 for (i = 0; i < OP_COUNT; i++)
342 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_BOR, comm);
346 for (i = 0; i < OP_COUNT; i++)
347 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_LXOR, comm);
351 for (i = 0; i < OP_COUNT; i++)
352 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_BXOR, comm);
357 for (i = 0; i < OP_COUNT; i++)
358 MPI_Allreduce (buf0, buf1, buf_size, MPI_2INT, MPI_MAXLOC, comm);
360 fprintf (stderr, "Not enough tasks for MAXLOC test\n");
365 for (i = 0; i < OP_COUNT; i++)
366 MPI_Allreduce (buf0, buf1, buf_size, MPI_2INT, MPI_MINLOC, comm);
368 fprintf (stderr, "Not enough tasks for MINLOC test\n");
372 for (i = 0; i < OP_COUNT; i++)
373 MPI_Allreduce (a, answer, buf_size, ctype, user_op, comm);
377 #ifdef RUN_REDUCE_SCATTER
379 for (i = 0; i < OP_COUNT; i++)
380 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_MAX, comm);
384 for (i = 0; i < OP_COUNT; i++)
385 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_MIN, comm);
389 for (i = 0; i < OP_COUNT; i++)
390 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_SUM, comm);
394 for (i = 0; i < OP_COUNT; i++)
395 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_PROD, comm);
399 for (i = 0; i < OP_COUNT; i++)
400 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_LAND, comm);
404 for (i = 0; i < OP_COUNT; i++)
405 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_BAND, comm);
409 for (i = 0; i < OP_COUNT; i++)
410 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_LOR, comm);
414 for (i = 0; i < OP_COUNT; i++)
415 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_BOR, comm);
419 for (i = 0; i < OP_COUNT; i++)
420 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_LXOR, comm);
424 for (i = 0; i < OP_COUNT; i++)
425 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_BXOR, comm);
430 for (i = 0; i < OP_COUNT; i++)
431 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_2INT, MPI_MAXLOC, comm);
433 fprintf (stderr, "Not enough tasks for MAXLOC test\n");
438 for (i = 0; i < OP_COUNT; i++)
439 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_2INT, MPI_MINLOC, comm);
441 fprintf (stderr, "Not enough tasks for MINLOC test\n");
445 for (i = 0; i < OP_COUNT; i++)
446 MPI_Reduce_scatter (a, answer, rcounts, ctype, user_op, comm);
452 for (i = 0; i < OP_COUNT; i++)
453 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_MAX, comm);
457 for (i = 0; i < OP_COUNT; i++)
458 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_MIN, comm);
462 for (i = 0; i < OP_COUNT; i++)
463 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_SUM, comm);
467 for (i = 0; i < OP_COUNT; i++)
468 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_PROD, comm);
472 for (i = 0; i < OP_COUNT; i++)
473 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_LAND, comm);
477 for (i = 0; i < OP_COUNT; i++)
478 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_BAND, comm);
482 for (i = 0; i < OP_COUNT; i++)
483 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_LOR, comm);
487 for (i = 0; i < OP_COUNT; i++)
488 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_BOR, comm);
492 for (i = 0; i < OP_COUNT; i++)
493 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_LXOR, comm);
497 for (i = 0; i < OP_COUNT; i++)
498 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_BXOR, comm);
503 for (i = 0; i < OP_COUNT; i++)
504 MPI_Scan (buf0, buf1, buf_size, MPI_2INT, MPI_MAXLOC, comm);
506 fprintf (stderr, "Not enough tasks for MAXLOC test\n");
511 for (i = 0; i < OP_COUNT; i++)
512 MPI_Scan (buf0, buf1, buf_size, MPI_2INT, MPI_MINLOC, comm);
514 fprintf (stderr, "Not enough tasks for MINLOC test\n");
518 for (i = 0; i < OP_COUNT; i++)
519 MPI_Scan (a, answer, buf_size, ctype, user_op, comm);
530 MPI_Op_free (&user_op);
531 MPI_Type_free (&ctype);
535 free (alltoallvcounts);
545 printf ("(%d) Finished normally\n", rank);