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) continue;
33 MPI_Comm_rank( comm, &rank );
34 MPI_Comm_size( comm, &size );
36 for (count = 1; count < 65000; count = count * 2) {
38 sendbuf = (int *)malloc( count * sizeof(int) );
39 recvbuf = (int *)malloc( count * sizeof(int) );
41 for (i=0; i<count; i++) {
42 sendbuf[i] = rank + i * size;
46 MPI_Exscan( sendbuf, recvbuf, count, MPI_INT, MPI_SUM, comm );
48 /* Check the results. rank 0 has no data */
51 for (i=0; i<count; i++) {
52 result = rank * i * size + ((rank) * (rank-1))/2;
53 if (recvbuf[i] != result) {
56 fprintf( stderr, "Error in recvbuf[%d] = %d on %d, expected %d\n",
57 i, recvbuf[i], rank, result );
63 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
64 /* now try the MPI_IN_PLACE flavor */
65 for (i=0; i<count; i++) {
66 sendbuf[i] = -1; /* unused */
67 recvbuf[i] = rank + i * size;
70 MPI_Exscan( MPI_IN_PLACE, recvbuf, count, MPI_INT, MPI_SUM, comm );
72 /* Check the results. rank 0's data must remain unchanged */
73 for (i=0; i<count; i++) {
76 result = rank + i * size;
78 result = rank * i * size + ((rank) * (rank-1))/2;
79 if (recvbuf[i] != result) {
82 fprintf( stderr, "Error in recvbuf[%d] = %d on %d, expected %d\n",
83 i, recvbuf[i], rank, result );
88 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
89 /* Make sure that we check for buffer aliasing properly */
90 if (MPI_SUCCESS == MPI_Exscan( recvbuf, recvbuf, count, MPI_INT, MPI_SUM, comm ))
97 MTestFreeComm( &comm );
100 MTest_Finalize( errs );