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();
36 fprintf(stderr, "error in single_struct_test\n");
39 /* print message and exit */
41 fprintf(stderr, "Found %d errors\n", errs);
44 printf(" No Errors\n");
50 int single_struct_test(void)
54 int sendbuf[6] = { 1, 2, 3, 4, 5, 6 };
55 struct test_struct_1 ts1[2];
56 MPI_Datatype mystruct;
60 /* note: first element of struct has zero blklen and should be dropped */
61 MPI_Aint disps[3] = { 2 * sizeof(float), 0, 2 * sizeof(int) };
62 int blks[3] = { 0, 1, 2 };
63 MPI_Datatype types[3] = { MPI_FLOAT, MPI_INT, MPI_INT };
75 err = MPI_Type_struct(3, blks, disps, types, &mystruct);
76 if (err != MPI_SUCCESS) {
79 fprintf(stderr, "MPI_Type_struct returned error\n");
83 MPI_Type_commit(&mystruct);
85 err = MPI_Irecv(ts1, 2, mystruct, 0, 0, MPI_COMM_SELF, &request);
86 if (err != MPI_SUCCESS) {
89 fprintf(stderr, "MPI_Irecv returned error\n");
93 err = MPI_Send(sendbuf, 6, MPI_INT, 0, 0, MPI_COMM_SELF);
94 if (err != MPI_SUCCESS) {
97 fprintf(stderr, "MPI_Send returned error\n");
101 err = MPI_Wait(&request, &status);
102 if (err != MPI_SUCCESS) {
105 fprintf(stderr, "MPI_Wait returned error\n");
113 fprintf(stderr, "ts1[0].a = %d; should be %d\n", ts1[0].a, 1);
116 if (ts1[0].b != -1) {
119 fprintf(stderr, "ts1[0].b = %d; should be %d\n", ts1[0].b, -1);
125 fprintf(stderr, "ts1[0].c = %d; should be %d\n", ts1[0].c, 2);
131 fprintf(stderr, "ts1[0].d = %d; should be %d\n", ts1[0].d, 3);
137 fprintf(stderr, "ts1[1].a = %d; should be %d\n", ts1[1].a, 4);
140 if (ts1[1].b != -1) {
143 fprintf(stderr, "ts1[1].b = %d; should be %d\n", ts1[1].b, -1);
149 fprintf(stderr, "ts1[1].c = %d; should be %d\n", ts1[1].c, 5);
155 fprintf(stderr, "ts1[1].d = %d; should be %d\n", ts1[1].d, 6);
159 /* verify count and elements */
160 err = MPI_Get_count(&status, mystruct, &count);
161 if (err != MPI_SUCCESS) {
164 fprintf(stderr, "MPI_Get_count returned error\n");
170 fprintf(stderr, "count = %d; should be 2\n", count);
174 err = MPI_Get_elements(&status, mystruct, &elements);
175 if (err != MPI_SUCCESS) {
178 fprintf(stderr, "MPI_Get_elements returned error\n");
184 fprintf(stderr, "elements = %d; should be 6\n", elements);
188 MPI_Type_free(&mystruct);
194 int parse_args(int argc, char **argv)
199 * while ((ret = getopt(argc, argv, "v")) >= 0)
208 if (argc > 1 && strcmp(argv[1], "-v") == 0)