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_PROD operations on optional datatypes dupported by MPICH";
19 #ifdef HAVE_LONG_DOUBLE
26 * This test looks at the handling of logical and for types that are not
27 * integers or are not required integers (e.g., long long). MPICH allows
28 * these as well. A strict MPI test should not include this test.
30 int main(int argc, char *argv[])
33 int rank, size, maxsize, result[6] = { 1, 1, 2, 6, 24, 120 };
35 char cinbuf[3], coutbuf[3];
36 signed char scinbuf[3], scoutbuf[3];
37 unsigned char ucinbuf[3], ucoutbuf[3];
38 d_complex dinbuf[3], doutbuf[3];
40 MTest_Init(&argc, &argv);
42 comm = MPI_COMM_WORLD;
44 MPI_Comm_rank(comm, &rank);
45 MPI_Comm_size(comm, &size);
51 /* General forumula: If we multiple the values from 1 to n, the
52 * product is n!. This grows very fast, so we'll only use the first
53 * five (1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120), with n!
54 * stored in the array result[n] */
56 #ifndef USE_STRICT_MPI
58 MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
59 cinbuf[0] = (rank < maxsize && rank > 0) ? rank : 1;
61 cinbuf[2] = (rank > 1);
66 MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_PROD, 0, comm);
68 if (coutbuf[0] != (char) result[maxsize - 1]) {
70 fprintf(stderr, "char PROD(rank) test failed (%d!=%d)\n",
71 (int) coutbuf[0], (int) result[maxsize]);
75 fprintf(stderr, "char PROD(0) test failed\n");
77 if (size > 1 && coutbuf[2]) {
79 fprintf(stderr, "char PROD(>) test failed\n");
82 #endif /* USE_STRICT_MPI */
85 MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
86 scinbuf[0] = (rank < maxsize && rank > 0) ? rank : 1;
88 scinbuf[2] = (rank > 1);
93 MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_PROD, 0, comm);
95 if (scoutbuf[0] != (signed char) result[maxsize - 1]) {
97 fprintf(stderr, "signed char PROD(rank) test failed (%d!=%d)\n",
98 (int) scoutbuf[0], (int) result[maxsize]);
102 fprintf(stderr, "signed char PROD(0) test failed\n");
104 if (size > 1 && scoutbuf[2]) {
106 fprintf(stderr, "signed char PROD(>) test failed\n");
111 MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
112 ucinbuf[0] = (rank < maxsize && rank > 0) ? rank : 1;
114 ucinbuf[2] = (rank > 0);
119 MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_PROD, 0, comm);
121 if (ucoutbuf[0] != (unsigned char) result[maxsize - 1]) {
123 fprintf(stderr, "unsigned char PROD(rank) test failed\n");
127 fprintf(stderr, "unsigned char PROD(0) test failed\n");
129 if (size > 1 && ucoutbuf[2]) {
131 fprintf(stderr, "unsigned char PROD(>) test failed\n");
135 #ifndef USE_STRICT_MPI
136 /* For some reason, complex is not allowed for sum and prod */
137 if (MPI_DOUBLE_COMPLEX != MPI_DATATYPE_NULL) {
139 #ifdef HAVE_LONG_DOUBLE
140 ld_complex ldinbuf[3], ldoutbuf[3];
141 MTEST_VG_MEM_INIT(ldinbuf, 3* sizeof(ldinbuf[0]));
143 /* Must determine which C type matches this Fortran type */
144 MPI_Type_size(MPI_DOUBLE_COMPLEX, &dc);
145 if (dc == sizeof(d_complex)) {
146 /* double complex; may be null if we do not have Fortran support */
147 dinbuf[0].r = (rank < maxsize && rank > 0) ? rank : 1;
149 dinbuf[2].r = (rank > 0);
152 dinbuf[2].i = -(rank > 0);
160 MPI_Reduce(dinbuf, doutbuf, 3, MPI_DOUBLE_COMPLEX, MPI_PROD, 0, comm);
163 if (doutbuf[0].r != (double) result[maxsize - 1] || doutbuf[0].i != 0) {
165 fprintf(stderr, "double complex PROD(rank) test failed\n");
167 /* Multiplying the imaginary part depends on size mod 4 */
169 real = 0.0; /* Make compiler happy */
188 if (doutbuf[1].r != real || doutbuf[1].i != imag) {
190 fprintf(stderr, "double complex PROD(i) test failed (%f,%f)!=(%f,%f)\n",
191 doutbuf[1].r, doutbuf[1].i, real, imag);
193 if (doutbuf[2].r != 0 || doutbuf[2].i != 0) {
195 fprintf(stderr, "double complex PROD(>) test failed\n");
199 #ifdef HAVE_LONG_DOUBLE
200 else if (dc == sizeof(ld_complex)) {
201 /* double complex; may be null if we do not have Fortran support */
202 ldinbuf[0].r = (rank < maxsize && rank > 0) ? rank : 1;
204 ldinbuf[2].r = (rank > 0);
207 ldinbuf[2].i = -(rank > 0);
215 MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_DOUBLE_COMPLEX, MPI_PROD, 0, comm);
217 long double imag, real;
218 if (ldoutbuf[0].r != (double) result[maxsize - 1] || ldoutbuf[0].i != 0) {
220 fprintf(stderr, "double complex PROD(rank) test failed\n");
222 /* Multiplying the imaginary part depends on size mod 4 */
224 real = 0.0; /* Make compiler happy */
243 if (ldoutbuf[1].r != real || ldoutbuf[1].i != imag) {
245 fprintf(stderr, "double complex PROD(i) test failed (%Lf,%Lf)!=(%Lf,%Lf)\n",
246 ldoutbuf[1].r, ldoutbuf[1].i, real, imag);
248 if (ldoutbuf[2].r != 0 || ldoutbuf[2].i != 0) {
250 fprintf(stderr, "double complex PROD(>) test failed\n");
254 #endif /* HAVE_LONG_DOUBLE */
256 #endif /* USE_STRICT_MPI */
258 #ifdef HAVE_LONG_DOUBLE
260 long double ldinbuf[3], ldoutbuf[3];
261 MTEST_VG_MEM_INIT(ldinbuf, 3 * sizeof(ldinbuf[0]));
263 ldinbuf[0] = (rank < maxsize && rank > 0) ? rank : 1;
265 ldinbuf[2] = (rank > 0);
270 if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
271 MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_PROD, 0, comm);
273 if (ldoutbuf[0] != (long double) result[maxsize - 1]) {
275 fprintf(stderr, "long double PROD(rank) test failed\n");
279 fprintf(stderr, "long double PROD(0) test failed\n");
281 if (size > 1 && ldoutbuf[2] != 0) {
283 fprintf(stderr, "long double PROD(>) test failed\n");
288 #endif /* HAVE_LONG_DOUBLE */
290 #ifdef HAVE_LONG_LONG
292 long long llinbuf[3], lloutbuf[3];
294 llinbuf[0] = (rank < maxsize && rank > 0) ? rank : 1;
296 llinbuf[2] = (rank > 0);
301 if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
302 MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_PROD, 0, comm);
304 if (lloutbuf[0] != (long long) result[maxsize - 1]) {
306 fprintf(stderr, "long long PROD(rank) test failed\n");
310 fprintf(stderr, "long long PROD(0) test failed\n");
312 if (size > 1 && lloutbuf[2]) {
314 fprintf(stderr, "long long PROD(>) test failed\n");
319 #endif /* HAVE_LONG_LONG */
321 MTest_Finalize(errs);