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 );
40 struct twoint { int val; int loc; } cinbuf[3], coutbuf[3];
55 MPI_Reduce( cinbuf, coutbuf, 3, MPI_2INT, MPI_MAXLOC, 0, comm );
57 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
59 fprintf( stderr, "2int MAXLOC(1) test failed\n" );
61 if (coutbuf[1].val != 0) {
63 fprintf( stderr, "2int MAXLOC(0) test failed, value = %d, should be zero\n", coutbuf[1].val );
65 if (coutbuf[1].loc != 0) {
67 fprintf( stderr, "2int MAXLOC(0) test failed, location of max = %d, should be zero\n", coutbuf[1].loc );
69 if (coutbuf[2].val != size-1 || coutbuf[2].loc != size-1) {
71 fprintf( stderr, "2int MAXLOC(>) test failed\n" );
78 struct floatint { float val; int loc; } cinbuf[3], coutbuf[3];
84 cinbuf[2].val = (float)rank;
93 MPI_Reduce( cinbuf, coutbuf, 3, MPI_FLOAT_INT, MPI_MAXLOC, 0, comm );
95 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
97 fprintf( stderr, "float-int MAXLOC(1) test failed\n" );
99 if (coutbuf[1].val != 0) {
101 fprintf( stderr, "float-int MAXLOC(0) test failed, value = %f, should be zero\n", coutbuf[1].val );
103 if (coutbuf[1].loc != 0) {
105 fprintf( stderr, "float-int MAXLOC(0) test failed, location of max = %d, should be zero\n", coutbuf[1].loc );
107 if (coutbuf[2].val != size-1 || coutbuf[2].loc != size-1) {
109 fprintf( stderr, "float-int MAXLOC(>) test failed\n" );
116 struct longint { long val; int loc; } cinbuf[3], coutbuf[3];
119 cinbuf[0].loc = rank;
121 cinbuf[1].loc = rank;
122 cinbuf[2].val = rank;
123 cinbuf[2].loc = rank;
131 MPI_Reduce( cinbuf, coutbuf, 3, MPI_LONG_INT, MPI_MAXLOC, 0, comm );
133 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
135 fprintf( stderr, "long-int MAXLOC(1) test failed\n" );
137 if (coutbuf[1].val != 0) {
139 fprintf( stderr, "long-int MAXLOC(0) test failed, value = %ld, should be zero\n", coutbuf[1].val );
141 if (coutbuf[1].loc != 0) {
143 fprintf( stderr, "long-int MAXLOC(0) test failed, location of max = %d, should be zero\n", coutbuf[1].loc );
145 if (coutbuf[2].val != size-1 || coutbuf[2].loc != size-1) {
147 fprintf( stderr, "long-int MAXLOC(>) test failed\n" );
154 struct shortint { short val; int loc; } cinbuf[3], coutbuf[3];
157 cinbuf[0].loc = rank;
159 cinbuf[1].loc = rank;
160 cinbuf[2].val = rank;
161 cinbuf[2].loc = rank;
169 MPI_Reduce( cinbuf, coutbuf, 3, MPI_SHORT_INT, MPI_MAXLOC, 0, comm );
171 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
173 fprintf( stderr, "short-int MAXLOC(1) test failed\n" );
175 if (coutbuf[1].val != 0) {
177 fprintf( stderr, "short-int MAXLOC(0) test failed, value = %d, should be zero\n", coutbuf[1].val );
179 if (coutbuf[1].loc != 0) {
181 fprintf( stderr, "short-int MAXLOC(0) test failed, location of max = %d, should be zero\n", coutbuf[1].loc );
183 if (coutbuf[2].val != size-1) {
185 fprintf( stderr, "short-int MAXLOC(>) test failed, value = %d, should be %d\n", coutbuf[2].val, size-1 );
187 if (coutbuf[2].loc != size -1) {
189 fprintf( stderr, "short-int MAXLOC(>) test failed, location of max = %d, should be %d\n", coutbuf[2].loc, size-1 );
196 struct doubleint { double val; int loc; } cinbuf[3], coutbuf[3];
199 cinbuf[0].loc = rank;
201 cinbuf[1].loc = rank;
202 cinbuf[2].val = rank;
203 cinbuf[2].loc = rank;
211 MPI_Reduce( cinbuf, coutbuf, 3, MPI_DOUBLE_INT, MPI_MAXLOC, 0, comm );
213 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
215 fprintf( stderr, "double-int MAXLOC(1) test failed\n" );
217 if (coutbuf[1].val != 0) {
219 fprintf( stderr, "double-int MAXLOC(0) test failed, value = %f, should be zero\n", coutbuf[1].val );
221 if (coutbuf[1].loc != 0) {
223 fprintf( stderr, "double-int MAXLOC(0) test failed, location of max = %d, should be zero\n", coutbuf[1].loc );
225 if (coutbuf[2].val != size-1 || coutbuf[2].loc != size-1) {
227 fprintf( stderr, "double-int MAXLOC(>) test failed\n" );
232 #ifdef HAVE_LONG_DOUBLE
233 /* long double int */
235 struct longdoubleint { long double val; int loc; } cinbuf[3], coutbuf[3];
237 /* avoid valgrind warnings about padding bytes in the long double */
238 memset(&cinbuf[0], 0, sizeof(cinbuf));
239 memset(&coutbuf[0], 0, sizeof(coutbuf));
242 cinbuf[0].loc = rank;
244 cinbuf[1].loc = rank;
245 cinbuf[2].val = rank;
246 cinbuf[2].loc = rank;
254 if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
255 MPI_Reduce( cinbuf, coutbuf, 3, MPI_LONG_DOUBLE_INT, MPI_MAXLOC,
258 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
260 fprintf( stderr, "long double-int MAXLOC(1) test failed\n" );
262 if (coutbuf[1].val != 0) {
264 fprintf( stderr, "long double-int MAXLOC(0) test failed, value = %f, should be zero\n", (double)coutbuf[1].val );
266 if (coutbuf[1].loc != 0) {
268 fprintf( stderr, "long double-int MAXLOC(0) test failed, location of max = %d, should be zero\n", coutbuf[1].loc );
270 if (coutbuf[2].val != size-1) {
272 fprintf( stderr, "long double-int MAXLOC(>) test failed, value = %f, should be %d\n", (double)coutbuf[2].val, size-1 );
274 if (coutbuf[2].loc != size-1) {
276 fprintf( stderr, "long double-int MAXLOC(>) test failed, location of max = %d, should be %d\n", coutbuf[2].loc, size-1 );
283 MTest_Finalize( errs );