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_MINLOC operations on datatypes dupported by MPICH";
17 * This test looks at the handling of char and types that are not required
18 * integers (e.g., long long). MPICH allows
19 * these as well. A strict MPI test should not include this test.
21 * The rule on min loc is that if there is a tie in the value, the minimum
22 * rank is used (see 4.9.3 in the MPI-1 standard)
24 int main( int argc, char *argv[] )
30 MTest_Init( &argc, &argv );
32 comm = MPI_COMM_WORLD;
34 MPI_Comm_rank( comm, &rank );
35 MPI_Comm_size( comm, &size );
39 struct twoint { int val; int loc; } cinbuf[3], coutbuf[3];
45 cinbuf[2].val = (rank & 0x7f);
54 MPI_Reduce( cinbuf, coutbuf, 3, MPI_2INT, MPI_MINLOC, 0, comm );
56 if (coutbuf[0].val != 1 && coutbuf[0].loc != -1) {
58 fprintf( stderr, "2int MINLOC(1) test failed\n" );
60 if (coutbuf[1].val != 0 && coutbuf[1].loc != -1) {
62 fprintf( stderr, "2int MINLOC(0) test failed\n" );
64 if (coutbuf[2].val != 0 && coutbuf[2].loc != 0) {
66 fprintf( stderr, "2int MINLOC(>) test failed\n" );
73 struct floatint { float val; int loc; } cinbuf[3], coutbuf[3];
79 cinbuf[2].val = (float)rank;
88 MPI_Reduce( cinbuf, coutbuf, 3, MPI_FLOAT_INT, MPI_MINLOC, 0, comm );
90 if (coutbuf[0].val != 1 && coutbuf[0].loc != -1) {
92 fprintf( stderr, "float-int MINLOC(1) test failed\n" );
94 if (coutbuf[1].val != 0 && coutbuf[1].loc != -1) {
96 fprintf( stderr, "float-int MINLOC(0) test failed\n" );
98 if (coutbuf[2].val != 0 && coutbuf[2].loc != 0) {
100 fprintf( stderr, "float-int MINLOC(>) test failed\n" );
107 struct longint { long val; int loc; } cinbuf[3], coutbuf[3];
110 cinbuf[0].loc = rank;
112 cinbuf[1].loc = rank;
113 cinbuf[2].val = rank;
114 cinbuf[2].loc = rank;
122 MPI_Reduce( cinbuf, coutbuf, 3, MPI_LONG_INT, MPI_MINLOC, 0, comm );
124 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
126 fprintf( stderr, "long-int MINLOC(1) test failed\n" );
128 if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
130 fprintf( stderr, "long-int MINLOC(0) test failed\n" );
132 if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
134 fprintf( stderr, "long-int MINLOC(>) test failed\n" );
141 struct shortint { short val; int loc; } cinbuf[3], coutbuf[3];
144 cinbuf[0].loc = rank;
146 cinbuf[1].loc = rank;
147 cinbuf[2].val = rank;
148 cinbuf[2].loc = rank;
156 MPI_Reduce( cinbuf, coutbuf, 3, MPI_SHORT_INT, MPI_MINLOC, 0, comm );
158 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
160 fprintf( stderr, "short-int MINLOC(1) test failed\n" );
162 if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
164 fprintf( stderr, "short-int MINLOC(0) test failed\n" );
166 if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
168 fprintf( stderr, "short-int MINLOC(>) test failed\n" );
175 struct doubleint { double val; int loc; } 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_DOUBLE_INT, MPI_MINLOC, 0, comm );
192 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
194 fprintf( stderr, "double-int MINLOC(1) test failed\n" );
196 if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
198 fprintf( stderr, "double-int MINLOC(0) test failed\n" );
200 if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
202 fprintf( stderr, "double-int MINLOC(>) test failed\n" );
207 #ifdef HAVE_LONG_DOUBLE
208 /* long double int */
210 struct longdoubleint { long double val; int loc; } cinbuf[3], coutbuf[3];
213 cinbuf[0].loc = rank;
215 cinbuf[1].loc = rank;
216 cinbuf[2].val = rank;
217 cinbuf[2].loc = rank;
225 if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
226 MPI_Reduce( cinbuf, coutbuf, 3, MPI_LONG_DOUBLE_INT, MPI_MINLOC,
229 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
231 fprintf( stderr, "long double-int MINLOC(1) test failed\n" );
233 if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
235 fprintf( stderr, "long double-int MINLOC(0) test failed\n" );
237 if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
239 fprintf( stderr, "long double-int MINLOC(>) test failed\n" );
246 MTest_Finalize( errs );