Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix HAVE_FOOBAR flags handling
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / struct-zero-count.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "mpitestconf.h"
10 #ifdef HAVE_STRING_H
11 #include <string.h>
12 #endif
13
14 static int verbose = 0;
15
16 /* tests */
17 int builtin_struct_test(void);
18
19 /* helper functions */
20 int parse_args(int argc, char **argv);
21
22 int main(int argc, char **argv)
23 {
24     int err, errs = 0;
25
26     MPI_Init(&argc, &argv); /* MPI-1.2 doesn't allow for MPI_Init(0,0) */
27     parse_args(argc, argv);
28
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 );
32
33     /* perform some tests */
34     err = builtin_struct_test();
35     if (err && verbose) fprintf(stderr, "%d errors in builtin struct test.\n", err);
36     errs += err;
37
38     /* print message and exit */
39     if (errs) {
40         fprintf(stderr, "Found %d errors\n", errs);
41     }
42     else {
43         printf(" No Errors\n");
44     }
45     MPI_Finalize();
46     return 0;
47 }
48
49 /* builtin_struct_test()
50  *
51  * Tests behavior with a zero-count struct of builtins.
52  *
53  * Returns the number of errors encountered.
54  */
55 int builtin_struct_test(void)
56 {
57     int err, errs = 0;
58
59     int count = 0;
60     MPI_Datatype newtype;
61
62     int size;
63     MPI_Aint extent;
64
65     err = MPI_Type_create_struct(count,
66                                  (int *) 0,
67                                  (MPI_Aint *) 0,
68                                  (MPI_Datatype *) 0,
69                                  &newtype);
70     if (err != MPI_SUCCESS) {
71         if (verbose) {
72             fprintf(stderr,
73                     "error creating struct type in builtin_struct_test()\n");
74         }
75         errs++;
76     }
77
78     err = MPI_Type_size(newtype, &size);
79     if (err != MPI_SUCCESS) {
80         if (verbose) {
81             fprintf(stderr,
82                     "error obtaining type size in builtin_struct_test()\n");
83         }
84         errs++;
85     }
86     
87     if (size != 0) {
88         if (verbose) {
89             fprintf(stderr,
90                     "error: size != 0 in builtin_struct_test()\n");
91         }
92         errs++;
93     }    
94
95     err = MPI_Type_extent(newtype, &extent);
96     if (err != MPI_SUCCESS) {
97         if (verbose) {
98             fprintf(stderr,
99                     "error obtaining type extent in builtin_struct_test()\n");
100         }
101         errs++;
102     }
103     
104     if (extent != 0) {
105         if (verbose) {
106             fprintf(stderr,
107                     "error: extent != 0 in builtin_struct_test()\n");
108         }
109         errs++;
110     }    
111
112     MPI_Type_free( &newtype );
113
114     return errs;
115 }
116
117
118 int parse_args(int argc, char **argv)
119 {
120     /*
121     int ret;
122
123     while ((ret = getopt(argc, argv, "v")) >= 0)
124     {
125         switch (ret) {
126             case 'v':
127                 verbose = 1;
128                 break;
129         }
130     }
131     */
132     if (argc > 1 && strcmp(argv[1], "-v") == 0)
133         verbose = 1;
134     return 0;
135 }
136