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 != (MPI_Aint)(((n - 1) * 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++)
47 vecin[i] = (double) i;
48 for (root = 0; root < size; root++) {
49 for (i = 0; i < n; i++)
52 MPI_Scatter(vecin, 1, vec, MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, root, MPI_COMM_WORLD);
55 MPI_Scatter(NULL, -1, MPI_DATATYPE_NULL, vecout, n, MPI_DOUBLE, root, MPI_COMM_WORLD);
56 ivalue = rank * ((n - 1) * stride + 1);
57 for (i = 0; i < n; i++) {
58 if (vecout[i] != ivalue) {
59 printf("[%d] Expected %f but found %f for vecout[%d]\n",
60 rank, ivalue, vecout[i], i);