1 /* Copyright (c) 2012-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 int main(int argc, char **argv)
13 struct { int a;int c; double b;int tab[2][3];} value;
14 MPI_Datatype mystruct;
17 MPI_Datatype old_types[3];
20 MPI_Init( &argc, &argv );
22 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
24 int tab[2][3]={{1*rank,2*rank,3*rank},{7*rank,8*rank,9*rank}};
25 MPI_Type_contiguous(3, MPI_INT, &type2);
26 MPI_Type_commit(&type2);
28 /* One value of each type, and two for the contiguous one */
33 old_types[0] = MPI_INT;
34 old_types[1] = MPI_DOUBLE;
36 /* The locations of each element */
37 MPI_Address( &value.a, &indices[0] );
38 MPI_Address( &value.b, &indices[1] );
39 MPI_Address( &tab, &indices[2] );
41 indices[2] = indices[2] - indices[0];
42 indices[1] = indices[1] - indices[0];
45 MPI_Type_struct( 3, blocklens, indices, old_types, &mystruct );
46 MPI_Type_commit( &mystruct );
56 MPI_Bcast( &value, 1, mystruct, 0, MPI_COMM_WORLD );
58 printf( "Process %d got %d (-2?) and %f (8.0?), tab (should be all 0): ", rank, value.a, value.b );
60 for (int j = 0; j < 2; j++)
61 for (int i = 0; i < 3; i++)
62 printf("%d ", tab[j][i]);
65 /* Clean up the type */
66 MPI_Type_free(&mystruct);
67 MPI_Type_free(&type2);