1 /* -*- Mode: c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2011 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
12 /* Tests MPI_Get_elements with a contiguous datatype that triggered a bug in
13 * past versions of MPICH. See ticket #1467 for more info. */
21 int main(int argc, char **argv)
24 struct test_struct sendbuf, recvbuf;
27 MPI_Datatype types[3];
28 MPI_Datatype struct_type, contig;
31 MPI_Init(&argc, &argv);
32 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
34 /* We use a contig of a struct in order to satisfy two properties:
35 * (A) a type that contains more than one element type (the struct portion)
36 * (B) a type that has an odd number of ints in its "type contents" (1 in
38 * This triggers a specific bug in some versions of MPICH. */
40 displs[0] = offsetof(struct test_struct, a);
43 displs[1] = offsetof(struct test_struct, b);
46 displs[2] = offsetof(struct test_struct, c);
48 MPI_Type_create_struct(3, blens, displs, types, &struct_type);
49 MPI_Type_contiguous(1, struct_type, &contig);
50 MPI_Type_commit(&struct_type);
51 MPI_Type_commit(&contig);
61 MPI_Sendrecv(&sendbuf, 1, contig, 0, 0,
62 &recvbuf, 1, contig, 0, 0,
63 MPI_COMM_SELF, &status);
66 assert(sendbuf.a == recvbuf.a);
67 assert(sendbuf.b == recvbuf.b);
68 assert(sendbuf.c == recvbuf.c);
70 /* now check that MPI_Get_elements returns the correct answer and that the
71 * library doesn't explode in the process */
73 MPI_Get_elements(&status, contig, &count);
74 MPI_Type_free(&struct_type);
75 MPI_Type_free(&contig);
78 printf("unexpected value for count, expected 3, got %d\n", count);
82 printf(" No Errors\n");