Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / opbor.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_BOR 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     short sinbuf[3], soutbuf[3];
31     unsigned short usinbuf[3], usoutbuf[3];
32     long linbuf[3], loutbuf[3];
33     unsigned long ulinbuf[3], uloutbuf[3];
34     unsigned uinbuf[3], uoutbuf[3];
35     int iinbuf[3], ioutbuf[3];
36     
37
38     MTest_Init( &argc, &argv );
39
40     comm = MPI_COMM_WORLD;
41     /* Set errors return so that we can provide better information 
42        should a routine reject one of the operand/datatype pairs */
43     MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );
44
45     MPI_Comm_rank( comm, &rank );
46     MPI_Comm_size( comm, &size );
47
48 #ifndef USE_STRICT_MPI
49     /* char */
50     MTestPrintfMsg( 10, "Reduce of MPI_CHAR\n" );
51     cinbuf[0] = 0xff;
52     cinbuf[1] = 0;
53     cinbuf[2] = (rank > 0) ? 0x3c : 0xc3;
54
55     coutbuf[0] = 0;
56     coutbuf[1] = 1;
57     coutbuf[2] = 1;
58     rc = MPI_Reduce( cinbuf, coutbuf, 3, MPI_CHAR, MPI_BOR, 0, comm );
59     if (rc) {
60         MTestPrintErrorMsg( "MPI_BOR and MPI_CHAR", rc );
61         errs++;
62     }
63     else {
64         if (rank == 0) {
65             if (coutbuf[0] != (char)0xff) {
66                 errs++;
67                 fprintf( stderr, "char BOR(1) test failed\n" );
68             }
69             if (coutbuf[1]) {
70                 errs++;
71                 fprintf( stderr, "char BOR(0) test failed\n" );
72             }
73             if (coutbuf[2] != (char)0xff && size > 1) {
74                 errs++;
75                 fprintf( stderr, "char BOR(>) test failed\n" );
76             }
77         }
78     }
79 #endif /* USE_STRICT_MPI */
80
81     /* signed char */
82     MTestPrintfMsg( 10, "Reduce of MPI_SIGNED_CHAR\n" );
83     scinbuf[0] = 0xff;
84     scinbuf[1] = 0;
85     scinbuf[2] = (rank > 0) ? 0x3c : 0xc3;
86
87     scoutbuf[0] = 0;
88     scoutbuf[1] = 1;
89     scoutbuf[2] = 1;
90     rc = MPI_Reduce( scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_BOR, 0, comm );
91     if (rc) {
92         MTestPrintErrorMsg( "MPI_BOR and MPI_SIGNED_CHAR", rc );
93         errs++;
94     }
95     else {
96         if (rank == 0) {
97             if (scoutbuf[0] != (signed char)0xff) {
98                 errs++;
99                 fprintf( stderr, "signed char BOR(1) test failed\n" );
100             }
101             if (scoutbuf[1]) {
102                 errs++;
103                 fprintf( stderr, "signed char BOR(0) test failed\n" );
104             }
105             if (scoutbuf[2] != (signed char)0xff && size > 1) {
106                 errs++;
107                 fprintf( stderr, "signed char BOR(>) test failed\n" );
108             }
109         }
110     }
111
112     /* unsigned char */
113     MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_CHAR\n" );
114     ucinbuf[0] = 0xff;
115     ucinbuf[1] = 0;
116     ucinbuf[2] = (rank > 0) ? 0x3c : 0xc3;
117
118     ucoutbuf[0] = 0;
119     ucoutbuf[1] = 1;
120     ucoutbuf[2] = 1;
121     rc = MPI_Reduce( ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_BOR, 0, comm );
122     if (rc) {
123         MTestPrintErrorMsg( "MPI_BOR and MPI_UNSIGNED_CHAR", rc );
124         errs++;
125     }
126     else {
127         if (rank == 0) {
128             if (ucoutbuf[0] != 0xff) {
129                 errs++;
130                 fprintf( stderr, "unsigned char BOR(1) test failed\n" );
131             }
132             if (ucoutbuf[1]) {
133                 errs++;
134                 fprintf( stderr, "unsigned char BOR(0) test failed\n" );
135             }
136             if (ucoutbuf[2] != 0xff && size > 1) {
137                 errs++;
138                 fprintf( stderr, "unsigned char BOR(>) test failed\n" );
139             }
140         }
141     }
142
143     /* bytes */
144     MTestPrintfMsg( 10, "Reduce of MPI_BYTE\n" );
145     cinbuf[0] = 0xff;
146     cinbuf[1] = 0;
147     cinbuf[2] = (rank > 0) ? 0x3c : 0xc3;
148
149     coutbuf[0] = 0;
150     coutbuf[1] = 1;
151     coutbuf[2] = 1;
152     rc = MPI_Reduce( cinbuf, coutbuf, 3, MPI_BYTE, MPI_BOR, 0, comm );
153     if (rc) {
154         MTestPrintErrorMsg( "MPI_BOR and MPI_BYTE", rc );
155         errs++;
156     }
157     else {
158         if (rank == 0) {
159             if (coutbuf[0] != (char)0xff) {
160                 errs++;
161                 fprintf( stderr, "byte BOR(1) test failed\n" );
162             }
163             if (coutbuf[1]) {
164                 errs++;
165                 fprintf( stderr, "byte BOR(0) test failed\n" );
166             }
167             if (coutbuf[2] != (char)0xff && size > 1) {
168                 errs++;
169                 fprintf( stderr, "byte BOR(>) test failed\n" );
170             }
171         }
172     }
173
174     /* short */
175     MTestPrintfMsg( 10, "Reduce of MPI_SHORT\n" );
176     sinbuf[0] = 0xffff;
177     sinbuf[1] = 0;
178     sinbuf[2] = (rank > 0) ? 0x3c3c : 0xc3c3;
179
180     soutbuf[0] = 0;
181     soutbuf[1] = 1;
182     soutbuf[2] = 1;
183     rc = MPI_Reduce( sinbuf, soutbuf, 3, MPI_SHORT, MPI_BOR, 0, comm );
184     if (rc) {
185         MTestPrintErrorMsg( "MPI_BOR and MPI_SHORT", rc );
186         errs++;
187     }
188     else {
189         if (rank == 0) {
190             if (soutbuf[0] != (short)0xffff) {
191                 errs++;
192                 fprintf( stderr, "short BOR(1) test failed\n" );
193             }
194             if (soutbuf[1]) {
195                 errs++;
196                 fprintf( stderr, "short BOR(0) test failed\n" );
197             }
198             if (soutbuf[2] != (short)0xffff && size > 1) {
199                 errs++;
200                 fprintf( stderr, "short BOR(>) test failed\n" );
201             }
202         }
203     }
204
205     /* unsigned short */
206     MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_SHORT\n" );
207     usinbuf[0] = 0xffff;
208     usinbuf[1] = 0;
209     usinbuf[2] = (rank > 0) ? 0x3c3c : 0xc3c3;
210
211     usoutbuf[0] = 0;
212     usoutbuf[1] = 1;
213     usoutbuf[2] = 1;
214     rc = MPI_Reduce( usinbuf, usoutbuf, 3, MPI_UNSIGNED_SHORT, MPI_BOR, 0, comm );
215     if (rc) {
216         MTestPrintErrorMsg( "MPI_BOR and MPI_UNSIGNED_SHORT", rc );
217         errs++;
218     }
219     else {
220         if (rank == 0) {
221             if (usoutbuf[0] != 0xffff) {
222                 errs++;
223                 fprintf( stderr, "short BOR(1) test failed\n" );
224             }
225             if (usoutbuf[1]) {
226                 errs++;
227                 fprintf( stderr, "short BOR(0) test failed\n" );
228             }
229             if (usoutbuf[2] != 0xffff && size > 1) {
230                 errs++;
231                 fprintf( stderr, "short BOR(>) test failed\n" );
232             }
233         }
234     }
235
236     /* unsigned */
237     MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED\n" );
238     uinbuf[0] = 0xffffffff;
239     uinbuf[1] = 0;
240     uinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;
241
242     uoutbuf[0] = 0;
243     uoutbuf[1] = 1;
244     uoutbuf[2] = 1;
245     rc = MPI_Reduce( uinbuf, uoutbuf, 3, MPI_UNSIGNED, MPI_BOR, 0, comm );
246     if (rc) {
247         MTestPrintErrorMsg( "MPI_BOR and MPI_UNSIGNED", rc );
248         errs++;
249     }
250     else {
251         if (rank == 0) {
252             if (uoutbuf[0] != 0xffffffff) {
253                 errs++;
254                 fprintf( stderr, "unsigned BOR(1) test failed\n" );
255             }
256             if (uoutbuf[1]) {
257                 errs++;
258                 fprintf( stderr, "unsigned BOR(0) test failed\n" );
259             }
260             if (uoutbuf[2] != 0xffffffff && size > 1) {
261                 errs++;
262                 fprintf( stderr, "unsigned BOR(>) test failed\n" );
263             }
264         }
265     }
266
267     /* int */
268     MTestPrintfMsg( 10, "Reduce of MPI_INT\n" );
269     iinbuf[0] = 0xffffffff;
270     iinbuf[1] = 0;
271     iinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;
272
273     ioutbuf[0] = 0;
274     ioutbuf[1] = 1;
275     ioutbuf[2] = 1;
276     rc = MPI_Reduce( iinbuf, ioutbuf, 3, MPI_INT, MPI_BOR, 0, comm );
277     if (rc) {
278         MTestPrintErrorMsg( "MPI_BOR and MPI_INT", rc );
279         errs++;
280     }
281     else {
282         if (rank == 0) {
283             if (ioutbuf[0] != 0xffffffff) {
284                 errs++;
285                 fprintf( stderr, "int BOR(1) test failed\n" );
286             }
287             if (ioutbuf[1]) {
288                 errs++;
289                 fprintf( stderr, "int BOR(0) test failed\n" );
290             }
291             if (ioutbuf[2] != 0xffffffff && size > 1) {
292                 errs++;
293                 fprintf( stderr, "int BOR(>) test failed\n" );
294             }
295         }
296     }
297
298     /* long */
299     MTestPrintfMsg( 10, "Reduce of MPI_LONG\n" );
300     linbuf[0] = 0xffffffff;
301     linbuf[1] = 0;
302     linbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;
303
304     loutbuf[0] = 0;
305     loutbuf[1] = 1;
306     loutbuf[2] = 1;
307     rc = MPI_Reduce( linbuf, loutbuf, 3, MPI_LONG, MPI_BOR, 0, comm );
308     if (rc) {
309         MTestPrintErrorMsg( "MPI_BOR and MPI_LONG", rc );
310         errs++;
311     }
312     else {
313         if (rank == 0) {
314             if (loutbuf[0] != 0xffffffff) {
315                 errs++;
316                 fprintf( stderr, "long BOR(1) test failed\n" );
317             }
318             if (loutbuf[1]) {
319                 errs++;
320                 fprintf( stderr, "long BOR(0) test failed\n" );
321             }
322             if (loutbuf[2] != 0xffffffff && size > 1) {
323                 errs++;
324                 fprintf( stderr, "long BOR(>) test failed\n" );
325             }
326         }
327     }
328
329     /* unsigned long */
330     MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_LONG\n" );
331     ulinbuf[0] = 0xffffffff;
332     ulinbuf[1] = 0;
333     ulinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;
334
335     uloutbuf[0] = 0;
336     uloutbuf[1] = 1;
337     uloutbuf[2] = 1;
338     rc = MPI_Reduce( ulinbuf, uloutbuf, 3, MPI_UNSIGNED_LONG, MPI_BOR, 0, comm );
339     if (rc) {
340         MTestPrintErrorMsg( "MPI_BOR and MPI_UNSIGNED_LONG", rc );
341         errs++;
342     }
343     else {
344         if (rank == 0) {
345             if (uloutbuf[0] != 0xffffffff) {
346                 errs++;
347                 fprintf( stderr, "unsigned long BOR(1) test failed\n" );
348             }
349             if (uloutbuf[1]) {
350                 errs++;
351                 fprintf( stderr, "unsigned long BOR(0) test failed\n" );
352             }
353             if (uloutbuf[2] != 0xffffffff && size > 1) {
354                 errs++;
355                 fprintf( stderr, "unsigned long BOR(>) test failed\n" );
356             }
357         }
358     }
359
360 #ifdef HAVE_LONG_LONG
361     {
362         long long llinbuf[3], lloutbuf[3];
363     /* long long */
364     llinbuf[0] = 0xffffffff;
365     llinbuf[1] = 0;
366     llinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;
367
368     lloutbuf[0] = 0;
369     lloutbuf[1] = 1;
370     lloutbuf[2] = 1;
371     if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
372         MTestPrintfMsg( 10, "Reduce of MPI_LONG_LONG\n" );
373         rc = MPI_Reduce( llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_BOR, 0, comm );
374         if (rc) {
375             MTestPrintErrorMsg( "MPI_BOR and MPI_LONG_LONG", rc );
376             errs++;
377         }
378         else {
379             if (rank == 0) {
380                 if (lloutbuf[0] != 0xffffffff) {
381                     errs++;
382                     fprintf( stderr, "long long BOR(1) test failed\n" );
383                 }
384                 if (lloutbuf[1]) {
385                     errs++;
386                     fprintf( stderr, "long long BOR(0) test failed\n" );
387                 }
388                 if (lloutbuf[2] != 0xffffffff && size > 1) {
389                     errs++;
390                     fprintf( stderr, "long long BOR(>) test failed\n" );
391                 }
392             }
393         }
394     }
395     }
396 #endif
397
398     MPI_Errhandler_set( comm, MPI_ERRORS_ARE_FATAL );
399     MTest_Finalize( errs );
400     MPI_Finalize();
401     return 0;
402 }