Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / oplxor.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_LXOR 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_LXOR, 0, comm );
54     if (rc) {
55         MTestPrintErrorMsg( "MPI_LXOR and MPI_CHAR", rc );
56         errs++;
57     }
58     else {
59         if (rank == 0) {
60             if (coutbuf[0] != (size % 2)) {
61                 errs++;
62                 fprintf( stderr, "char XOR(1) test failed\n" );
63             }
64             if (coutbuf[1]) {
65                 errs++;
66                 fprintf( stderr, "char XOR(0) test failed\n" );
67             }
68             if (coutbuf[2] == (size % 2) && size > 1) {
69                 errs++;
70                 fprintf( stderr, "char XOR(>) 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_LXOR, 0, comm );
86     if (rc) {
87         MTestPrintErrorMsg( "MPI_LXOR and MPI_SIGNED_CHAR", rc );
88         errs++;
89     }
90     else {
91         if (rank == 0) {
92             if (scoutbuf[0] != (size % 2)) {
93                 errs++;
94                 fprintf( stderr, "signed char XOR(1) test failed\n" );
95             }
96             if (scoutbuf[1]) {
97                 errs++;
98                 fprintf( stderr, "signed char XOR(0) test failed\n" );
99             }
100             if (scoutbuf[2] == (size % 2) && size > 1) {
101                 errs++;
102                 fprintf( stderr, "signed char XOR(>) 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_LXOR, 0, comm );
117     if (rc) {
118         MTestPrintErrorMsg( "MPI_LXOR and MPI_UNSIGNED_CHAR", rc );
119         errs++;
120     }
121     else {
122         if (rank == 0) {
123             if (ucoutbuf[0] != (size % 2)) {
124                 errs++;
125                 fprintf( stderr, "unsigned char XOR(1) test failed\n" );
126             }
127             if (ucoutbuf[1]) {
128                 errs++;
129                 fprintf( stderr, "unsigned char XOR(0) test failed\n" );
130             }
131             if (ucoutbuf[2] == (size % 2) && size > 1) {
132                 errs++;
133                 fprintf( stderr, "unsigned char XOR(>) 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_LXOR, 0, comm );
149     if (rc) {
150         MTestPrintErrorMsg( "MPI_LXOR and MPI_FLOAT", rc );
151         errs++;
152     }
153     else {
154         if (rank == 0) {
155             if (foutbuf[0] != (size % 2)) {
156                 errs++;
157                 fprintf( stderr, "float XOR(1) test failed\n" );
158             }
159             if (foutbuf[1]) {
160                 errs++;
161                 fprintf( stderr, "float XOR(0) test failed\n" );
162             }
163             if (foutbuf[2] == (size % 2) && size > 1) {
164                 errs++;
165                 fprintf( stderr, "float XOR(>) test failed\n" );
166             }
167         }
168     }
169
170     /* double */
171     MTestPrintfMsg( 10, "Reduce of MPI_DOUBLE\n" );
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_LXOR, 0, comm );
180     if (rc) {
181         MTestPrintErrorMsg( "MPI_LXOR and MPI_DOUBLE", rc );
182         errs++;
183     }
184     else {
185         if (rank == 0) {
186             if (doutbuf[0] != (size % 2)) {
187                 errs++;
188                 fprintf( stderr, "double XOR(1) test failed\n" );
189             }
190             if (doutbuf[1]) {
191                 errs++;
192                 fprintf( stderr, "double XOR(0) test failed\n" );
193             }
194             if (doutbuf[2] == (size % 2) && size > 1) {
195                 errs++;
196                 fprintf( stderr, "double XOR(>) 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_LXOR, 0, comm );
214         if (rc) {
215             MTestPrintErrorMsg( "MPI_LXOR and MPI_LONG_DOUBLE", rc );
216             errs++;
217         }
218         else {
219             if (rank == 0) {
220                 if (ldoutbuf[0] != (size % 2)) {
221                     errs++;
222                     fprintf( stderr, "long double XOR(1) test failed\n" );
223                 }
224                 if (ldoutbuf[1]) {
225                     errs++;
226                     fprintf( stderr, "long double XOR(0) test failed\n" );
227                 }
228                 if (ldoutbuf[2] == (size % 2) && size > 1) {
229                     errs++;
230                     fprintf( stderr, "long double XOR(>) test failed\n" );
231                 }
232             }
233         }
234     }
235     }
236 #endif /* HAVE_LONG_DOUBLE */
237 #endif /* USE_STRICT_MPI */
238
239 #ifdef HAVE_LONG_LONG
240     {
241         long long llinbuf[3], lloutbuf[3];
242     /* long long */
243     llinbuf[0] = 1;
244     llinbuf[1] = 0;
245     llinbuf[2] = (rank > 0);
246
247     lloutbuf[0] = 0;
248     lloutbuf[1] = 1;
249     lloutbuf[2] = 1;
250     if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
251         MTestPrintfMsg( 10, "Reduce of MPI_LONG_LONG\n" );
252         rc = MPI_Reduce( llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_LXOR, 0, comm );
253         if (rc) {
254             MTestPrintErrorMsg( "MPI_LXOR and MPI_LONG_LONG", rc );
255             errs++;
256         }
257         else {
258             if (rank == 0) {
259                 if (lloutbuf[0] != (size % 2)) {
260                     errs++;
261                     fprintf( stderr, "long long XOR(1) test failed\n" );
262                 }
263                 if (lloutbuf[1]) {
264                     errs++;
265                     fprintf( stderr, "long long XOR(0) test failed\n" );
266                 }
267                 if (lloutbuf[2] == (size % 2) && size > 1) {
268                     errs++;
269                     fprintf( stderr, "long long XOR(>) test failed\n" );
270                 }
271             }
272         }
273     }
274     }
275 #endif
276
277     MPI_Errhandler_set( comm, MPI_ERRORS_ARE_FATAL );
278     MTest_Finalize( errs );
279     MPI_Finalize();
280     return 0;
281 }