Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / struct-no-real-types.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 "mpitest.h"
10 #include "mpitestconf.h"
11 #ifdef HAVE_STRING_H
12 #include <string.h>
13 #endif
14
15 /*
16    The default behavior of the test routines should be to briefly indicate
17    the cause of any errors - in this test, that means that verbose needs
18    to be set. Verbose should turn on output that is independent of error
19    levels.
20 */
21 static int verbose = 1;
22
23 /* tests */
24 int no_real_types_test(void);
25
26 /* helper functions */
27 int parse_args(int argc, char **argv);
28
29 int main(int argc, char **argv)
30 {
31     int err, errs = 0;
32
33     MTest_Init(&argc, &argv);
34     parse_args(argc, argv);
35
36     /* To improve reporting of problems about operations, we
37      * change the error handler to errors return */
38     MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
39
40     /* perform some tests */
41     err = no_real_types_test();
42     if (err && verbose)
43         fprintf(stderr, "%d errors in blockindexed test.\n", err);
44     errs += err;
45
46     MTest_Finalize(errs);
47     MPI_Finalize();
48     return 0;
49 }
50
51 /* no_real_types_test()
52  *
53  * Tests behavior with an empty struct type
54  *
55  * Returns the number of errors encountered.
56  */
57 int no_real_types_test(void)
58 {
59     int err, errs = 0;
60
61     int count = 1;
62     int len = 1;
63     MPI_Aint disp = 10;
64     MPI_Datatype type = MPI_LB;
65     MPI_Datatype newtype;
66
67     int size;
68     MPI_Aint extent;
69
70     err = MPI_Type_create_struct(count, &len, &disp, &type, &newtype);
71     if (err != MPI_SUCCESS) {
72         if (verbose) {
73             fprintf(stderr, "error creating struct type no_real_types_test()\n");
74         }
75         MTestPrintError(err);
76         errs++;
77     }
78
79     err = MPI_Type_size(newtype, &size);
80     if (err != MPI_SUCCESS) {
81         if (verbose) {
82             fprintf(stderr, "error obtaining type size in no_real_types_test()\n");
83         }
84         MTestPrintError(err);
85         errs++;
86     }
87
88     if (size != 0) {
89         if (verbose) {
90             fprintf(stderr, "error: size != 0 in no_real_types_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, "error obtaining type extent in no_real_types_test()\n");
99         }
100         MTestPrintError(err);
101         errs++;
102     }
103
104     if (extent != -10) {
105         if (verbose) {
106             fprintf(stderr,
107                     "error: extent is %ld but should be -10 in no_real_types_test()\n",
108                     (long) extent);
109             fprintf(stderr, "type map is { (LB,10) }, so UB is 0 and extent is ub-lb\n");
110         }
111         errs++;
112     }
113
114     MPI_Type_free(&newtype);
115
116     return errs;
117 }
118
119
120 int parse_args(int argc, char **argv)
121 {
122     /*
123      * int ret;
124      *
125      * while ((ret = getopt(argc, argv, "v")) >= 0)
126      * {
127      * switch (ret) {
128      * case 'v':
129      * verbose = 1;
130      * break;
131      * }
132      * }
133      */
134     if (argc > 1 && strcmp(argv[1], "-v") == 0)
135         verbose = 1;
136     return 0;
137 }