1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
8 #include "mpitestconf.h"
13 static char MTEST_Descrip[] = "Test MPI_BXOR operations on optional datatypes dupported by MPICH";
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.
21 int main(int argc, char *argv[])
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];
38 MTest_Init(&argc, &argv);
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);
45 MPI_Comm_rank(comm, &rank);
46 MPI_Comm_size(comm, &size);
48 #ifndef USE_STRICT_MPI
50 MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
53 cinbuf[2] = (rank > 0) ? 0x3c : 0xc3;
58 rc = MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_BXOR, 0, comm);
60 MTestPrintErrorMsg("MPI_BXOR and MPI_CHAR", rc);
65 if (coutbuf[0] != ((size % 2) ? (char) 0xff : (char) 0)) {
67 fprintf(stderr, "char BXOR(1) test failed\n");
71 fprintf(stderr, "char BXOR(0) test failed\n");
73 if (coutbuf[2] != ((size % 2) ? (char) 0xc3 : (char) 0xff)) {
75 fprintf(stderr, "char BXOR(>) test failed\n");
79 #endif /* USE_STRICT_MPI */
82 MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
85 scinbuf[2] = (rank > 0) ? 0x3c : 0xc3;
90 rc = MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_BXOR, 0, comm);
92 MTestPrintErrorMsg("MPI_BXOR and MPI_SIGNED_CHAR", rc);
97 if (scoutbuf[0] != ((size % 2) ? (signed char) 0xff : (signed char) 0)) {
99 fprintf(stderr, "signed char BXOR(1) test failed\n");
103 fprintf(stderr, "signed char BXOR(0) test failed\n");
105 if (scoutbuf[2] != ((size % 2) ? (signed char) 0xc3 : (signed char) 0xff)) {
107 fprintf(stderr, "signed char BXOR(>) test failed\n");
113 MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
116 ucinbuf[2] = (rank > 0) ? 0x3c : 0xc3;
121 rc = MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_BXOR, 0, comm);
123 MTestPrintErrorMsg("MPI_BXOR and MPI_UNSIGNED_CHAR", rc);
128 if (ucoutbuf[0] != ((size % 2) ? 0xff : 0)) {
130 fprintf(stderr, "unsigned char BXOR(1) test failed\n");
134 fprintf(stderr, "unsigned char BXOR(0) test failed\n");
136 if (ucoutbuf[2] != ((size % 2) ? (unsigned char) 0xc3 : (unsigned char) 0xff)) {
138 fprintf(stderr, "unsigned char BXOR(>) test failed\n");
144 MTestPrintfMsg(10, "Reduce of MPI_BYTE\n");
147 cinbuf[2] = (rank > 0) ? 0x3c : 0xc3;
152 rc = MPI_Reduce(cinbuf, coutbuf, 3, MPI_BYTE, MPI_BXOR, 0, comm);
154 MTestPrintErrorMsg("MPI_BXOR and MPI_BYTE", rc);
159 if (coutbuf[0] != ((size % 2) ? (char) 0xff : 0)) {
161 fprintf(stderr, "byte BXOR(1) test failed\n");
165 fprintf(stderr, "byte BXOR(0) test failed\n");
167 if (coutbuf[2] != ((size % 2) ? (char) 0xc3 : (char) 0xff)) {
169 fprintf(stderr, "byte BXOR(>) test failed\n");
175 MTestPrintfMsg(10, "Reduce of MPI_SHORT\n");
178 sinbuf[2] = (rank > 0) ? 0x3c3c : 0xc3c3;
183 rc = MPI_Reduce(sinbuf, soutbuf, 3, MPI_SHORT, MPI_BXOR, 0, comm);
185 MTestPrintErrorMsg("MPI_BXOR and MPI_SHORT", rc);
190 if (soutbuf[0] != ((size % 2) ? (short) 0xffff : 0)) {
192 fprintf(stderr, "short BXOR(1) test failed\n");
196 fprintf(stderr, "short BXOR(0) test failed\n");
198 if (soutbuf[2] != ((size % 2) ? (short) 0xc3c3 : (short) 0xffff)) {
200 fprintf(stderr, "short BXOR(>) test failed\n");
206 MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_SHORT\n");
209 usinbuf[2] = (rank > 0) ? 0x3c3c : 0xc3c3;
214 rc = MPI_Reduce(usinbuf, usoutbuf, 3, MPI_UNSIGNED_SHORT, MPI_BXOR, 0, comm);
216 MTestPrintErrorMsg("MPI_BXOR and MPI_UNSIGNED_SHORT", rc);
221 if (usoutbuf[0] != ((size % 2) ? 0xffff : 0)) {
223 fprintf(stderr, "short BXOR(1) test failed\n");
227 fprintf(stderr, "short BXOR(0) test failed\n");
229 if (usoutbuf[2] != ((size % 2) ? 0xc3c3 : 0xffff)) {
231 fprintf(stderr, "short BXOR(>) test failed\n");
237 MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED\n");
238 uinbuf[0] = 0xffffffff;
240 uinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;
245 rc = MPI_Reduce(uinbuf, uoutbuf, 3, MPI_UNSIGNED, MPI_BXOR, 0, comm);
247 MTestPrintErrorMsg("MPI_BXOR and MPI_UNSIGNED", rc);
252 if (uoutbuf[0] != ((size % 2) ? 0xffffffff : 0)) {
254 fprintf(stderr, "unsigned BXOR(1) test failed\n");
258 fprintf(stderr, "unsigned BXOR(0) test failed\n");
260 if (uoutbuf[2] != ((size % 2) ? 0xc3c3c3c3 : 0xffffffff)) {
262 fprintf(stderr, "unsigned BXOR(>) test failed\n");
268 MTestPrintfMsg(10, "Reduce of MPI_INT\n");
269 iinbuf[0] = 0xffffffff;
271 iinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;
276 rc = MPI_Reduce(iinbuf, ioutbuf, 3, MPI_INT, MPI_BXOR, 0, comm);
278 MTestPrintErrorMsg("MPI_BXOR and MPI_INT", rc);
283 if (ioutbuf[0] != ((size % 2) ? 0xffffffff : 0)) {
285 fprintf(stderr, "int BXOR(1) test failed\n");
289 fprintf(stderr, "int BXOR(0) test failed\n");
291 if (ioutbuf[2] != ((size % 2) ? 0xc3c3c3c3 : 0xffffffff)) {
293 fprintf(stderr, "int BXOR(>) test failed\n");
299 MTestPrintfMsg(10, "Reduce of MPI_LONG\n");
300 linbuf[0] = 0xffffffff;
302 linbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;
307 rc = MPI_Reduce(linbuf, loutbuf, 3, MPI_LONG, MPI_BXOR, 0, comm);
309 MTestPrintErrorMsg("MPI_BXOR and MPI_LONG", rc);
314 if (loutbuf[0] != ((size % 2) ? 0xffffffff : 0)) {
316 fprintf(stderr, "long BXOR(1) test failed\n");
320 fprintf(stderr, "long BXOR(0) test failed\n");
322 if (loutbuf[2] != ((size % 2) ? 0xc3c3c3c3 : 0xffffffff)) {
324 fprintf(stderr, "long BXOR(>) test failed\n");
330 MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_LONG\n");
331 ulinbuf[0] = 0xffffffff;
333 ulinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;
338 rc = MPI_Reduce(ulinbuf, uloutbuf, 3, MPI_UNSIGNED_LONG, MPI_BXOR, 0, comm);
340 MTestPrintErrorMsg("MPI_BXOR and MPI_UNSIGNED_LONG", rc);
345 if (uloutbuf[0] != ((size % 2) ? 0xffffffff : 0)) {
347 fprintf(stderr, "unsigned long BXOR(1) test failed\n");
351 fprintf(stderr, "unsigned long BXOR(0) test failed\n");
353 if (uloutbuf[2] != ((size % 2) ? 0xc3c3c3c3 : 0xffffffff)) {
355 fprintf(stderr, "unsigned long BXOR(>) test failed\n");
360 #ifdef HAVE_LONG_LONG
362 long long llinbuf[3], lloutbuf[3];
364 llinbuf[0] = 0xffffffff;
366 llinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;
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_BXOR, 0, comm);
375 MTestPrintErrorMsg("MPI_BXOR and MPI_LONG_LONG", rc);
380 if (lloutbuf[0] != ((size % 2) ? 0xffffffff : 0)) {
382 fprintf(stderr, "long long BXOR(1) test failed\n");
386 fprintf(stderr, "long long BXOR(0) test failed\n");
388 if (lloutbuf[2] != ((size % 2) ? 0xc3c3c3c3 : 0xffffffff)) {
390 fprintf(stderr, "long long BXOR(>) test failed\n");
398 MPI_Errhandler_set(comm, MPI_ERRORS_ARE_FATAL);
399 MTest_Finalize(errs);