Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
functioning MPI_Comm_get_name, MPI_Comm_set_name
[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 {
27         float a;
28         int b;
29     } foo;
30
31     MPI_Init(&argc, &argv);
32     parse_args(argc, argv);
33
34     /* To improve reporting of problems about operations, we
35      * change the error handler to errors return */
36     MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
37
38     type = MPI_INT;
39     mpi_err = MPI_Type_size(type, &size);
40     if (mpi_err != MPI_SUCCESS) {
41         if (verbose) {
42             fprintf(stderr, "MPI_Type_size of MPI_INT failed.\n");
43         }
44         errs++;
45     }
46     if (size != sizeof(int)) {
47         if (verbose) {
48             fprintf(stderr, "MPI_Type_size of MPI_INT incorrect size (%d); should be %d.\n",
49                     size, (int) sizeof(int));
50         }
51         errs++;
52     }
53
54     mpi_err = MPI_Type_get_extent(type, &lb, &extent);
55     if (mpi_err != MPI_SUCCESS) {
56         if (verbose) {
57             fprintf(stderr, "MPI_Type_get_extent of MPI_INT failed.\n");
58         }
59         errs++;
60     }
61     if (extent != sizeof(int)) {
62         if (verbose) {
63             fprintf(stderr,
64                     "MPI_Type_get_extent of MPI_INT returned incorrect extent (%d); should be %d.\n",
65                     (int) extent, (int) sizeof(int));
66         }
67         errs++;
68     }
69     if (lb != 0) {
70         if (verbose) {
71             fprintf(stderr,
72                     "MPI_Type_get_extent of MPI_INT returned incorrect lb (%d); should be 0.\n",
73                     (int) lb);
74         }
75         errs++;
76     }
77     mpi_err = MPI_Type_ub(type, &ub);
78     if (mpi_err != MPI_SUCCESS) {
79         if (verbose) {
80             fprintf(stderr, "MPI_Type_ub of MPI_INT failed.\n");
81         }
82         errs++;
83     }
84     if (ub != extent - lb) {
85         if (verbose) {
86             fprintf(stderr, "MPI_Type_ub of MPI_INT returned incorrect ub (%d); should be %d.\n",
87                     (int) ub, (int) (extent - lb));
88         }
89         errs++;
90     }
91
92     type = MPI_FLOAT_INT;
93     mpi_err = MPI_Type_size(type, &size);
94     if (mpi_err != MPI_SUCCESS) {
95         if (verbose) {
96             fprintf(stderr, "MPI_Type_size of MPI_FLOAT_INT failed.\n");
97         }
98         errs++;
99     }
100     if (size != sizeof(float) + sizeof(int)) {
101         if (verbose) {
102             fprintf(stderr,
103                     "MPI_Type_size of MPI_FLOAT_INT returned incorrect size (%d); should be %d.\n",
104                     size, (int) (sizeof(float) + sizeof(int)));
105         }
106         errs++;
107     }
108
109     mpi_err = MPI_Type_get_extent(type, &lb, &extent);
110     if (mpi_err != MPI_SUCCESS) {
111         if (verbose) {
112             fprintf(stderr, "MPI_Type_get_extent of MPI_FLOAT_INT failed.\n");
113         }
114         errs++;
115     }
116     if (extent != sizeof(foo)) {
117         if (verbose) {
118             fprintf(stderr,
119                     "MPI_Type_get_extent of MPI_FLOAT_INT returned incorrect extent (%d); should be %d.\n",
120                     (int) extent, (int) sizeof(foo));
121         }
122         errs++;
123     }
124     if (lb != 0) {
125         if (verbose) {
126             fprintf(stderr,
127                     "MPI_Type_get_extent of MPI_FLOAT_INT returned incorrect lb (%d); should be 0.\n",
128                     (int) lb);
129         }
130         errs++;
131     }
132     mpi_err = MPI_Type_ub(type, &ub);
133     if (mpi_err != MPI_SUCCESS) {
134         if (verbose) {
135             fprintf(stderr, "MPI_Type_ub of MPI_FLOAT_INT failed.\n");
136         }
137         errs++;
138     }
139     if (ub != extent - lb) {
140         if (verbose) {
141             fprintf(stderr,
142                     "MPI_Type_ub of MPI_FLOAT_INT returned incorrect ub (%d); should be %d.\n",
143                     (int) ub, (int) (extent - lb));
144         }
145         errs++;
146     }
147
148     /* print message and exit */
149     if (errs) {
150         fprintf(stderr, "Found %d errors\n", errs);
151     }
152     else {
153         printf(" No Errors\n");
154     }
155     MPI_Finalize();
156     return 0;
157 }
158
159 int parse_args(int argc, char **argv)
160 {
161     /*
162      * int ret;
163      *
164      * while ((ret = getopt(argc, argv, "v")) >= 0)
165      * {
166      * switch (ret) {
167      * case 'v':
168      * verbose = 1;
169      * break;
170      * }
171      * }
172      */
173     if (argc > 1 && strcmp(argv[1], "-v") == 0)
174         verbose = 1;
175     return 0;
176 }