Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix HAVE_FOOBAR flags handling
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / simple-size-extent.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
7 /* Tests that Type_get_extent of a couple of basic types succeeds. */
8
9 #include "mpi.h"
10 #include <stdio.h>
11 #include "mpitestconf.h"
12 #ifdef HAVE_STRING_H
13 #include <string.h>
14 #endif
15
16 static int verbose = 0;
17
18 int parse_args(int argc, char **argv);
19
20 int main(int argc, char **argv)
21 {
22     int mpi_err, errs = 0, size;
23     MPI_Aint lb, ub, extent;
24     MPI_Datatype type;
25
26     struct { float a; int b; } foo;
27
28     MPI_Init(&argc, &argv);
29     parse_args(argc, argv);
30
31     /* To improve reporting of problems about operations, we
32        change the error handler to errors return */
33     MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
34
35     type = MPI_INT;
36     mpi_err = MPI_Type_size(type, &size);
37     if (mpi_err != MPI_SUCCESS) {
38         if (verbose) {
39             fprintf(stderr, "MPI_Type_size of MPI_INT failed.\n");
40         }
41         errs++;
42     }
43     if (size != sizeof(int)) {
44         if (verbose) {
45             fprintf(stderr, "MPI_Type_size of MPI_INT incorrect size (%d); should be %d.\n",
46                     size, (int) sizeof(int));
47         }
48         errs++;
49     }
50
51     mpi_err = MPI_Type_get_extent(type, &lb, &extent);
52     if (mpi_err != MPI_SUCCESS) {
53         if (verbose) {
54             fprintf(stderr, "MPI_Type_get_extent of MPI_INT failed.\n");
55         }
56         errs++;
57     }
58     if (extent != sizeof(int)) {
59         if (verbose) {
60             fprintf(stderr, "MPI_Type_get_extent of MPI_INT returned incorrect extent (%d); should be %d.\n",
61                     (int) extent, (int) sizeof(int));
62         }
63         errs++;
64     }
65     if (lb != 0) {
66         if (verbose) {
67             fprintf(stderr, "MPI_Type_get_extent of MPI_INT returned incorrect lb (%d); should be 0.\n",
68                     (int) lb);
69         }
70         errs++;
71     }
72     mpi_err = MPI_Type_ub(type, &ub);
73     if (mpi_err != MPI_SUCCESS) {
74         if (verbose) {
75             fprintf(stderr, "MPI_Type_ub of MPI_INT failed.\n");
76         }
77         errs++;
78     }
79     if (ub != extent - lb) {
80         if (verbose) {
81             fprintf(stderr, "MPI_Type_ub of MPI_INT returned incorrect ub (%d); should be %d.\n",
82                     (int) ub, (int) (extent - lb));
83         }
84         errs++;
85     }
86
87     type = MPI_FLOAT_INT;
88     mpi_err = MPI_Type_size(type, &size);
89     if (mpi_err != MPI_SUCCESS) {
90         if (verbose) {
91             fprintf(stderr, "MPI_Type_size of MPI_FLOAT_INT failed.\n");
92         }
93         errs++;
94     }
95     if (size != sizeof(float) + sizeof(int)) {
96         if (verbose) {
97             fprintf(stderr, "MPI_Type_size of MPI_FLOAT_INT returned incorrect size (%d); should be %d.\n",
98                     size, (int) (sizeof(float) + sizeof(int)));
99         }
100         errs++;
101     }
102
103     mpi_err = MPI_Type_get_extent(type, &lb, &extent);
104     if (mpi_err != MPI_SUCCESS) {
105         if (verbose) {
106             fprintf(stderr, "MPI_Type_get_extent of MPI_FLOAT_INT failed.\n");
107         }
108         errs++;
109     }
110     if (extent != sizeof(foo)) {
111         if (verbose) {
112             fprintf(stderr, "MPI_Type_get_extent of MPI_FLOAT_INT returned incorrect extent (%d); should be %d.\n",
113                     (int) extent, (int) sizeof(foo));
114         }
115         errs++;
116     }
117     if (lb != 0) {
118         if (verbose) {
119             fprintf(stderr, "MPI_Type_get_extent of MPI_FLOAT_INT returned incorrect lb (%d); should be 0.\n",
120                     (int) lb);
121         }
122         errs++;
123     }
124     mpi_err = MPI_Type_ub(type, &ub);
125     if (mpi_err != MPI_SUCCESS) {
126         if (verbose) {
127             fprintf(stderr, "MPI_Type_ub of MPI_FLOAT_INT failed.\n");
128         }
129         errs++;
130     }
131     if (ub != extent - lb) {
132         if (verbose) {
133             fprintf(stderr, "MPI_Type_ub of MPI_FLOAT_INT returned incorrect ub (%d); should be %d.\n",
134                     (int) ub, (int) (extent - lb));
135         }
136         errs++;
137     }
138
139     /* print message and exit */
140     if (errs) {
141         fprintf(stderr, "Found %d errors\n", errs);
142     }
143     else {
144         printf(" No Errors\n");
145     }
146     MPI_Finalize();
147     return 0;
148 }
149
150 int parse_args(int argc, char **argv)
151 {
152     /*
153     int ret;
154
155     while ((ret = getopt(argc, argv, "v")) >= 0)
156     {
157         switch (ret) {
158             case 'v':
159                 verbose = 1;
160                 break;
161         }
162     }
163     */
164     if (argc > 1 && strcmp(argv[1], "-v") == 0)
165         verbose = 1;
166     return 0;
167 }