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 parse_args(int argc, char **argv);
15 int single_struct_test(void);
17 struct test_struct_1 {
21 int main(int argc, char *argv[])
26 MPI_Init(&argc, &argv);
27 parse_args(argc, argv);
29 /* To improve reporting of problems about operations, we
30 change the error handler to errors return */
31 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
33 err = single_struct_test();
34 if (verbose && err) fprintf(stderr, "error in single_struct_test\n");
37 /* print message and exit */
39 fprintf(stderr, "Found %d errors\n", errs);
42 printf(" No Errors\n");
48 int single_struct_test(void)
52 int sendbuf[6] = { 1, 2, 3, 4, 5, 6 };
53 struct test_struct_1 ts1[2];
54 MPI_Datatype mystruct;
58 /* note: first element of struct has zero blklen and should be dropped */
59 MPI_Aint disps[3] = { 2*sizeof(float), 0, 2*sizeof(int) };
60 int blks[3] = { 0, 1, 2 };
61 MPI_Datatype types[3] = { MPI_FLOAT, MPI_INT, MPI_INT };
73 err = MPI_Type_struct(3, blks, disps, types, &mystruct);
74 if (err != MPI_SUCCESS) {
77 fprintf(stderr, "MPI_Type_struct returned error\n");
81 MPI_Type_commit(&mystruct);
83 err = MPI_Irecv(ts1, 2, mystruct, 0, 0, MPI_COMM_SELF, &request);
84 if (err != MPI_SUCCESS) {
87 fprintf(stderr, "MPI_Irecv returned error\n");
91 err = MPI_Send(sendbuf, 6, MPI_INT, 0, 0, MPI_COMM_SELF);
92 if (err != MPI_SUCCESS) {
95 fprintf(stderr, "MPI_Send returned error\n");
99 err = MPI_Wait(&request, &status);
100 if (err != MPI_SUCCESS) {
103 fprintf(stderr, "MPI_Wait returned error\n");
111 fprintf(stderr, "ts1[0].a = %d; should be %d\n", ts1[0].a, 1);
114 if (ts1[0].b != -1) {
117 fprintf(stderr, "ts1[0].b = %d; should be %d\n", ts1[0].b, -1);
123 fprintf(stderr, "ts1[0].c = %d; should be %d\n", ts1[0].c, 2);
129 fprintf(stderr, "ts1[0].d = %d; should be %d\n", ts1[0].d, 3);
135 fprintf(stderr, "ts1[1].a = %d; should be %d\n", ts1[1].a, 4);
138 if (ts1[1].b != -1) {
141 fprintf(stderr, "ts1[1].b = %d; should be %d\n", ts1[1].b, -1);
147 fprintf(stderr, "ts1[1].c = %d; should be %d\n", ts1[1].c, 5);
153 fprintf(stderr, "ts1[1].d = %d; should be %d\n", ts1[1].d, 6);
157 /* verify count and elements */
158 err = MPI_Get_count(&status, mystruct, &count);
159 if (err != MPI_SUCCESS) {
162 fprintf(stderr, "MPI_Get_count returned error\n");
168 fprintf(stderr, "count = %d; should be 2\n", count);
172 err = MPI_Get_elements(&status, mystruct, &elements);
173 if (err != MPI_SUCCESS) {
176 fprintf(stderr, "MPI_Get_elements returned error\n");
182 fprintf(stderr, "elements = %d; should be 6\n", elements);
186 MPI_Type_free(&mystruct);
192 int parse_args(int argc, char **argv)
197 while ((ret = getopt(argc, argv, "v")) >= 0)
206 if (argc > 1 && strcmp(argv[1], "-v") == 0)