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 scatterv test";
16 int main( int argc, char *argv[] )
22 int leftGroup, i, count, rank, rsize, size;
24 MPI_Datatype datatype;
26 MTest_Init( &argc, &argv );
29 /* Get an intercommunicator */
30 while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
31 if (comm == MPI_COMM_NULL) continue;
32 MPI_Comm_remote_size( comm, &rsize );
33 MPI_Comm_rank( comm, &rank );
34 MPI_Comm_size( comm, &size );
36 /* To improve reporting of problems about operations, we
37 change the error handler to errors return */
38 MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
40 for (count = 1; count < 65000; count = 2 * count) {
42 sendcounts = (int *)malloc( rsize * sizeof(int) );
43 senddispls = (int *)malloc( rsize * sizeof(int) );
44 for (i=0; i<rsize; i++) {
45 sendcounts[i] = count;
46 senddispls[i] = count * i;
49 buf = (int *)malloc( count * rsize * sizeof(int) );
51 for (i=0; i<count*rsize; i++) buf[i] = i;
54 for (i=0; i<count*rsize; i++) buf[i] = -1;
56 err = MPI_Scatterv( buf, sendcounts, senddispls, datatype,
58 (rank == 0) ? MPI_ROOT : MPI_PROC_NULL,
62 MTestPrintError( err );
64 /* Test that no other process in this group received the
67 for (i=0; i<count*rsize; i++) {
70 fprintf( stderr, "Received data on root group!\n" );
78 buf = (int *)malloc( count * sizeof(int) );
79 /* In the right group */
80 for (i=0; i<count; i++) buf[i] = -1;
81 err = MPI_Scatterv( NULL, 0, 0, datatype,
82 buf, count, datatype, 0, comm );
85 MTestPrintError( err );
87 /* Check that we have received the correct data */
88 for (i=0; i<count; i++) {
89 if (buf[i] != i + rank * count) {
91 fprintf( stderr, "buf[%d] = %d on %d\n",
101 MTestFreeComm( &comm );
104 MTest_Finalize( errs );