Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Also add the mpich3 binaries in the dependencies of make tests
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / tmatchsize.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test of type_match_size";
14 */
15
16 /*
17  * type match size is part of the extended Fortran support, and may not
18  * be present in
19  */
20
21 int main(int argc, char *argv[])
22 {
23     int errs = 0, err;
24     int dsize;
25     MPI_Datatype newtype;
26
27     MTest_Init(&argc, &argv);
28
29     /* Check the most likely cases.  Note that it is an error to
30      * free the type returned by MPI_Type_match_size.  Also note
31      * that it is an error to request a size not supported by the compiler,
32      * so Type_match_size should generate an error in that case */
33     MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
34
35     err = MPI_Type_match_size(MPI_TYPECLASS_REAL, sizeof(float), &newtype);
36     if (err) {
37         errs++;
38         MTestPrintErrorMsg("Float: ", err);
39     }
40     else {
41         err = MPI_Type_size(newtype, &dsize);
42         if (err) {
43             errs++;
44             MTestPrintErrorMsg("Float type: ", err);
45         }
46         else {
47             if (dsize != sizeof(float)) {
48                 errs++;
49                 printf("Unexpected size for float (%d != %d)\n", dsize, (int) sizeof(float));
50             }
51         }
52     }
53
54     err = MPI_Type_match_size(MPI_TYPECLASS_REAL, sizeof(double), &newtype);
55     if (err) {
56         errs++;
57         MTestPrintErrorMsg("Double: ", err);
58     }
59     else {
60         MPI_Type_size(newtype, &dsize);
61         if (dsize != sizeof(double)) {
62             errs++;
63             printf("Unexpected size for double\n");
64         }
65     }
66 #ifdef HAVE_LONG_DOUBLE
67     err = MPI_Type_match_size(MPI_TYPECLASS_REAL, sizeof(long double), &newtype);
68     if (err) {
69         errs++;
70         MTestPrintErrorMsg("Long double: ", err);
71     }
72     else {
73         MPI_Type_size(newtype, &dsize);
74         if (dsize != sizeof(long double)) {
75             errs++;
76             printf("Unexpected size for long double\n");
77         }
78     }
79 #endif
80
81     err = MPI_Type_match_size(MPI_TYPECLASS_INTEGER, sizeof(short), &newtype);
82     if (err) {
83         errs++;
84         MTestPrintErrorMsg("Short: ", err);
85     }
86     else {
87         MPI_Type_size(newtype, &dsize);
88         if (dsize != sizeof(short)) {
89             errs++;
90             printf("Unexpected size for short\n");
91         }
92     }
93
94     err = MPI_Type_match_size(MPI_TYPECLASS_INTEGER, sizeof(int), &newtype);
95     if (err) {
96         errs++;
97         MTestPrintErrorMsg("Int: ", err);
98     }
99     else {
100         MPI_Type_size(newtype, &dsize);
101         if (dsize != sizeof(int)) {
102             errs++;
103             printf("Unexpected size for int\n");
104         }
105     }
106
107     err = MPI_Type_match_size(MPI_TYPECLASS_INTEGER, sizeof(long), &newtype);
108     if (err) {
109         errs++;
110         MTestPrintErrorMsg("Long: ", err);
111     }
112     else {
113         MPI_Type_size(newtype, &dsize);
114         if (dsize != sizeof(long)) {
115             errs++;
116             printf("Unexpected size for long\n");
117         }
118     }
119 #ifdef HAVE_LONG_LONG
120     err = MPI_Type_match_size(MPI_TYPECLASS_INTEGER, sizeof(long long), &newtype);
121     if (err) {
122         errs++;
123         MTestPrintErrorMsg("Long long: ", err);
124     }
125     else {
126         MPI_Type_size(newtype, &dsize);
127         if (dsize != sizeof(long long)) {
128             errs++;
129             printf("Unexpected size for long long\n");
130         }
131     }
132 #endif
133
134     /* COMPLEX is a FORTRAN type.  The MPICH Type_match_size attempts
135      * to give a valid datatype, but if Fortran is not available,
136      * MPI_COMPLEX and MPI_DOUBLE_COMPLEX are not supported.
137      * Allow this case by testing for MPI_DATATYPE_NULL */
138     if (MPI_COMPLEX != MPI_DATATYPE_NULL) {
139         err = MPI_Type_match_size(MPI_TYPECLASS_COMPLEX, 2 * sizeof(float), &newtype);
140         if (err) {
141             errs++;
142             MTestPrintErrorMsg("Complex: ", err);
143         }
144         else {
145             MPI_Type_size(newtype, &dsize);
146             if (dsize != 2 * sizeof(float)) {
147                 errs++;
148                 printf("Unexpected size for complex\n");
149             }
150         }
151     }
152
153     if (MPI_COMPLEX != MPI_DATATYPE_NULL && MPI_DOUBLE_COMPLEX != MPI_DATATYPE_NULL) {
154         err = MPI_Type_match_size(MPI_TYPECLASS_COMPLEX, 2 * sizeof(double), &newtype);
155         if (err) {
156             errs++;
157             MTestPrintErrorMsg("Double complex: ", err);
158         }
159         else {
160             MPI_Type_size(newtype, &dsize);
161             if (dsize != 2 * sizeof(double)) {
162                 errs++;
163                 printf("Unexpected size for double complex\n");
164             }
165         }
166     }
167
168     MTest_Finalize(errs);
169     MPI_Finalize();
170     return 0;
171 }