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[] = "Simple intercomm alltoall test";
16 int main( int argc, char *argv[] )
19 int *sendbuf = 0, *recvbuf = 0;
20 int leftGroup, i, j, idx, count, rrank, rsize;
22 MPI_Datatype datatype;
24 MTest_Init( &argc, &argv );
27 while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
28 if (comm == MPI_COMM_NULL) continue;
29 for (count = 1; count < 66000; count = 2 * count) {
30 /* Get an intercommunicator */
31 MPI_Comm_remote_size( comm, &rsize );
32 MPI_Comm_rank( comm, &rrank );
33 sendbuf = (int *)malloc( rsize * count * sizeof(int) );
34 recvbuf = (int *)malloc( rsize * count * sizeof(int) );
35 for (i=0; i<rsize*count; i++) recvbuf[i] = -1;
38 for (j=0; j<rsize; j++) {
39 for (i=0; i<count; i++) {
40 sendbuf[idx++] = i + rrank;
43 err = MPI_Alltoall( sendbuf, count, datatype,
44 NULL, 0, datatype, comm );
47 MTestPrintError( err );
53 MPI_Comm_rank( comm, &rank );
54 MPI_Comm_size( comm, &size );
56 /* In the right group */
57 err = MPI_Alltoall( NULL, 0, datatype,
58 recvbuf, count, datatype, comm );
61 MTestPrintError( err );
63 /* Check that we have received the correct data */
65 for (j=0; j<rsize; j++) {
66 for (i=0; i<count; i++) {
67 if (recvbuf[idx++] != i + j) {
70 fprintf( stderr, "buf[%d] = %d on %d\n",
71 i, recvbuf[i], rank );
79 MTestFreeComm( &comm );
82 MTest_Finalize( errs );