2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Thu Oct 17 2002 */
3 /* collective-exhaustive-byte-int-mismatch.c -- do many collective */
4 /* operations with simple type mismatches whenever possible (i.e., */
5 /* MPI_INT does not match MPI_BYTE, despite many thinking it does) */
9 "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/collective-exhaustive-byte-int-mismatch.c,v 1.1 2002/10/24 17:04:54 bronis Exp $";
25 #define RUN_ALLGATHERV
30 #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 if (*dptr == MPI_BYTE)
65 stop = (*len)/(2 * sizeof(double));
69 for (i = 0; i < stop; i++) {
70 c.real = inout->real * in->real - inout->imag * in->imag;
71 c.imag = inout->real * in->imag + inout->imag * in->real;
83 main (int argc, char **argv)
87 MPI_Comm comm = MPI_COMM_WORLD;
88 char processor_name[128];
90 int *buf0, *buf1, *displs, *counts, *rcounts, *alltoallvcounts;
93 complex_t *a, *answer;
98 MPI_Init (&argc, &argv);
99 MPI_Comm_size (comm, &nprocs);
100 MPI_Comm_rank (comm, &rank);
101 MPI_Get_processor_name (processor_name, &namelen);
102 printf ("(%d) is alive on %s\n", rank, processor_name);
105 buf0 = (int *) malloc (buf_size * nprocs * sizeof(int));
107 for (i = 0; i < buf_size * nprocs; i++)
111 alltoallvcounts = (int *) malloc (nprocs * sizeof(int));
112 assert (alltoallvcounts);
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;
144 if ((i + rank) < buf_size)
145 alltoallvcounts[i] = i + rank;
147 alltoallvcounts[i] = buf_size;
151 answer = (complex_t *) malloc (buf_size * nprocs * sizeof(complex_t));
155 for (i = 0; i < OP_COUNT; i++)
160 for (i = 0; i < OP_COUNT; i++)
161 MPI_Bcast (buf0, buf_size, MPI_INT, 0, comm);
165 for (i = 0; i < OP_COUNT; i++)
166 MPI_Gather (&buf0[rank*buf_size], buf_size,
167 MPI_INT, buf1, buf_size, MPI_INT, 0, comm);
171 for (i = 0; i < OP_COUNT; i++)
172 MPI_Scatter (buf1, buf_size, MPI_INT, buf0, buf_size, MPI_INT, 0, comm);
176 for (i = 0; i < OP_COUNT; i++)
177 MPI_Gatherv (&buf0[rank*buf_size],
178 (rank < buf_size) ? rank : buf_size,
179 MPI_INT, buf1, rcounts, displs, MPI_INT, 0, comm);
183 for (i = 0; i < OP_COUNT; i++)
184 MPI_Scatterv (buf1, counts, displs, MPI_INT, buf0,
185 (rank < buf_size) ? rank : buf_size, MPI_INT, 0, comm);
190 for (i = 0; i < OP_COUNT; i++)
191 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_MAX, 0, comm);
195 for (i = 0; i < OP_COUNT; i++)
196 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_MIN, 0, comm);
200 for (i = 0; i < OP_COUNT; i++)
201 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_SUM, 0, comm);
205 for (i = 0; i < OP_COUNT; i++)
206 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_PROD, 0, comm);
210 for (i = 0; i < OP_COUNT; i++)
211 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_LAND, 0, comm);
215 for (i = 0; i < OP_COUNT; i++)
216 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_BAND, 0, comm);
220 for (i = 0; i < OP_COUNT; i++)
221 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_LOR, 0, comm);
225 for (i = 0; i < OP_COUNT; i++)
226 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_BOR, 0, comm);
230 for (i = 0; i < OP_COUNT; i++)
231 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_LXOR, 0, comm);
235 for (i = 0; i < OP_COUNT; i++)
236 MPI_Reduce (buf0, buf1, buf_size, MPI_INT, MPI_BXOR, 0, comm);
240 for (i = 0; i < OP_COUNT; i++)
241 MPI_Reduce (a, answer, buf_size, ctype, user_op, 0, comm);
246 for (i = 0; i < OP_COUNT; i++)
247 MPI_Allgather (buf0, buf_size, MPI_INT, buf1, buf_size, MPI_INT, comm);
251 for (i = 0; i < OP_COUNT; i++)
252 MPI_Alltoall (buf1, buf_size, MPI_INT, buf0, buf_size, MPI_INT, comm);
255 #ifdef RUN_ALLGATHERV
256 for (i = 0; i < OP_COUNT; i++)
257 MPI_Allgatherv (buf0,
258 (rank < buf_size) ? rank : buf_size,
259 MPI_INT, buf1, rcounts, displs, MPI_INT, comm);
263 for (i = 0; i < OP_COUNT; i++)
264 MPI_Alltoallv (buf1, alltoallvcounts, displs, MPI_INT,
265 buf0, alltoallvcounts, displs, MPI_INT, comm);
270 for (i = 0; i < OP_COUNT; i++)
271 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_MAX, comm);
275 for (i = 0; i < OP_COUNT; i++)
276 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_MIN, comm);
280 for (i = 0; i < OP_COUNT; i++)
281 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_SUM, comm);
285 for (i = 0; i < OP_COUNT; i++)
286 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_PROD, comm);
290 for (i = 0; i < OP_COUNT; i++)
291 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_LAND, comm);
295 for (i = 0; i < OP_COUNT; i++)
296 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_BAND, comm);
300 for (i = 0; i < OP_COUNT; i++)
301 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_LOR, comm);
305 for (i = 0; i < OP_COUNT; i++)
306 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_BOR, comm);
310 for (i = 0; i < OP_COUNT; i++)
311 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_LXOR, comm);
315 for (i = 0; i < OP_COUNT; i++)
316 MPI_Allreduce (buf0, buf1, buf_size, MPI_INT, MPI_BXOR, comm);
320 for (i = 0; i < OP_COUNT; i++)
321 MPI_Allreduce (a, answer, buf_size, ctype, user_op, comm);
325 #ifdef RUN_REDUCE_SCATTER
327 for (i = 0; i < OP_COUNT; i++)
328 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_MAX, comm);
332 for (i = 0; i < OP_COUNT; i++)
333 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_MIN, comm);
337 for (i = 0; i < OP_COUNT; i++)
338 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_SUM, comm);
342 for (i = 0; i < OP_COUNT; i++)
343 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_PROD, comm);
347 for (i = 0; i < OP_COUNT; i++)
348 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_LAND, comm);
352 for (i = 0; i < OP_COUNT; i++)
353 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_BAND, comm);
357 for (i = 0; i < OP_COUNT; i++)
358 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_LOR, comm);
362 for (i = 0; i < OP_COUNT; i++)
363 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_BOR, comm);
367 for (i = 0; i < OP_COUNT; i++)
368 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_LXOR, comm);
372 for (i = 0; i < OP_COUNT; i++)
373 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_INT, MPI_BXOR, comm);
377 for (i = 0; i < OP_COUNT; i++)
378 MPI_Reduce_scatter (a, answer, rcounts, ctype, user_op, comm);
384 for (i = 0; i < OP_COUNT; i++)
385 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_MAX, comm);
389 for (i = 0; i < OP_COUNT; i++)
390 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_MIN, comm);
394 for (i = 0; i < OP_COUNT; i++)
395 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_SUM, comm);
399 for (i = 0; i < OP_COUNT; i++)
400 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_PROD, comm);
404 for (i = 0; i < OP_COUNT; i++)
405 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_LAND, comm);
409 for (i = 0; i < OP_COUNT; i++)
410 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_BAND, comm);
414 for (i = 0; i < OP_COUNT; i++)
415 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_LOR, comm);
419 for (i = 0; i < OP_COUNT; i++)
420 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_BOR, comm);
424 for (i = 0; i < OP_COUNT; i++)
425 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_LXOR, comm);
429 for (i = 0; i < OP_COUNT; i++)
430 MPI_Scan (buf0, buf1, buf_size, MPI_INT, MPI_BXOR, comm);
434 for (i = 0; i < OP_COUNT; i++)
435 MPI_Scan (a, answer, buf_size, ctype, user_op, comm);
440 int *ricounts, *rdcounts;
443 for (i = 0; i < OP_COUNT; i++)
448 for (i = 0; i < OP_COUNT; i++)
449 MPI_Bcast (buf0, buf_size * sizeof(int), MPI_BYTE, 0, comm);
453 for (i = 0; i < OP_COUNT; i++)
454 MPI_Gather (&buf0[rank*buf_size], buf_size * sizeof(int),
455 MPI_BYTE, buf1, buf_size * sizeof(int), MPI_BYTE, 0, comm);
459 for (i = 0; i < OP_COUNT; i++)
460 MPI_Scatter (buf1, buf_size * sizeof(int), MPI_BYTE,
461 buf0, buf_size * sizeof(int), MPI_BYTE, 0, comm);
465 for (i = 0; i < OP_COUNT; i++)
466 MPI_Gatherv (&buf0[rank*buf_size],
467 ((rank < buf_size) ? rank : buf_size) * sizeof(int),
468 MPI_BYTE, buf1, rcounts, displs, MPI_BYTE, 0, comm);
472 for (i = 0; i < OP_COUNT; i++)
473 MPI_Scatterv (buf1, counts, displs, MPI_BYTE, buf0,
474 ((rank < buf_size) ? rank : buf_size) * sizeof(int),
480 for (i = 0; i < OP_COUNT; i++)
481 MPI_Reduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_MAX, 0, comm);
485 for (i = 0; i < OP_COUNT; i++)
486 MPI_Reduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_MIN, 0, comm);
490 for (i = 0; i < OP_COUNT; i++)
491 MPI_Reduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_SUM, 0, comm);
495 for (i = 0; i < OP_COUNT; i++)
496 MPI_Reduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_PROD, 0, comm);
500 for (i = 0; i < OP_COUNT; i++)
501 MPI_Reduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_LAND, 0, comm);
505 for (i = 0; i < OP_COUNT; i++)
506 MPI_Reduce (buf0, buf1,
507 buf_size * sizeof(int), MPI_BYTE, MPI_BAND, 0, comm);
511 for (i = 0; i < OP_COUNT; i++)
512 MPI_Reduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_LOR, 0, comm);
516 for (i = 0; i < OP_COUNT; i++)
517 MPI_Reduce (buf0, buf1,
518 buf_size * sizeof(int), MPI_BYTE, MPI_BOR, 0, comm);
522 for (i = 0; i < OP_COUNT; i++)
523 MPI_Reduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_LXOR, 0, comm);
527 for (i = 0; i < OP_COUNT; i++)
528 MPI_Reduce (buf0, buf1,
529 buf_size * sizeof(int), MPI_BYTE, MPI_BXOR, 0, comm);
533 for (i = 0; i < OP_COUNT; i++)
534 MPI_Reduce (a, answer,
535 buf_size * 2 * sizeof(double), MPI_BYTE, user_op, 0, comm);
539 buf1 = (int *) malloc (buf_size * nprocs * sizeof(int));
541 for (i = 0; i < buf_size * nprocs; i++)
544 displs = (int *) malloc (nprocs * sizeof(int));
545 counts = (int *) malloc (nprocs * sizeof(int));
546 rcounts = (int *) malloc (nprocs * sizeof(int));
547 ricounts = (int *) malloc (nprocs * sizeof(int));
548 rdcounts = (int *) malloc (nprocs * sizeof(int));
549 assert (displs && counts && rcounts);
550 for (i = 0; i < nprocs; i++) {
551 displs[i] = i * buf_size * sizeof(int);
553 rcounts[i] = counts[i] = i * sizeof(int);
555 rdcounts[i] = i * 2 * sizeof(double);
558 rcounts[i] = counts[i] = buf_size * sizeof(int);
559 ricounts[i] = buf_size;
560 rdcounts[i] = buf_size * 2 * sizeof(double);
562 if ((i + rank) < buf_size)
563 alltoallvcounts[i] = i + rank * sizeof(int);
565 alltoallvcounts[i] = buf_size * sizeof(int);
569 answer = (complex_t *) malloc (buf_size * nprocs * sizeof(complex_t));
573 for (i = 0; i < OP_COUNT; i++)
574 MPI_Allgather (buf0, buf_size * sizeof(int), MPI_BYTE,
575 buf1, buf_size * sizeof(int), MPI_BYTE, comm);
579 for (i = 0; i < OP_COUNT; i++)
580 MPI_Alltoall (buf1, buf_size * sizeof(int), MPI_BYTE,
581 buf0, buf_size * sizeof(int), MPI_BYTE, comm);
584 #ifdef RUN_ALLGATHERV
585 for (i = 0; i < OP_COUNT; i++)
586 MPI_Allgatherv (buf0,
587 ((rank < buf_size) ? rank : buf_size) * sizeof(int),
588 MPI_BYTE, buf1, rcounts, displs, MPI_BYTE, comm);
592 for (i = 0; i < OP_COUNT; i++)
593 MPI_Alltoallv (buf1, alltoallvcounts, displs, MPI_BYTE,
594 buf0, alltoallvcounts, displs, MPI_BYTE, comm);
599 for (i = 0; i < OP_COUNT; i++)
600 MPI_Allreduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_MAX, comm);
604 for (i = 0; i < OP_COUNT; i++)
605 MPI_Allreduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_MIN, comm);
609 for (i = 0; i < OP_COUNT; i++)
610 MPI_Allreduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_SUM, comm);
614 for (i = 0; i < OP_COUNT; i++)
615 MPI_Allreduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_PROD, comm);
619 for (i = 0; i < OP_COUNT; i++)
620 MPI_Allreduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_LAND, comm);
624 for (i = 0; i < OP_COUNT; i++)
625 MPI_Allreduce (buf0, buf1,
626 buf_size * sizeof (int), MPI_BYTE, MPI_BAND, comm);
630 for (i = 0; i < OP_COUNT; i++)
631 MPI_Allreduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_LOR, comm);
635 for (i = 0; i < OP_COUNT; i++)
636 MPI_Allreduce (buf0, buf1,
637 buf_size * sizeof (int), MPI_BYTE, MPI_BOR, comm);
641 for (i = 0; i < OP_COUNT; i++)
642 MPI_Allreduce (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_LXOR, comm);
646 for (i = 0; i < OP_COUNT; i++)
647 MPI_Allreduce (buf0, buf1,
648 buf_size * sizeof (int), MPI_BYTE, MPI_BXOR, comm);
652 for (i = 0; i < OP_COUNT; i++)
653 MPI_Allreduce (a, answer,
654 buf_size * 2 * sizeof (double), MPI_BYTE, user_op, comm);
658 #ifdef RUN_REDUCE_SCATTER
660 for (i = 0; i < OP_COUNT; i++)
661 MPI_Reduce_scatter (buf0, buf1, ricounts, MPI_UNSIGNED, MPI_MAX, comm);
665 for (i = 0; i < OP_COUNT; i++)
666 MPI_Reduce_scatter (buf0, buf1, ricounts, MPI_UNSIGNED, MPI_MIN, comm);
670 for (i = 0; i < OP_COUNT; i++)
671 MPI_Reduce_scatter (buf0, buf1, ricounts, MPI_UNSIGNED, MPI_SUM, comm);
675 for (i = 0; i < OP_COUNT; i++)
676 MPI_Reduce_scatter (buf0, buf1, ricounts, MPI_UNSIGNED, MPI_PROD, comm);
680 for (i = 0; i < OP_COUNT; i++)
681 MPI_Reduce_scatter (buf0, buf1, ricounts, MPI_UNSIGNED, MPI_LAND, comm);
685 for (i = 0; i < OP_COUNT; i++)
686 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_BYTE, MPI_BAND, comm);
690 for (i = 0; i < OP_COUNT; i++)
691 MPI_Reduce_scatter (buf0, buf1, ricounts, MPI_UNSIGNED, MPI_LOR, comm);
695 for (i = 0; i < OP_COUNT; i++)
696 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_BYTE, MPI_BOR, comm);
700 for (i = 0; i < OP_COUNT; i++)
701 MPI_Reduce_scatter (buf0, buf1, ricounts, MPI_UNSIGNED, MPI_LXOR, comm);
705 for (i = 0; i < OP_COUNT; i++)
706 MPI_Reduce_scatter (buf0, buf1, rcounts, MPI_BYTE, MPI_BXOR, comm);
710 for (i = 0; i < OP_COUNT; i++)
711 MPI_Reduce_scatter (a, answer, rdcounts, MPI_BYTE, user_op, comm);
717 for (i = 0; i < OP_COUNT; i++)
718 MPI_Scan (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_MAX, comm);
722 for (i = 0; i < OP_COUNT; i++)
723 MPI_Scan (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_MIN, comm);
727 for (i = 0; i < OP_COUNT; i++)
728 MPI_Scan (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_SUM, comm);
732 for (i = 0; i < OP_COUNT; i++)
733 MPI_Scan (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_PROD, comm);
737 for (i = 0; i < OP_COUNT; i++)
738 MPI_Scan (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_LAND, comm);
742 for (i = 0; i < OP_COUNT; i++)
743 MPI_Scan (buf0, buf1, buf_size * sizeof(int), MPI_BYTE, MPI_BAND, comm);
747 for (i = 0; i < OP_COUNT; i++)
748 MPI_Scan (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_LOR, comm);
752 for (i = 0; i < OP_COUNT; i++)
753 MPI_Scan (buf0, buf1, buf_size * sizeof(int), MPI_BYTE, MPI_BOR, comm);
757 for (i = 0; i < OP_COUNT; i++)
758 MPI_Scan (buf0, buf1, buf_size, MPI_UNSIGNED, MPI_LXOR, comm);
762 for (i = 0; i < OP_COUNT; i++)
763 MPI_Scan (buf0, buf1, buf_size * sizeof(int), MPI_BYTE, MPI_BXOR, comm);
767 for (i = 0; i < OP_COUNT; i++)
769 buf_size * 2 * sizeof(double), MPI_BYTE, user_op, comm);
781 MPI_Op_free (&user_op);
782 MPI_Type_free (&ctype);
786 free (alltoallvcounts);
796 printf ("(%d) Finished normally\n", rank);