Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[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)
36         fprintf(stderr, "%d errors in builtin struct test.\n", err);
37     errs += err;
38
39     /* print message and exit */
40     if (errs) {
41         fprintf(stderr, "Found %d errors\n", errs);
42     }
43     else {
44         printf(" No Errors\n");
45     }
46     MPI_Finalize();
47     return 0;
48 }
49
50 /* builtin_struct_test()
51  *
52  * Tests behavior with a zero-count struct of builtins.
53  *
54  * Returns the number of errors encountered.
55  */
56 int builtin_struct_test(void)
57 {
58     int err, errs = 0;
59
60     int count = 0;
61     MPI_Datatype newtype;
62
63     int size;
64     MPI_Aint extent;
65
66     err = MPI_Type_create_struct(count, (int *) 0, (MPI_Aint *) 0, (MPI_Datatype *) 0, &newtype);
67     if (err != MPI_SUCCESS) {
68         if (verbose) {
69             fprintf(stderr, "error creating struct type in builtin_struct_test()\n");
70         }
71         errs++;
72     }
73
74     err = MPI_Type_size(newtype, &size);
75     if (err != MPI_SUCCESS) {
76         if (verbose) {
77             fprintf(stderr, "error obtaining type size in builtin_struct_test()\n");
78         }
79         errs++;
80     }
81
82     if (size != 0) {
83         if (verbose) {
84             fprintf(stderr, "error: size != 0 in builtin_struct_test()\n");
85         }
86         errs++;
87     }
88
89     err = MPI_Type_extent(newtype, &extent);
90     if (err != MPI_SUCCESS) {
91         if (verbose) {
92             fprintf(stderr, "error obtaining type extent in builtin_struct_test()\n");
93         }
94         errs++;
95     }
96
97     if (extent != 0) {
98         if (verbose) {
99             fprintf(stderr, "error: extent != 0 in builtin_struct_test()\n");
100         }
101         errs++;
102     }
103
104     MPI_Type_free(&newtype);
105
106     return errs;
107 }
108
109
110 int parse_args(int argc, char **argv)
111 {
112     /*
113      * int ret;
114      *
115      * while ((ret = getopt(argc, argv, "v")) >= 0)
116      * {
117      * switch (ret) {
118      * case 'v':
119      * verbose = 1;
120      * break;
121      * }
122      * }
123      */
124     if (argc > 1 && strcmp(argv[1], "-v") == 0)
125         verbose = 1;
126     return 0;
127 }