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 /* Gather data from a vector to contiguous */
15 int main( int argc, char **argv )
19 double *vecin, *vecout;
20 int minsize = 2, count;
21 int root, i, n, stride, errs = 0;
24 MTest_Init( &argc, &argv );
26 while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
27 if (comm == MPI_COMM_NULL) continue;
28 /* Determine the sender and receiver */
29 MPI_Comm_rank( comm, &rank );
30 MPI_Comm_size( comm, &size );
32 for (root=0; root<size; root++) {
33 for (count = 1; count < 65000; count = count * 2) {
36 vecin = (double *)malloc( n * stride * size * sizeof(double) );
37 vecout = (double *)malloc( size * n * sizeof(double) );
39 MPI_Type_vector( n, 1, stride, MPI_DOUBLE, &vec );
40 MPI_Type_commit( &vec );
42 for (i=0; i<n*stride; i++) vecin[i] =-2;
43 for (i=0; i<n; i++) vecin[i*stride] = rank * n + i;
45 MPI_Gather( vecin, 1, vec, vecout, n, MPI_DOUBLE, root, comm );
48 for (i=0; i<n*size; i++) {
52 fprintf( stderr, "vecout[%d]=%d\n",
58 MPI_Type_free( &vec );
63 MTestFreeComm( &comm );
66 /* do a zero length gather */
67 MPI_Gather( NULL, 0, MPI_BYTE, NULL, 0, MPI_BYTE, 0, MPI_COMM_WORLD );
69 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
70 /* Check to make sure that aliasing is disallowed correctly */
71 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
72 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
74 if (MPI_SUCCESS == MPI_Gather(&rank, 1, MPI_INT,
75 &rank, 1, MPI_INT, 0, MPI_COMM_WORLD))
79 MTest_Finalize( errs );