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);
42 } cinbuf[3], coutbuf[3];
48 cinbuf[2].val = (rank & 0x7f);
57 MPI_Reduce(cinbuf, coutbuf, 3, MPI_2INT, MPI_MINLOC, 0, comm);
59 if (coutbuf[0].val != 1 && coutbuf[0].loc != -1) {
61 fprintf(stderr, "2int MINLOC(1) test failed\n");
63 if (coutbuf[1].val != 0 && coutbuf[1].loc != -1) {
65 fprintf(stderr, "2int MINLOC(0) test failed\n");
67 if (coutbuf[2].val != 0 && coutbuf[2].loc != 0) {
69 fprintf(stderr, "2int MINLOC(>) test failed\n");
79 } cinbuf[3], coutbuf[3];
85 cinbuf[2].val = (float) rank;
94 MPI_Reduce(cinbuf, coutbuf, 3, MPI_FLOAT_INT, MPI_MINLOC, 0, comm);
96 if (coutbuf[0].val != 1 && coutbuf[0].loc != -1) {
98 fprintf(stderr, "float-int MINLOC(1) test failed\n");
100 if (coutbuf[1].val != 0 && coutbuf[1].loc != -1) {
102 fprintf(stderr, "float-int MINLOC(0) test failed\n");
104 if (coutbuf[2].val != 0 && coutbuf[2].loc != 0) {
106 fprintf(stderr, "float-int MINLOC(>) test failed\n");
116 } 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_MINLOC, 0, comm);
133 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
135 fprintf(stderr, "long-int MINLOC(1) test failed\n");
137 if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
139 fprintf(stderr, "long-int MINLOC(0) test failed\n");
141 if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
143 fprintf(stderr, "long-int MINLOC(>) test failed\n");
153 } cinbuf[3], coutbuf[3];
156 cinbuf[0].loc = rank;
158 cinbuf[1].loc = rank;
159 cinbuf[2].val = rank;
160 cinbuf[2].loc = rank;
168 MPI_Reduce(cinbuf, coutbuf, 3, MPI_SHORT_INT, MPI_MINLOC, 0, comm);
170 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
172 fprintf(stderr, "short-int MINLOC(1) test failed\n");
174 if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
176 fprintf(stderr, "short-int MINLOC(0) test failed\n");
178 if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
180 fprintf(stderr, "short-int MINLOC(>) test failed\n");
190 } cinbuf[3], coutbuf[3];
193 cinbuf[0].loc = rank;
195 cinbuf[1].loc = rank;
196 cinbuf[2].val = rank;
197 cinbuf[2].loc = rank;
205 MPI_Reduce(cinbuf, coutbuf, 3, MPI_DOUBLE_INT, MPI_MINLOC, 0, comm);
207 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
209 fprintf(stderr, "double-int MINLOC(1) test failed\n");
211 if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
213 fprintf(stderr, "double-int MINLOC(0) test failed\n");
215 if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
217 fprintf(stderr, "double-int MINLOC(>) test failed\n");
222 #ifdef HAVE_LONG_DOUBLE
223 /* long double int */
225 struct longdoubleint {
228 } cinbuf[3], coutbuf[3];
229 MTEST_VG_MEM_INIT(cinbuf, 3* sizeof(cinbuf[0]));
232 cinbuf[0].loc = rank;
234 cinbuf[1].loc = rank;
235 cinbuf[2].val = rank;
236 cinbuf[2].loc = rank;
244 if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
245 MPI_Reduce(cinbuf, coutbuf, 3, MPI_LONG_DOUBLE_INT, MPI_MINLOC, 0, comm);
247 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
249 fprintf(stderr, "long double-int MINLOC(1) test failed\n");
251 if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
253 fprintf(stderr, "long double-int MINLOC(0) test failed\n");
255 if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
257 fprintf(stderr, "long double-int MINLOC(>) test failed\n");
264 MTest_Finalize(errs);