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 int comm = MPI_COMM_WORLD;
43 char processor_name[128];
46 int blocklens[3], displs[3];
47 MPI_Datatype structtypes[3];
48 MPI_Datatype newtype[2];
50 MPI_Status aStatus[2];
51 test_small_struct_t small_struct_buf[SMALL_SIZE];
52 test_big_struct_t big_struct_buf[BIG_SIZE];
55 MPI_Init (&argc, &argv);
56 MPI_Comm_size (comm, &nprocs);
57 MPI_Comm_rank (comm, &rank);
58 MPI_Get_processor_name (processor_name, &namelen);
59 printf ("(%d) is alive on %s\n", rank, processor_name);
62 structtypes[0] = MPI_DOUBLE;
63 structtypes[1] = MPI_CHAR;
64 structtypes[2] = MPI_DOUBLE;
65 blocklens[0] = blocklens[1] = blocklens[2] = 1;
67 displs[1] = sizeof(double);
69 ((void *) &(big_struct_buf[0].the_other_double)) -
70 ((void *) big_struct_buf);
72 if (displs[2] < 0) displs[2] = -displs[2];
76 /* create the types */
77 MPI_Type_struct (2, blocklens, displs, structtypes, &newtype[0]);
78 MPI_Type_struct (3, blocklens, displs, structtypes, &newtype[1]);
80 MPI_Type_extent (newtype[0], &basic_extent);
81 if (basic_extent != sizeof (test_small_struct_t)) {
82 fprintf (stderr, "(%d): Unexpected extent for small struct\n");
83 MPI_Abort (MPI_COMM_WORLD, 666);
86 MPI_Type_extent (newtype[1], &basic_extent);
87 if (basic_extent != sizeof (test_big_struct_t)) {
88 fprintf (stderr, "(%d): Unexpected extent for big struct\n");
89 MPI_Abort (MPI_COMM_WORLD, 666);
92 MPI_Type_commit (&newtype[0]);
93 MPI_Type_commit (&newtype[1]);
96 /* initialize buffers */
97 for (i = 0; i < SMALL_SIZE; i++) {
98 small_struct_buf[i].the_double = 1.0;
99 small_struct_buf[i].the_char = 'a';
102 for (i = 0; i < BIG_SIZE; i++) {
103 big_struct_buf[i].the_double = 1.0;
104 big_struct_buf[i].the_char = 'a';
105 big_struct_buf[i].the_other_double = 1.0;
108 /* set up the sends */
109 MPI_Isend (small_struct_buf, 1, newtype[0], 1, 0, comm, &aReq[0]);
110 MPI_Isend (big_struct_buf, 1, newtype[1], 1, 1, comm, &aReq[1]);
112 else if (rank == 1) {
113 /* initialize buffers */
114 for (i = 0; i < SMALL_SIZE; i++) {
115 small_struct_buf[i].the_double = 2.0;
116 small_struct_buf[i].the_char = 'b';
119 for (i = 0; i < BIG_SIZE; i++) {
120 big_struct_buf[i].the_double = 2.0;
121 big_struct_buf[i].the_char = 'b';
122 big_struct_buf[i].the_other_double = 2.0;
125 /* set up the receives... */
126 MPI_Irecv (big_struct_buf, BIG_SIZE, newtype[1],0,0, comm, &aReq[0]);
127 MPI_Irecv (small_struct_buf, SMALL_SIZE, newtype[0],0,1, comm, &aReq[1]);
130 if ((rank == 0) || (rank == 1)) {
131 /* wait on everything... */
132 MPI_Waitall (2, aReq, aStatus);
135 for (i = 0; i < 2; i++) {
136 MPI_Type_free (&newtype[i]);
141 printf ("(%d) Finished normally\n", rank);