1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2015 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
12 /* Allgather a two-field struct datatype. This test
13 may trigger bugs such as when the implementation
14 does not handle well misaligned types.*/
21 int main(int argc, char **argv)
30 MPI_Aint displacements[2];
31 MPI_Datatype types[] = { MPI_INT, MPI_LONG };
32 int blocklength[2] = { 1, 1 };
33 int_long_t* gathered_objects;
35 MTest_Init(&argc, &argv);
37 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
39 if (comm == MPI_COMM_NULL)
41 /* Determine the sender and receiver */
42 MPI_Comm_rank(comm, &rank);
43 MPI_Comm_size(comm, &size);
45 gathered_objects = (int_long_t*) malloc (size*sizeof(int_long_t));
49 object.second = rank * 10;
51 /* Datatype creation */
52 MPI_Get_address(&object, &begin);
53 MPI_Get_address(&object.first, &displacements[0]);
54 MPI_Get_address(&object.second, &displacements[1]);
56 for (i = 0; i != 2; ++i)
57 displacements[i] -= begin;
59 MPI_Type_create_struct(2, &blocklength[0], &displacements[0], &types[0], &type);
60 MPI_Type_commit(&type);
62 MPI_Allgather(&object, 1, type, gathered_objects, 1, type, comm);
64 for (i = 0; i < size; i++) {
65 if (gathered_objects[i].first != i || gathered_objects[i].second != i * 10)
71 free(gathered_objects);