Logo AND Algorithmique Numérique Distribuée

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