Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix build and dist, add missing folder
[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", 
50                         dsize, (int) sizeof(float) );
51             }
52         }
53     }
54
55     err = MPI_Type_match_size( MPI_TYPECLASS_REAL, sizeof(double), &newtype );
56     if (err) {
57         errs++;
58         MTestPrintErrorMsg( "Double: ", err );
59     }
60     else {
61         MPI_Type_size( newtype, &dsize );
62         if (dsize != sizeof(double)) {
63             errs++;
64             printf( "Unexpected size for double\n" );
65         }
66     }
67 #ifdef HAVE_LONG_DOUBLE
68     err = MPI_Type_match_size( MPI_TYPECLASS_REAL, sizeof(long double), &newtype );
69     if (err) {
70         errs++;
71         MTestPrintErrorMsg( "Long double: ", err );
72     }
73     else {
74         MPI_Type_size( newtype, &dsize );
75         if (dsize != sizeof(long double)) {
76             errs++;
77             printf( "Unexpected size for long double\n" );
78         }
79     }
80 #endif
81     
82     err = MPI_Type_match_size( MPI_TYPECLASS_INTEGER, sizeof(short), &newtype );
83     if (err) {
84         errs++;
85         MTestPrintErrorMsg( "Short: ", err );
86     }
87     else {
88         MPI_Type_size( newtype, &dsize );
89         if (dsize != sizeof(short)) {
90             errs++;
91             printf( "Unexpected size for short\n" );
92         }
93     }
94
95     err = MPI_Type_match_size( MPI_TYPECLASS_INTEGER, sizeof(int), &newtype );
96     if (err) {
97         errs++;
98         MTestPrintErrorMsg( "Int: ", err );
99     }
100     else {
101         MPI_Type_size( newtype, &dsize );
102         if (dsize != sizeof(int)) {
103             errs++;
104             printf( "Unexpected size for int\n" );
105         }
106     }
107
108     err = MPI_Type_match_size( MPI_TYPECLASS_INTEGER, sizeof(long), &newtype );
109     if (err) {
110         errs++;
111         MTestPrintErrorMsg( "Long: ", err );
112     }
113     else {
114         MPI_Type_size( newtype, &dsize );
115         if (dsize != sizeof(long)) {
116             errs++;
117             printf( "Unexpected size for long\n" );
118         }
119     }
120 #ifdef HAVE_LONG_LONG
121     err = MPI_Type_match_size( MPI_TYPECLASS_INTEGER, sizeof(long long), &newtype );
122     if (err) {
123         errs++;
124         MTestPrintErrorMsg( "Long long: ", err );
125     }
126     else {
127         MPI_Type_size( newtype, &dsize );
128         if (dsize != sizeof(long long)) {
129             errs++;
130             printf( "Unexpected size for long long\n" );
131         }
132     }
133 #endif
134
135     /* COMPLEX is a FORTRAN type.  The MPICH Type_match_size attempts
136        to give a valid datatype, but if Fortran is not available,
137        MPI_COMPLEX and MPI_DOUBLE_COMPLEX are not supported.  
138        Allow this case by testing for MPI_DATATYPE_NULL */
139     if (MPI_COMPLEX != MPI_DATATYPE_NULL) {
140         err = MPI_Type_match_size( MPI_TYPECLASS_COMPLEX, 2*sizeof(float), &newtype );
141         if (err) {
142             errs++;
143             MTestPrintErrorMsg( "Complex: ", err );
144         }
145         else {
146             MPI_Type_size( newtype, &dsize );
147             if (dsize != 2*sizeof(float)) {
148                 errs++;
149                 printf( "Unexpected size for complex\n" );
150             }
151         }
152     }
153
154     if (MPI_COMPLEX != MPI_DATATYPE_NULL &&
155         MPI_DOUBLE_COMPLEX != MPI_DATATYPE_NULL) {
156         err = MPI_Type_match_size( MPI_TYPECLASS_COMPLEX, 2*sizeof(double), &newtype );
157         if (err) {
158             errs++;
159             MTestPrintErrorMsg( "Double complex: ", err );
160         }
161         else {
162             MPI_Type_size( newtype, &dsize );
163             if (dsize != 2*sizeof(double)) {
164                 errs++;
165                 printf( "Unexpected size for double complex\n" );
166             }
167         }
168     }
169     
170     MTest_Finalize( errs );
171     MPI_Finalize();
172     return 0;
173 }