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 / opland.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_LAND 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;
24     int rc;
25     int rank, size;
26     MPI_Comm      comm;
27     char cinbuf[3], coutbuf[3];
28     signed char scinbuf[3], scoutbuf[3];
29     unsigned char ucinbuf[3], ucoutbuf[3];
30     float finbuf[3], foutbuf[3];
31     double dinbuf[3], doutbuf[3];
32
33     MTest_Init( &argc, &argv );
34
35     comm = MPI_COMM_WORLD;
36     /* Set errors return so that we can provide better information 
37        should a routine reject one of the operand/datatype pairs */
38     MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );
39
40     MPI_Comm_rank( comm, &rank );
41     MPI_Comm_size( comm, &size );
42
43 #ifndef USE_STRICT_MPI
44     /* char */
45     MTestPrintfMsg( 10, "Reduce of MPI_CHAR\n" );
46     cinbuf[0] = 1;
47     cinbuf[1] = 0;
48     cinbuf[2] = (rank > 0);
49
50     coutbuf[0] = 0;
51     coutbuf[1] = 1;
52     coutbuf[2] = 1;
53     rc = MPI_Reduce( cinbuf, coutbuf, 3, MPI_CHAR, MPI_LAND, 0, comm );
54     if (rc) {
55         MTestPrintErrorMsg( "MPI_LAND and MPI_CHAR", rc );
56         errs++;
57     }
58     else {
59         if (rank == 0) {
60             if (!coutbuf[0]) {
61                 errs++;
62                 fprintf( stderr, "char AND(1) test failed\n" );
63             }
64             if (coutbuf[1]) {
65                 errs++;
66                 fprintf( stderr, "char AND(0) test failed\n" );
67             }
68             if (coutbuf[2] && size > 1) {
69                 errs++;
70                 fprintf( stderr, "char AND(>) test failed\n" );
71             }
72         }
73     }
74 #endif /* USE_STRICT_MPI */
75
76     /* signed char */
77     MTestPrintfMsg( 10, "Reduce of MPI_SIGNED_CHAR\n" );
78     scinbuf[0] = 1;
79     scinbuf[1] = 0;
80     scinbuf[2] = (rank > 0);
81
82     scoutbuf[0] = 0;
83     scoutbuf[1] = 1;
84     scoutbuf[2] = 1;
85     rc = MPI_Reduce( scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_LAND, 0, comm );
86     if (rc) {
87         MTestPrintErrorMsg( "MPI_LAND and MPI_SIGNED_CHAR", rc );
88         errs++;
89     }
90     else {
91         if (rank == 0) {
92             if (!scoutbuf[0]) {
93                 errs++;
94                 fprintf( stderr, "signed char AND(1) test failed\n" );
95             }
96             if (scoutbuf[1]) {
97                 errs++;
98                 fprintf( stderr, "signed char AND(0) test failed\n" );
99             }
100             if (scoutbuf[2] && size > 1) {
101                 errs++;
102                 fprintf( stderr, "signed char AND(>) test failed\n" );
103             }
104         }
105     }
106
107     /* unsigned char */
108     MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_CHAR\n" );
109     ucinbuf[0] = 1;
110     ucinbuf[1] = 0;
111     ucinbuf[2] = (rank > 0);
112
113     ucoutbuf[0] = 0;
114     ucoutbuf[1] = 1;
115     ucoutbuf[2] = 1;
116     rc = MPI_Reduce( ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_LAND, 0, comm );
117     if (rc) {
118         MTestPrintErrorMsg( "MPI_LAND and MPI_UNSIGNED_CHAR", rc );
119         errs++;
120     }
121     else {
122         if (rank == 0) {
123             if (!ucoutbuf[0]) {
124                 errs++;
125                 fprintf( stderr, "unsigned char AND(1) test failed\n" );
126             }
127             if (ucoutbuf[1]) {
128                 errs++;
129                 fprintf( stderr, "unsigned char AND(0) test failed\n" );
130             }
131             if (ucoutbuf[2] && size > 1) {
132                 errs++;
133                 fprintf( stderr, "unsigned char AND(>) test failed\n" );
134             }
135         }
136     }
137
138 #ifndef USE_STRICT_MPI
139     /* float */
140     MTestPrintfMsg( 10, "Reduce of MPI_FLOAT\n" );
141     finbuf[0] = 1;
142     finbuf[1] = 0;
143     finbuf[2] = (rank > 0);
144
145     foutbuf[0] = 0;
146     foutbuf[1] = 1;
147     foutbuf[2] = 1;
148     rc = MPI_Reduce( finbuf, foutbuf, 3, MPI_FLOAT, MPI_LAND, 0, comm );
149     if (rc) {
150         MTestPrintErrorMsg( "MPI_LAND and MPI_FLOAT", rc );
151         errs++;
152     }
153     else {
154         if (rank == 0) {
155             if (!foutbuf[0]) {
156                 errs++;
157                 fprintf( stderr, "float AND(1) test failed\n" );
158             }
159             if (foutbuf[1]) {
160                 errs++;
161                 fprintf( stderr, "float AND(0) test failed\n" );
162             }
163             if (foutbuf[2] && size > 1) {
164                 errs++;
165                 fprintf( stderr, "float AND(>) test failed\n" );
166             }
167         }
168     }
169
170     MTestPrintfMsg( 10, "Reduce of MPI_DOUBLE\n" );
171     /* double */
172     dinbuf[0] = 1;
173     dinbuf[1] = 0;
174     dinbuf[2] = (rank > 0);
175
176     doutbuf[0] = 0;
177     doutbuf[1] = 1;
178     doutbuf[2] = 1;
179     rc = MPI_Reduce( dinbuf, doutbuf, 3, MPI_DOUBLE, MPI_LAND, 0, comm );
180     if (rc) {
181         MTestPrintErrorMsg( "MPI_LAND and MPI_DOUBLE", rc );
182         errs++;
183     }
184     else {
185         if (rank == 0) {
186             if (!doutbuf[0]) {
187                 errs++;
188                 fprintf( stderr, "double AND(1) test failed\n" );
189             }
190             if (doutbuf[1]) {
191                 errs++;
192                 fprintf( stderr, "double AND(0) test failed\n" );
193             }
194             if (doutbuf[2] && size > 1) {
195                 errs++;
196                 fprintf( stderr, "double AND(>) test failed\n" );
197             }
198         }
199     }
200
201 #ifdef HAVE_LONG_DOUBLE
202     { long double ldinbuf[3], ldoutbuf[3];
203     /* long double */
204     ldinbuf[0] = 1;
205     ldinbuf[1] = 0;
206     ldinbuf[2] = (rank > 0);
207
208     ldoutbuf[0] = 0;
209     ldoutbuf[1] = 1;
210     ldoutbuf[2] = 1;
211     if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
212         MTestPrintfMsg( 10, "Reduce of MPI_LONG_DOUBLE\n" );
213         rc = MPI_Reduce( ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_LAND, 0, comm );
214         if (rc) {
215             MTestPrintErrorMsg( "MPI_LAND and MPI_LONG_DOUBLE", rc );
216             errs++;
217         }
218         else {
219             if (rank == 0) {
220                 if (!ldoutbuf[0]) {
221                     errs++;
222                     fprintf( stderr, "long double AND(1) test failed\n" );
223                 }
224                 if (ldoutbuf[1]) {
225                     errs++;
226                     fprintf( stderr, "long double AND(0) test failed\n" );
227                 }
228                 if (ldoutbuf[2] && size > 1) {
229                     errs++;
230                     fprintf( stderr, "long double AND(>) test failed\n" );
231                 }
232             }
233         }
234     }
235     }
236 #endif /* HAVE_LONG_DOUBLE */
237 #endif /* USE_STRICT_MPI */
238
239
240 #ifdef HAVE_LONG_LONG
241     {
242         long long llinbuf[3], lloutbuf[3];
243     /* long long */
244     llinbuf[0] = 1;
245     llinbuf[1] = 0;
246     llinbuf[2] = (rank > 0);
247
248     lloutbuf[0] = 0;
249     lloutbuf[1] = 1;
250     lloutbuf[2] = 1;
251     if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
252         MTestPrintfMsg( 10, "Reduce of MPI_LONG_LONG\n" );
253         rc = MPI_Reduce( llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_LAND, 0, comm );
254         if (rc) {
255             MTestPrintErrorMsg( "MPI_LAND and MPI_LONG_LONG", rc );
256             errs++;
257         }
258         else {
259             if (rank == 0) {
260                 if (!lloutbuf[0]) {
261                     errs++;
262                     fprintf( stderr, "long long AND(1) test failed\n" );
263                 }
264                 if (lloutbuf[1]) {
265                     errs++;
266                     fprintf( stderr, "long long AND(0) test failed\n" );
267                 }
268                 if (lloutbuf[2] && size > 1) {
269                     errs++;
270                     fprintf( stderr, "long long AND(>) test failed\n" );
271                 }
272             }
273         }
274     }
275     }
276 #endif
277
278     MPI_Errhandler_set( comm, MPI_ERRORS_ARE_FATAL );
279     MTest_Finalize( errs );
280     MPI_Finalize();
281     return 0;
282 }
283