Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change include order for smpi tests/examples to avoid conflicts
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / oplor.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 "mpitestconf.h"
9 #include <stdio.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test MPI_LOR operations on optional datatypes dupported by MPICH";
14 */
15
16 /*
17  * This test looks at the handling of logical and for types that are not 
18  * integers or are not required integers (e.g., long long).  MPICH allows
19  * these as well.  A strict MPI test should not include this test.
20  */
21 int main( int argc, char *argv[] )
22 {
23     int errs = 0, err;
24     int rank, size;
25     MPI_Comm      comm;
26     char cinbuf[3], coutbuf[3];
27     signed char scinbuf[3], scoutbuf[3];
28     unsigned char ucinbuf[3], ucoutbuf[3];
29     float finbuf[3], foutbuf[3];
30     double dinbuf[3], doutbuf[3];
31
32     MTest_Init( &argc, &argv );
33
34     comm = MPI_COMM_WORLD;
35
36     MPI_Comm_rank( comm, &rank );
37     MPI_Comm_size( comm, &size );
38
39     /* Some MPI implementations do not implement all of the required
40        (datatype,operations) combinations, and further, they do not
41        always provide clear and specific error messages.  By catching 
42        the error, we can provide a higher quality, more specific message.
43     */
44     MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
45
46 #ifndef USE_STRICT_MPI
47     /* char */
48     MTestPrintfMsg( 10, "Reduce of MPI_CHAR\n" );
49     cinbuf[0] = 1;
50     cinbuf[1] = 0;
51     cinbuf[2] = (rank > 0);
52
53     coutbuf[0] = 0;
54     coutbuf[1] = 1;
55     coutbuf[2] = 1;
56     err = MPI_Reduce( cinbuf, coutbuf, 3, MPI_CHAR, MPI_LOR, 0, comm );
57     if (err) {
58         errs++;
59         MTestPrintErrorMsg( "MPI_LOR and MPI_CHAR", err );
60     }
61     else {
62         if (rank == 0) {
63             if (!coutbuf[0]) {
64                 errs++;
65                 fprintf( stderr, "char OR(1) test failed\n" );
66             }
67             if (coutbuf[1]) {
68                 errs++;
69                 fprintf( stderr, "char OR(0) test failed\n" );
70             }
71             if (!coutbuf[2] && size > 1) {
72                 errs++;
73                 fprintf( stderr, "char OR(>) test failed\n" );
74             }
75         }
76     }
77 #endif /* USE_STRICT_MPI */
78
79     /* signed char */
80     MTestPrintfMsg( 10, "Reduce of MPI_SIGNED_CHAR\n" );
81     scinbuf[0] = 1;
82     scinbuf[1] = 0;
83     scinbuf[2] = (rank > 0);
84
85     scoutbuf[0] = 0;
86     scoutbuf[1] = 1;
87     scoutbuf[2] = 1;
88     err = MPI_Reduce( scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_LOR, 0, comm );
89     if (err) {
90         errs++;
91         MTestPrintErrorMsg( "MPI_LOR and MPI_SIGNED_CHAR", err );
92     }
93     else {
94         if (rank == 0) {
95             if (!scoutbuf[0]) {
96                 errs++;
97                 fprintf( stderr, "signed char OR(1) test failed\n" );
98             }
99             if (scoutbuf[1]) {
100                 errs++;
101                 fprintf( stderr, "signed char OR(0) test failed\n" );
102             }
103             if (!scoutbuf[2] && size > 1) {
104                 errs++;
105                 fprintf( stderr, "signed char OR(>) test failed\n" );
106             }
107         }
108     }
109
110     /* unsigned char */
111     MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_CHAR\n" );
112     ucinbuf[0] = 1;
113     ucinbuf[1] = 0;
114     ucinbuf[2] = (rank > 0);
115
116     ucoutbuf[0] = 0;
117     ucoutbuf[1] = 1;
118     ucoutbuf[2] = 1;
119     err = MPI_Reduce( ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_LOR, 0, comm );
120     if (err) {
121         errs++;
122         MTestPrintErrorMsg( "MPI_LOR and MPI_UNSIGNED_CHAR", err );
123     }
124     else {
125         if (rank == 0) {
126             if (!ucoutbuf[0]) {
127                 errs++;
128                 fprintf( stderr, "unsigned char OR(1) test failed\n" );
129             }
130             if (ucoutbuf[1]) {
131                 errs++;
132                 fprintf( stderr, "unsigned char OR(0) test failed\n" );
133             }
134             if (!ucoutbuf[2] && size > 1) {
135                 errs++;
136                 fprintf( stderr, "unsigned char OR(>) test failed\n" );
137             }
138         }
139     }
140
141 #ifndef USE_STRICT_MPI
142     /* float */
143     MTestPrintfMsg( 10, "Reduce of MPI_FLOAT\n" );
144     finbuf[0] = 1;
145     finbuf[1] = 0;
146     finbuf[2] = (rank > 0);
147
148     foutbuf[0] = 0;
149     foutbuf[1] = 1;
150     foutbuf[2] = 1;
151     err = MPI_Reduce( finbuf, foutbuf, 3, MPI_FLOAT, MPI_LOR, 0, comm );
152     if (err) {
153         errs++;
154         MTestPrintErrorMsg( "MPI_LOR and MPI_FLOAT", err );
155     }
156     else {
157         if (rank == 0) {
158             if (!foutbuf[0]) {
159                 errs++;
160                 fprintf( stderr, "float OR(1) test failed\n" );
161             }
162             if (foutbuf[1]) {
163                 errs++;
164                 fprintf( stderr, "float OR(0) test failed\n" );
165             }
166             if (!foutbuf[2] && size > 1) {
167                 errs++;
168                 fprintf( stderr, "float OR(>) test failed\n" );
169             }
170         }
171     }
172
173     /* double */
174     MTestPrintfMsg( 10, "Reduce of MPI_DOUBLE\n" );
175     dinbuf[0] = 1;
176     dinbuf[1] = 0;
177     dinbuf[2] = (rank > 0);
178
179     doutbuf[0] = 0;
180     doutbuf[1] = 1;
181     doutbuf[2] = 1;
182     err = MPI_Reduce( dinbuf, doutbuf, 3, MPI_DOUBLE, MPI_LOR, 0, comm );
183     if (err) {
184         errs++;
185         MTestPrintErrorMsg( "MPI_LOR and MPI_DOUBLE", err );
186     }
187     else {
188         if (rank == 0) {
189             if (!doutbuf[0]) {
190                 errs++;
191                 fprintf( stderr, "double OR(1) test failed\n" );
192             }
193             if (doutbuf[1]) {
194                 errs++;
195                 fprintf( stderr, "double OR(0) test failed\n" );
196             }
197             if (!doutbuf[2] && size > 1) {
198                 errs++;
199                 fprintf( stderr, "double OR(>) test failed\n" );
200             }
201         }
202     }
203
204 #ifdef HAVE_LONG_DOUBLE
205     { long double ldinbuf[3], ldoutbuf[3];
206     /* long double */
207     ldinbuf[0] = 1;
208     ldinbuf[1] = 0;
209     ldinbuf[2] = (rank > 0);
210
211     ldoutbuf[0] = 0;
212     ldoutbuf[1] = 1;
213     ldoutbuf[2] = 1;
214     if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
215         MTestPrintfMsg( 10, "Reduce of MPI_LONG_DOUBLE\n" );
216         err = MPI_Reduce( ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_LOR, 0, comm );
217         if (err) {
218             errs++;
219             MTestPrintErrorMsg( "MPI_LOR and MPI_LONG_DOUBLE", err );
220         }
221         else {
222             if (rank == 0) {
223                 if (!ldoutbuf[0]) {
224                     errs++;
225                     fprintf( stderr, "long double OR(1) test failed\n" );
226                 }
227                 if (ldoutbuf[1]) {
228                     errs++;
229                     fprintf( stderr, "long double OR(0) test failed\n" );
230                 }
231                 if (!ldoutbuf[2] && size > 1) {
232                     errs++;
233                     fprintf( stderr, "long double OR(>) test failed\n" );
234                 }
235             }
236         }
237         }
238     }
239 #endif /* HAVE_LONG_DOUBLE */
240 #endif /* USE_STRICT_MPI */
241
242 #ifdef HAVE_LONG_LONG
243     {
244         long long llinbuf[3], lloutbuf[3];
245     /* long long */
246     llinbuf[0] = 1;
247     llinbuf[1] = 0;
248     llinbuf[2] = (rank > 0);
249
250     lloutbuf[0] = 0;
251     lloutbuf[1] = 1;
252     lloutbuf[2] = 1;
253     if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
254         MTestPrintfMsg( 10, "Reduce of MPI_LONG_LONG\n" );
255         err = MPI_Reduce( llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_LOR, 0, comm );
256         if (err) {
257             errs++;
258             MTestPrintErrorMsg( "MPI_LOR and MPI_LONG_LONG", err );
259         }
260         else {
261             if (rank == 0) {
262                 if (!lloutbuf[0]) {
263                     errs++;
264                     fprintf( stderr, "long long OR(1) test failed\n" );
265                 }
266                 if (lloutbuf[1]) {
267                     errs++;
268                     fprintf( stderr, "long long OR(0) test failed\n" );
269                 }
270                 if (!lloutbuf[2] && size > 1) {
271                     errs++;
272                     fprintf( stderr, "long long OR(>) test failed\n" );
273                 }
274             }
275         }
276     }
277     }
278 #endif
279
280     MPI_Errhandler_set( comm, MPI_ERRORS_ARE_FATAL );
281     MTest_Finalize( errs );
282     MPI_Finalize();
283     return 0;
284 }