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 gatherv 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 while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
30 if (comm == MPI_COMM_NULL) continue;
31 MPI_Comm_rank( comm, &rank );
32 MPI_Comm_remote_size( comm, &rsize );
33 MPI_Comm_size( comm, &size );
35 /* To improve reporting of problems about operations, we
36 change the error handler to errors return */
37 MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
39 for (count = 1; count < 65000; count = 2 * count) {
40 /* Get an intercommunicator */
41 recvcounts = (int *)malloc( rsize * sizeof(int) );
42 recvdispls = (int *)malloc( rsize * sizeof(int) );
43 /* This simple test duplicates the Gather test,
44 using the same lengths for all messages */
45 for (i=0; i<rsize; i++) {
46 recvcounts[i] = count;
47 recvdispls[i] = count * i;
50 buf = (int *)malloc( count * rsize * sizeof(int) );
51 for (i=0; i<count*rsize; i++) buf[i] = -1;
53 err = MPI_Gatherv( NULL, 0, datatype,
54 buf, recvcounts, recvdispls, datatype,
55 (rank == 0) ? MPI_ROOT : MPI_PROC_NULL,
59 MTestPrintError( err );
61 /* Test that no other process in this group received the
64 for (i=0; i<count; i++) {
71 /* Check for the correct data */
72 for (i=0; i<count*rsize; i++) {
80 /* In the right group */
81 buf = (int *)malloc( count * sizeof(int) );
82 for (i=0; i<count; i++) buf[i] = rank * count + i;
83 err = MPI_Gatherv( buf, count, datatype,
84 NULL, 0, 0, datatype, 0, comm );
87 MTestPrintError( err );
94 MTestFreeComm( &comm );
97 MTest_Finalize( errs );