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 #include "mpicolltest.h"
14 static char MTEST_Descrip[] = "";
17 int main(int argc, char *argv[])
21 int minsize = 2, count;
23 int *sendbuf, *recvbuf, *p;
24 int sendcount, recvcount;
26 MPI_Datatype sendtype, recvtype;
28 MTest_Init(&argc, &argv);
30 /* The following illustrates the use of the routines to
31 * run through a selection of communicators and datatypes.
32 * Use subsets of these for tests that do not involve combinations
33 * of communicators, datatypes, and counts of datatypes */
34 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
35 if (comm == MPI_COMM_NULL)
38 /* Determine the sender and receiver */
39 MPI_Comm_rank(comm, &rank);
40 MPI_Comm_size(comm, &size);
42 /* printf("Size of comm = %d\n", size); */
43 for (count = 1; count < 65000; count = count * 2) {
45 /* Create a send buf and a receive buf suitable for testing
49 sendbuf = (int *) malloc(count * size * sizeof(int));
50 recvbuf = (int *) malloc(count * size * sizeof(int));
54 if (!sendbuf || !recvbuf) {
56 fprintf(stderr, "Failed to allocate sendbuf and/or recvbuf\n");
57 MPI_Abort(MPI_COMM_WORLD, 1);
59 for (i = 0; i < count * size; i++)
62 for (j = 0; j < size; j++) {
63 for (i = 0; i < count; i++) {
64 *p++ = j * size + rank + i;
68 MTest_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
71 for (j = 0; j < size; j++) {
72 for (i = 0; i < count; i++) {
73 if (*p != rank * size + j + i) {
76 fprintf(stderr, "Error with communicator %s and size=%d count=%d\n",
77 MTestGetIntracommName(), size, count);
78 fprintf(stderr, "recvbuf[%d,%d] = %d, should %d\n",
79 j, i, *p, rank * size + j + i);
86 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
87 /* check MPI_IN_PLACE, added in MPI-2.2 */
89 for (j = 0; j < size; j++) {
90 for (i = 0; i < count; i++) {
91 *p++ = j * size + rank + i;
94 MPI_Alltoall(MPI_IN_PLACE, -1 /*ignored */ , MPI_DATATYPE_NULL /*ignored */ ,
95 recvbuf, recvcount, recvtype, comm);
97 for (j = 0; j < size; j++) {
98 for (i = 0; i < count; i++) {
99 if (*p != rank * size + j + i) {
103 "Error (MPI_IN_PLACE) with communicator %s and size=%d count=%d\n",
104 MTestGetIntracommName(), size, count);
105 fprintf(stderr, "recvbuf[%d,%d] = %d, should be %d\n", j, i, *p,
106 rank * size + j + i);
117 MTestFreeComm(&comm);
120 MTest_Finalize(errs);