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 / 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     {
203         long double ldinbuf[3], ldoutbuf[3];
204         /* long double */
205         MTEST_VG_MEM_INIT(ldinbuf, 3* sizeof(ldinbuf[0]));
206         ldinbuf[0] = 1;
207         ldinbuf[1] = 0;
208         ldinbuf[2] = (rank > 0);
209
210         ldoutbuf[0] = 0;
211         ldoutbuf[1] = 1;
212         ldoutbuf[2] = 1;
213         if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
214             MTestPrintfMsg(10, "Reduce of MPI_LONG_DOUBLE\n");
215             rc = MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_LXOR, 0, comm);
216             if (rc) {
217                 MTestPrintErrorMsg("MPI_LXOR and MPI_LONG_DOUBLE", rc);
218                 errs++;
219             }
220             else {
221                 if (rank == 0) {
222                     if (ldoutbuf[0] != (size % 2)) {
223                         errs++;
224                         fprintf(stderr, "long double XOR(1) test failed\n");
225                     }
226                     if (ldoutbuf[1]) {
227                         errs++;
228                         fprintf(stderr, "long double XOR(0) test failed\n");
229                     }
230                     if (ldoutbuf[2] == (size % 2) && size > 1) {
231                         errs++;
232                         fprintf(stderr, "long double XOR(>) test failed\n");
233                     }
234                 }
235             }
236         }
237     }
238 #endif /* HAVE_LONG_DOUBLE */
239 #endif /* USE_STRICT_MPI */
240
241 #ifdef HAVE_LONG_LONG
242     {
243         long long llinbuf[3], lloutbuf[3];
244         /* long long */
245         llinbuf[0] = 1;
246         llinbuf[1] = 0;
247         llinbuf[2] = (rank > 0);
248
249         lloutbuf[0] = 0;
250         lloutbuf[1] = 1;
251         lloutbuf[2] = 1;
252         if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
253             MTestPrintfMsg(10, "Reduce of MPI_LONG_LONG\n");
254             rc = MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_LXOR, 0, comm);
255             if (rc) {
256                 MTestPrintErrorMsg("MPI_LXOR and MPI_LONG_LONG", rc);
257                 errs++;
258             }
259             else {
260                 if (rank == 0) {
261                     if (lloutbuf[0] != (size % 2)) {
262                         errs++;
263                         fprintf(stderr, "long long XOR(1) test failed\n");
264                     }
265                     if (lloutbuf[1]) {
266                         errs++;
267                         fprintf(stderr, "long long XOR(0) test failed\n");
268                     }
269                     if (lloutbuf[2] == (size % 2) && size > 1) {
270                         errs++;
271                         fprintf(stderr, "long long XOR(>) test failed\n");
272                     }
273                 }
274             }
275         }
276     }
277 #endif
278
279     MPI_Errhandler_set(comm, MPI_ERRORS_ARE_FATAL);
280     MTest_Finalize(errs);
281     MPI_Finalize();
282     return 0;
283 }