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 /* This example sends a vector and receives individual elements, but the
14 root process does not receive any data */
16 int main( int argc, char **argv )
19 double *vecin, *vecout, ivalue;
20 int root, i, n, stride, err = 0;
24 MTest_Init( &argc, &argv );
26 MPI_Comm_size( MPI_COMM_WORLD, &size );
27 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
31 vecin = (double *)malloc( n * stride * size * sizeof(double) );
32 vecout = (double *)malloc( n * sizeof(double) );
34 MPI_Type_vector( n, 1, stride, MPI_DOUBLE, &vec );
35 MPI_Type_commit( &vec );
36 MPI_Type_extent( vec, &vextent );
37 if (vextent != ((n-1)*(MPI_Aint)stride + 1) * sizeof(double) ) {
39 printf( "Vector extent is %ld, should be %ld\n",
40 (long) vextent, (long)(((n-1)*stride+1)*sizeof(double)) );
42 /* Note that the exted of type vector is from the first to the
43 last element, not n*stride.
44 E.g., with n=1, the extent is a single double */
46 for (i=0; i<n*stride*size; i++) vecin[i] = (double)i;
47 for (root=0; root<size; root++) {
48 for (i=0; i<n; i++) vecout[i] = -1.0;
50 MPI_Scatter( vecin, 1, vec, MPI_IN_PLACE, -1, MPI_DATATYPE_NULL,
51 root, MPI_COMM_WORLD );
54 MPI_Scatter( NULL, -1, MPI_DATATYPE_NULL, vecout, n, MPI_DOUBLE,
55 root, MPI_COMM_WORLD );
56 ivalue = rank * ((n-1) * stride + 1);
58 if (vecout[i] != ivalue) {
59 printf( "[%d] Expected %f but found %f for vecout[%d]\n",
60 rank, ivalue, vecout[i], i );
68 MTest_Finalize( err );
69 MPI_Type_free( &vec );