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_LXOR 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 float finbuf[3], foutbuf[3];
31 double dinbuf[3], doutbuf[3];
33 MTest_Init(&argc, &argv);
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);
40 MPI_Comm_rank(comm, &rank);
41 MPI_Comm_size(comm, &size);
43 #ifndef USE_STRICT_MPI
45 MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
48 cinbuf[2] = (rank > 0);
53 rc = MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_LXOR, 0, comm);
55 MTestPrintErrorMsg("MPI_LXOR and MPI_CHAR", rc);
60 if (coutbuf[0] != (size % 2)) {
62 fprintf(stderr, "char XOR(1) test failed\n");
66 fprintf(stderr, "char XOR(0) test failed\n");
68 if (coutbuf[2] == (size % 2) && size > 1) {
70 fprintf(stderr, "char XOR(>) test failed\n");
74 #endif /* USE_STRICT_MPI */
77 MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
80 scinbuf[2] = (rank > 0);
85 rc = MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_LXOR, 0, comm);
87 MTestPrintErrorMsg("MPI_LXOR and MPI_SIGNED_CHAR", rc);
92 if (scoutbuf[0] != (size % 2)) {
94 fprintf(stderr, "signed char XOR(1) test failed\n");
98 fprintf(stderr, "signed char XOR(0) test failed\n");
100 if (scoutbuf[2] == (size % 2) && size > 1) {
102 fprintf(stderr, "signed char XOR(>) test failed\n");
108 MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
111 ucinbuf[2] = (rank > 0);
116 rc = MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_LXOR, 0, comm);
118 MTestPrintErrorMsg("MPI_LXOR and MPI_UNSIGNED_CHAR", rc);
123 if (ucoutbuf[0] != (size % 2)) {
125 fprintf(stderr, "unsigned char XOR(1) test failed\n");
129 fprintf(stderr, "unsigned char XOR(0) test failed\n");
131 if (ucoutbuf[2] == (size % 2) && size > 1) {
133 fprintf(stderr, "unsigned char XOR(>) test failed\n");
138 #ifndef USE_STRICT_MPI
140 MTestPrintfMsg(10, "Reduce of MPI_FLOAT\n");
143 finbuf[2] = (rank > 0);
148 rc = MPI_Reduce(finbuf, foutbuf, 3, MPI_FLOAT, MPI_LXOR, 0, comm);
150 MTestPrintErrorMsg("MPI_LXOR and MPI_FLOAT", rc);
155 if (foutbuf[0] != (size % 2)) {
157 fprintf(stderr, "float XOR(1) test failed\n");
161 fprintf(stderr, "float XOR(0) test failed\n");
163 if (foutbuf[2] == (size % 2) && size > 1) {
165 fprintf(stderr, "float XOR(>) test failed\n");
171 MTestPrintfMsg(10, "Reduce of MPI_DOUBLE\n");
174 dinbuf[2] = (rank > 0);
179 rc = MPI_Reduce(dinbuf, doutbuf, 3, MPI_DOUBLE, MPI_LXOR, 0, comm);
181 MTestPrintErrorMsg("MPI_LXOR and MPI_DOUBLE", rc);
186 if (doutbuf[0] != (size % 2)) {
188 fprintf(stderr, "double XOR(1) test failed\n");
192 fprintf(stderr, "double XOR(0) test failed\n");
194 if (doutbuf[2] == (size % 2) && size > 1) {
196 fprintf(stderr, "double XOR(>) test failed\n");
201 #ifdef HAVE_LONG_DOUBLE
203 long double ldinbuf[3], ldoutbuf[3];
205 MTEST_VG_MEM_INIT(ldinbuf, 3* sizeof(ldinbuf[0]));
208 ldinbuf[2] = (rank > 0);
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);
217 MTestPrintErrorMsg("MPI_LXOR and MPI_LONG_DOUBLE", rc);
222 if (ldoutbuf[0] != (size % 2)) {
224 fprintf(stderr, "long double XOR(1) test failed\n");
228 fprintf(stderr, "long double XOR(0) test failed\n");
230 if (ldoutbuf[2] == (size % 2) && size > 1) {
232 fprintf(stderr, "long double XOR(>) test failed\n");
238 #endif /* HAVE_LONG_DOUBLE */
239 #endif /* USE_STRICT_MPI */
241 #ifdef HAVE_LONG_LONG
243 long long llinbuf[3], lloutbuf[3];
247 llinbuf[2] = (rank > 0);
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);
256 MTestPrintErrorMsg("MPI_LXOR and MPI_LONG_LONG", rc);
261 if (lloutbuf[0] != (size % 2)) {
263 fprintf(stderr, "long long XOR(1) test failed\n");
267 fprintf(stderr, "long long XOR(0) test failed\n");
269 if (lloutbuf[2] == (size % 2) && size > 1) {
271 fprintf(stderr, "long long XOR(>) test failed\n");
279 MPI_Errhandler_set(comm, MPI_ERRORS_ARE_FATAL);
280 MTest_Finalize(errs);