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.
13 static char MTEST_Descrip[] = "Test MPI_Exscan";
16 int main(int argc, char *argv[])
20 int minsize = 2, count;
21 int *sendbuf, *recvbuf, i;
24 MTest_Init(&argc, &argv);
26 /* The following illustrates the use of the routines to
27 * run through a selection of communicators and datatypes.
28 * Use subsets of these for tests that do not involve combinations
29 * of communicators, datatypes, and counts of datatypes */
30 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
31 if (comm == MPI_COMM_NULL)
34 MPI_Comm_rank(comm, &rank);
35 MPI_Comm_size(comm, &size);
37 for (count = 1; count < 65000; count = count * 2) {
39 sendbuf = (int *) malloc(count * sizeof(int));
40 recvbuf = (int *) malloc(count * sizeof(int));
42 for (i = 0; i < count; i++) {
43 sendbuf[i] = rank + i * size;
47 MPI_Exscan(sendbuf, recvbuf, count, MPI_INT, MPI_SUM, comm);
49 /* Check the results. rank 0 has no data */
52 for (i = 0; i < count; i++) {
53 result = rank * i * size + ((rank) * (rank - 1)) / 2;
54 if (recvbuf[i] != result) {
57 fprintf(stderr, "Error in recvbuf[%d] = %d on %d, expected %d\n",
58 i, recvbuf[i], rank, result);
64 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
65 /* now try the MPI_IN_PLACE flavor */
66 for (i = 0; i < count; i++) {
67 sendbuf[i] = -1; /* unused */
68 recvbuf[i] = rank + i * size;
71 MPI_Exscan(MPI_IN_PLACE, recvbuf, count, MPI_INT, MPI_SUM, comm);
73 /* Check the results. rank 0's data must remain unchanged */
74 for (i = 0; i < count; i++) {
77 result = rank + i * size;
79 result = rank * i * size + ((rank) * (rank - 1)) / 2;
80 if (recvbuf[i] != result) {
83 fprintf(stderr, "Error in recvbuf[%d] = %d on %d, expected %d\n",
84 i, recvbuf[i], rank, result);