2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) */
4 /* type-no-error-exhaustive-with-isends.c -- send with weird types */
8 "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/partial-recv.c,v 1.1 2002/10/24 17:04:56 bronis Exp $";
17 typedef struct _test_small_struct_t
25 typedef struct _test_big_struct_t
29 double the_other_double;
38 main (int argc, char **argv)
42 MPI_Comm comm = MPI_COMM_WORLD;
43 char processor_name[128];
46 MPI_Aint basic_extent;
49 MPI_Datatype structtypes[3];
50 MPI_Datatype newtype[2];
52 MPI_Status aStatus[2];
53 test_small_struct_t small_struct_buf[SMALL_SIZE];
54 test_big_struct_t big_struct_buf[BIG_SIZE];
57 MPI_Init (&argc, &argv);
58 MPI_Comm_size (comm, &nprocs);
59 MPI_Comm_rank (comm, &rank);
60 MPI_Get_processor_name (processor_name, &namelen);
61 printf ("(%d) is alive on %s\n", rank, processor_name);
64 structtypes[0] = MPI_DOUBLE;
65 structtypes[1] = MPI_CHAR;
66 structtypes[2] = MPI_DOUBLE;
67 blocklens[0] = blocklens[1] = blocklens[2] = 1;
69 displs[1] = sizeof(double);
71 ((void *) &(big_struct_buf[0].the_other_double)) -
72 ((void *) big_struct_buf);
74 if (displs[2] < 0) displs[2] = -displs[2];
78 /* create the types */
79 MPI_Type_struct (2, blocklens, displs, structtypes, &newtype[0]);
80 MPI_Type_struct (3, blocklens, displs, structtypes, &newtype[1]);
82 MPI_Type_extent (newtype[0], &basic_extent);
83 if (basic_extent != sizeof (test_small_struct_t)) {
84 fprintf (stderr, "(%d): Unexpected extent for small struct\n", rank);
85 MPI_Abort (MPI_COMM_WORLD, 666);
88 MPI_Type_extent (newtype[1], &basic_extent);
89 if (basic_extent != sizeof (test_big_struct_t)) {
90 fprintf (stderr, "(%d): Unexpected extent for big struct\n", rank);
91 MPI_Abort (MPI_COMM_WORLD, 666);
94 MPI_Type_commit (&newtype[0]);
95 MPI_Type_commit (&newtype[1]);
98 /* initialize buffers */
99 for (i = 0; i < SMALL_SIZE; i++) {
100 small_struct_buf[i].the_double = 1.0;
101 small_struct_buf[i].the_char = 'a';
104 for (i = 0; i < BIG_SIZE; i++) {
105 big_struct_buf[i].the_double = 1.0;
106 big_struct_buf[i].the_char = 'a';
107 big_struct_buf[i].the_other_double = 1.0;
110 /* set up the sends */
111 MPI_Isend (small_struct_buf, 1, newtype[0], 1, 0, comm, &aReq[0]);
112 MPI_Isend (big_struct_buf, 1, newtype[1], 1, 1, comm, &aReq[1]);
114 else if (rank == 1) {
115 /* initialize buffers */
116 for (i = 0; i < SMALL_SIZE; i++) {
117 small_struct_buf[i].the_double = 2.0;
118 small_struct_buf[i].the_char = 'b';
121 for (i = 0; i < BIG_SIZE; i++) {
122 big_struct_buf[i].the_double = 2.0;
123 big_struct_buf[i].the_char = 'b';
124 big_struct_buf[i].the_other_double = 2.0;
127 /* set up the receives... */
128 MPI_Irecv (big_struct_buf, BIG_SIZE, newtype[1],0,0, comm, &aReq[0]);
129 MPI_Irecv (small_struct_buf, SMALL_SIZE, newtype[0],0,1, comm, &aReq[1]);
132 if ((rank == 0) || (rank == 1)) {
133 /* wait on everything... */
134 MPI_Waitall (2, aReq, aStatus);
137 for (i = 0; i < 2; i++) {
138 MPI_Type_free (&newtype[i]);
143 printf ("(%d) Finished normally\n", rank);