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 scatter test";
16 int main( int argc, char *argv[] )
20 int leftGroup, i, count, rank, size, rsize;
22 MPI_Datatype datatype;
24 MTest_Init( &argc, &argv );
27 /* Get an intercommunicator */
28 while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
29 if (comm == MPI_COMM_NULL) continue;
30 MPI_Comm_remote_size( comm, &rsize );
31 MPI_Comm_rank( comm, &rank );
32 MPI_Comm_size( comm, &size );
34 /* To improve reporting of problems about operations, we
35 change the error handler to errors return */
36 MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
38 for (count = 1; count < 65000; count = 2 * count) {
41 buf = (int *)malloc( count * rsize * sizeof(int) );
43 for (i=0; i<count*rsize; i++) buf[i] = i;
46 for (i=0; i<count*rsize; i++) buf[i] = -1;
48 err = MPI_Scatter( buf, count, datatype,
50 (rank == 0) ? MPI_ROOT : MPI_PROC_NULL,
54 MTestPrintError( err );
56 /* Test that no other process in this group received the
59 for (i=0; i<count*rsize; i++) {
62 fprintf( stderr, "Received data on root group!\n" );
70 buf = (int *)malloc( count * sizeof(int) );
71 /* In the right group */
72 for (i=0; i<count; i++) buf[i] = -1;
73 err = MPI_Scatter( NULL, 0, datatype,
74 buf, count, datatype, 0, comm );
77 MTestPrintError( err );
79 /* Check that we have received the correct data */
80 for (i=0; i<count; i++) {
81 if (buf[i] != i + rank * count) {
83 fprintf( stderr, "buf[%d] = %d on %d\n",
91 MTestFreeComm( &comm );
94 MTest_Finalize( errs );