1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
12 static int verbose = 0;
14 int main(int argc, char *argv[]);
15 int parse_args(int argc, char **argv);
16 int single_struct_test(void);
18 struct test_struct_1 {
22 int main(int argc, char *argv[])
27 MPI_Init(&argc, &argv);
28 parse_args(argc, argv);
30 /* To improve reporting of problems about operations, we
31 change the error handler to errors return */
32 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
34 err = single_struct_test();
35 if (verbose && err) fprintf(stderr, "error in single_struct_test\n");
38 /* print message and exit */
40 fprintf(stderr, "Found %d errors\n", errs);
43 printf(" No Errors\n");
49 int single_struct_test(void)
53 int sendbuf[6] = { 1, 2, 3, 4, 5, 6 };
54 struct test_struct_1 ts1[2];
55 MPI_Datatype mystruct;
59 /* note: first element of struct has zero blklen and should be dropped */
60 MPI_Aint disps[3] = { 2*sizeof(float), 0, 2*sizeof(int) };
61 int blks[3] = { 0, 1, 2 };
62 MPI_Datatype types[3] = { MPI_FLOAT, MPI_INT, MPI_INT };
74 err = MPI_Type_struct(3, blks, disps, types, &mystruct);
75 if (err != MPI_SUCCESS) {
78 fprintf(stderr, "MPI_Type_struct returned error\n");
82 MPI_Type_commit(&mystruct);
84 err = MPI_Irecv(ts1, 2, mystruct, 0, 0, MPI_COMM_SELF, &request);
85 if (err != MPI_SUCCESS) {
88 fprintf(stderr, "MPI_Irecv returned error\n");
92 err = MPI_Send(sendbuf, 6, MPI_INT, 0, 0, MPI_COMM_SELF);
93 if (err != MPI_SUCCESS) {
96 fprintf(stderr, "MPI_Send returned error\n");
100 err = MPI_Wait(&request, &status);
101 if (err != MPI_SUCCESS) {
104 fprintf(stderr, "MPI_Wait returned error\n");
112 fprintf(stderr, "ts1[0].a = %d; should be %d\n", ts1[0].a, 1);
115 if (ts1[0].b != -1) {
118 fprintf(stderr, "ts1[0].b = %d; should be %d\n", ts1[0].b, -1);
124 fprintf(stderr, "ts1[0].c = %d; should be %d\n", ts1[0].c, 2);
130 fprintf(stderr, "ts1[0].d = %d; should be %d\n", ts1[0].d, 3);
136 fprintf(stderr, "ts1[1].a = %d; should be %d\n", ts1[1].a, 4);
139 if (ts1[1].b != -1) {
142 fprintf(stderr, "ts1[1].b = %d; should be %d\n", ts1[1].b, -1);
148 fprintf(stderr, "ts1[1].c = %d; should be %d\n", ts1[1].c, 5);
154 fprintf(stderr, "ts1[1].d = %d; should be %d\n", ts1[1].d, 6);
158 /* verify count and elements */
159 err = MPI_Get_count(&status, mystruct, &count);
160 if (err != MPI_SUCCESS) {
163 fprintf(stderr, "MPI_Get_count returned error\n");
169 fprintf(stderr, "count = %d; should be 2\n", count);
173 err = MPI_Get_elements(&status, mystruct, &elements);
174 if (err != MPI_SUCCESS) {
177 fprintf(stderr, "MPI_Get_elements returned error\n");
183 fprintf(stderr, "elements = %d; should be 6\n", elements);
187 MPI_Type_free(&mystruct);
193 int parse_args(int argc, char **argv)
198 while ((ret = getopt(argc, argv, "v")) >= 0)
207 if (argc > 1 && strcmp(argv[1], "-v") == 0)