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[] = "";
16 int main( int argc, char *argv[] )
20 int minsize = 2, count;
22 int *sendbuf, *recvbuf, *p;
23 int sendcount, recvcount;
25 MPI_Datatype sendtype, recvtype;
27 MTest_Init( &argc, &argv );
29 /* The following illustrates the use of the routines to
30 run through a selection of communicators and datatypes.
31 Use subsets of these for tests that do not involve combinations
32 of communicators, datatypes, and counts of datatypes */
33 while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
34 if (comm == MPI_COMM_NULL) continue;
36 /* Determine the sender and receiver */
37 MPI_Comm_rank( comm, &rank );
38 MPI_Comm_size( comm, &size );
40 /* printf( "Size of comm = %d\n", size ); */
41 for (count = 1; count < 65000; count = count * 2) {
43 /* Create a send buf and a receive buf suitable for testing
47 sendbuf = (int *)malloc( count * size * sizeof(int) );
48 recvbuf = (int *)malloc( count * size * sizeof(int) );
52 if (!sendbuf || !recvbuf) {
54 fprintf( stderr, "Failed to allocate sendbuf and/or recvbuf\n" );
55 MPI_Abort( MPI_COMM_WORLD, 1 );
58 for (i=0; i<count*size; i++)
61 for (j=0; j<size; j++) {
62 for (i=0; i<count; i++) {
63 *p++ = j * size + rank + i;
67 MPI_Alltoall( sendbuf, sendcount, sendtype,
68 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) {
102 fprintf( stderr, "Error (MPI_IN_PLACE) with communicator %s and size=%d count=%d\n",
103 MTestGetIntracommName(), size, count );
104 fprintf(stderr, "recvbuf[%d,%d] = %d, should be %d\n",
105 j,i, *p, rank * size + j + i );
116 MTestFreeComm( &comm );
119 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
120 /* Check to make sure that aliasing is disallowed correctly */
121 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
122 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
123 if (MPI_SUCCESS == MPI_Alltoall(&rank, 1, MPI_INT, &rank, 1, MPI_INT, MPI_COMM_WORLD))
127 MTest_Finalize( errs );