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"
14 static char MTEST_Descrip[] = "Test MPI_MAXLOC operations on datatypes dupported by MPICH";
18 * This test looks at the handling of char and types that are not required
19 * integers (e.g., long long). MPICH allows
20 * these as well. A strict MPI test should not include this test.
22 * The rule on max loc is that if there is a tie in the value, the minimum
23 * rank is used (see 4.9.3 in the MPI-1 standard)
25 int main(int argc, char *argv[])
31 MTest_Init(&argc, &argv);
33 comm = MPI_COMM_WORLD;
35 MPI_Comm_rank(comm, &rank);
36 MPI_Comm_size(comm, &size);
43 } cinbuf[3], coutbuf[3];
58 MPI_Reduce(cinbuf, coutbuf, 3, MPI_2INT, MPI_MAXLOC, 0, comm);
60 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
62 fprintf(stderr, "2int MAXLOC(1) test failed\n");
64 if (coutbuf[1].val != 0) {
66 fprintf(stderr, "2int MAXLOC(0) test failed, value = %d, should be zero\n",
69 if (coutbuf[1].loc != 0) {
72 "2int MAXLOC(0) test failed, location of max = %d, should be zero\n",
75 if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
77 fprintf(stderr, "2int MAXLOC(>) test failed\n");
87 } cinbuf[3], coutbuf[3];
93 cinbuf[2].val = (float) rank;
102 MPI_Reduce(cinbuf, coutbuf, 3, MPI_FLOAT_INT, MPI_MAXLOC, 0, comm);
104 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
106 fprintf(stderr, "float-int MAXLOC(1) test failed\n");
108 if (coutbuf[1].val != 0) {
110 fprintf(stderr, "float-int MAXLOC(0) test failed, value = %f, should be zero\n",
113 if (coutbuf[1].loc != 0) {
116 "float-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
119 if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
121 fprintf(stderr, "float-int MAXLOC(>) test failed\n");
131 } cinbuf[3], coutbuf[3];
134 cinbuf[0].loc = rank;
136 cinbuf[1].loc = rank;
137 cinbuf[2].val = rank;
138 cinbuf[2].loc = rank;
146 MPI_Reduce(cinbuf, coutbuf, 3, MPI_LONG_INT, MPI_MAXLOC, 0, comm);
148 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
150 fprintf(stderr, "long-int MAXLOC(1) test failed\n");
152 if (coutbuf[1].val != 0) {
154 fprintf(stderr, "long-int MAXLOC(0) test failed, value = %ld, should be zero\n",
157 if (coutbuf[1].loc != 0) {
160 "long-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
163 if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
165 fprintf(stderr, "long-int MAXLOC(>) test failed\n");
175 } cinbuf[3], coutbuf[3];
178 cinbuf[0].loc = rank;
180 cinbuf[1].loc = rank;
181 cinbuf[2].val = rank;
182 cinbuf[2].loc = rank;
190 MPI_Reduce(cinbuf, coutbuf, 3, MPI_SHORT_INT, MPI_MAXLOC, 0, comm);
192 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
194 fprintf(stderr, "short-int MAXLOC(1) test failed\n");
196 if (coutbuf[1].val != 0) {
198 fprintf(stderr, "short-int MAXLOC(0) test failed, value = %d, should be zero\n",
201 if (coutbuf[1].loc != 0) {
204 "short-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
207 if (coutbuf[2].val != size - 1) {
209 fprintf(stderr, "short-int MAXLOC(>) test failed, value = %d, should be %d\n",
210 coutbuf[2].val, size - 1);
212 if (coutbuf[2].loc != size - 1) {
215 "short-int MAXLOC(>) test failed, location of max = %d, should be %d\n",
216 coutbuf[2].loc, size - 1);
226 } cinbuf[3], coutbuf[3];
229 cinbuf[0].loc = rank;
231 cinbuf[1].loc = rank;
232 cinbuf[2].val = rank;
233 cinbuf[2].loc = rank;
241 MPI_Reduce(cinbuf, coutbuf, 3, MPI_DOUBLE_INT, MPI_MAXLOC, 0, comm);
243 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
245 fprintf(stderr, "double-int MAXLOC(1) test failed\n");
247 if (coutbuf[1].val != 0) {
249 fprintf(stderr, "double-int MAXLOC(0) test failed, value = %lf, should be zero\n",
252 if (coutbuf[1].loc != 0) {
255 "double-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
258 if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
260 fprintf(stderr, "double-int MAXLOC(>) test failed\n");
265 #ifdef HAVE_LONG_DOUBLE
266 /* long double int */
268 struct longdoubleint {
271 } cinbuf[3], coutbuf[3];
273 /* avoid valgrind warnings about padding bytes in the long double */
274 memset(&cinbuf[0], 0, sizeof(cinbuf));
275 memset(&coutbuf[0], 0, sizeof(coutbuf));
278 cinbuf[0].loc = rank;
280 cinbuf[1].loc = rank;
281 cinbuf[2].val = rank;
282 cinbuf[2].loc = rank;
290 if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
291 MPI_Reduce(cinbuf, coutbuf, 3, MPI_LONG_DOUBLE_INT, MPI_MAXLOC, 0, comm);
293 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
295 fprintf(stderr, "long double-int MAXLOC(1) test failed\n");
297 if (coutbuf[1].val != 0) {
300 "long double-int MAXLOC(0) test failed, value = %lf, should be zero\n",
301 (double) coutbuf[1].val);
303 if (coutbuf[1].loc != 0) {
306 "long double-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
309 if (coutbuf[2].val != size - 1) {
312 "long double-int MAXLOC(>) test failed, value = %lf, should be %d\n",
313 (double) coutbuf[2].val, size - 1);
315 if (coutbuf[2].loc != size - 1) {
318 "long double-int MAXLOC(>) test failed, location of max = %d, should be %d\n",
319 coutbuf[2].loc, size - 1);
326 MTest_Finalize(errs);