1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
#include "mpi.h"
#include "mpitestconf.h"
#include <stdio.h>
#include <string.h>
#include "mpitest.h"
/*
static char MTEST_Descrip[] = "Test MPI_MAXLOC operations on datatypes dupported by MPICH";
*/
/*
* This test looks at the handling of char and types that are not required
* integers (e.g., long long). MPICH allows
* these as well. A strict MPI test should not include this test.
*
* The rule on max loc is that if there is a tie in the value, the minimum
* rank is used (see 4.9.3 in the MPI-1 standard)
*/
int main(int argc, char *argv[])
{
int errs = 0;
int rank, size;
MPI_Comm comm;
MTest_Init(&argc, &argv);
comm = MPI_COMM_WORLD;
MPI_Comm_rank(comm, &rank);
MPI_Comm_size(comm, &size);
/* 2 int */
{
struct twoint {
int val;
int loc;
} cinbuf[3], coutbuf[3];
cinbuf[0].val = 1;
cinbuf[0].loc = rank;
cinbuf[1].val = 0;
cinbuf[1].loc = rank;
cinbuf[2].val = rank;
cinbuf[2].loc = rank;
coutbuf[0].val = 0;
coutbuf[0].loc = -1;
coutbuf[1].val = 1;
coutbuf[1].loc = -1;
coutbuf[2].val = 1;
coutbuf[2].loc = -1;
MPI_Reduce(cinbuf, coutbuf, 3, MPI_2INT, MPI_MAXLOC, 0, comm);
if (rank == 0) {
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
errs++;
fprintf(stderr, "2int MAXLOC(1) test failed\n");
}
if (coutbuf[1].val != 0) {
errs++;
fprintf(stderr, "2int MAXLOC(0) test failed, value = %d, should be zero\n",
coutbuf[1].val);
}
if (coutbuf[1].loc != 0) {
errs++;
fprintf(stderr,
"2int MAXLOC(0) test failed, location of max = %d, should be zero\n",
coutbuf[1].loc);
}
if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
errs++;
fprintf(stderr, "2int MAXLOC(>) test failed\n");
}
}
}
/* float int */
{
struct floatint {
float val;
int loc;
} cinbuf[3], coutbuf[3];
cinbuf[0].val = 1;
cinbuf[0].loc = rank;
cinbuf[1].val = 0;
cinbuf[1].loc = rank;
cinbuf[2].val = (float) rank;
cinbuf[2].loc = rank;
coutbuf[0].val = 0;
coutbuf[0].loc = -1;
coutbuf[1].val = 1;
coutbuf[1].loc = -1;
coutbuf[2].val = 1;
coutbuf[2].loc = -1;
MPI_Reduce(cinbuf, coutbuf, 3, MPI_FLOAT_INT, MPI_MAXLOC, 0, comm);
if (rank == 0) {
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
errs++;
fprintf(stderr, "float-int MAXLOC(1) test failed\n");
}
if (coutbuf[1].val != 0) {
errs++;
fprintf(stderr, "float-int MAXLOC(0) test failed, value = %f, should be zero\n",
coutbuf[1].val);
}
if (coutbuf[1].loc != 0) {
errs++;
fprintf(stderr,
"float-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
coutbuf[1].loc);
}
if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
errs++;
fprintf(stderr, "float-int MAXLOC(>) test failed\n");
}
}
}
/* long int */
{
struct longint {
long val;
int loc;
} cinbuf[3], coutbuf[3];
cinbuf[0].val = 1;
cinbuf[0].loc = rank;
cinbuf[1].val = 0;
cinbuf[1].loc = rank;
cinbuf[2].val = rank;
cinbuf[2].loc = rank;
coutbuf[0].val = 0;
coutbuf[0].loc = -1;
coutbuf[1].val = 1;
coutbuf[1].loc = -1;
coutbuf[2].val = 1;
coutbuf[2].loc = -1;
MPI_Reduce(cinbuf, coutbuf, 3, MPI_LONG_INT, MPI_MAXLOC, 0, comm);
if (rank == 0) {
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
errs++;
fprintf(stderr, "long-int MAXLOC(1) test failed\n");
}
if (coutbuf[1].val != 0) {
errs++;
fprintf(stderr, "long-int MAXLOC(0) test failed, value = %ld, should be zero\n",
coutbuf[1].val);
}
if (coutbuf[1].loc != 0) {
errs++;
fprintf(stderr,
"long-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
coutbuf[1].loc);
}
if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
errs++;
fprintf(stderr, "long-int MAXLOC(>) test failed\n");
}
}
}
/* short int */
{
struct shortint {
short val;
int loc;
} cinbuf[3], coutbuf[3];
cinbuf[0].val = 1;
cinbuf[0].loc = rank;
cinbuf[1].val = 0;
cinbuf[1].loc = rank;
cinbuf[2].val = rank;
cinbuf[2].loc = rank;
coutbuf[0].val = 0;
coutbuf[0].loc = -1;
coutbuf[1].val = 1;
coutbuf[1].loc = -1;
coutbuf[2].val = 1;
coutbuf[2].loc = -1;
MPI_Reduce(cinbuf, coutbuf, 3, MPI_SHORT_INT, MPI_MAXLOC, 0, comm);
if (rank == 0) {
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
errs++;
fprintf(stderr, "short-int MAXLOC(1) test failed\n");
}
if (coutbuf[1].val != 0) {
errs++;
fprintf(stderr, "short-int MAXLOC(0) test failed, value = %d, should be zero\n",
coutbuf[1].val);
}
if (coutbuf[1].loc != 0) {
errs++;
fprintf(stderr,
"short-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
coutbuf[1].loc);
}
if (coutbuf[2].val != size - 1) {
errs++;
fprintf(stderr, "short-int MAXLOC(>) test failed, value = %d, should be %d\n",
coutbuf[2].val, size - 1);
}
if (coutbuf[2].loc != size - 1) {
errs++;
fprintf(stderr,
"short-int MAXLOC(>) test failed, location of max = %d, should be %d\n",
coutbuf[2].loc, size - 1);
}
}
}
/* double int */
{
struct doubleint {
double val;
int loc;
} cinbuf[3], coutbuf[3];
cinbuf[0].val = 1;
cinbuf[0].loc = rank;
cinbuf[1].val = 0;
cinbuf[1].loc = rank;
cinbuf[2].val = rank;
cinbuf[2].loc = rank;
coutbuf[0].val = 0;
coutbuf[0].loc = -1;
coutbuf[1].val = 1;
coutbuf[1].loc = -1;
coutbuf[2].val = 1;
coutbuf[2].loc = -1;
MPI_Reduce(cinbuf, coutbuf, 3, MPI_DOUBLE_INT, MPI_MAXLOC, 0, comm);
if (rank == 0) {
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
errs++;
fprintf(stderr, "double-int MAXLOC(1) test failed\n");
}
if (coutbuf[1].val != 0) {
errs++;
fprintf(stderr, "double-int MAXLOC(0) test failed, value = %lf, should be zero\n",
coutbuf[1].val);
}
if (coutbuf[1].loc != 0) {
errs++;
fprintf(stderr,
"double-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
coutbuf[1].loc);
}
if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
errs++;
fprintf(stderr, "double-int MAXLOC(>) test failed\n");
}
}
}
#ifdef HAVE_LONG_DOUBLE
/* long double int */
{
struct longdoubleint {
long double val;
int loc;
} cinbuf[3], coutbuf[3];
/* avoid valgrind warnings about padding bytes in the long double */
memset(&cinbuf[0], 0, sizeof(cinbuf));
memset(&coutbuf[0], 0, sizeof(coutbuf));
cinbuf[0].val = 1;
cinbuf[0].loc = rank;
cinbuf[1].val = 0;
cinbuf[1].loc = rank;
cinbuf[2].val = rank;
cinbuf[2].loc = rank;
coutbuf[0].val = 0;
coutbuf[0].loc = -1;
coutbuf[1].val = 1;
coutbuf[1].loc = -1;
coutbuf[2].val = 1;
coutbuf[2].loc = -1;
if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
MPI_Reduce(cinbuf, coutbuf, 3, MPI_LONG_DOUBLE_INT, MPI_MAXLOC, 0, comm);
if (rank == 0) {
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
errs++;
fprintf(stderr, "long double-int MAXLOC(1) test failed\n");
}
if (coutbuf[1].val != 0) {
errs++;
fprintf(stderr,
"long double-int MAXLOC(0) test failed, value = %lf, should be zero\n",
(double) coutbuf[1].val);
}
if (coutbuf[1].loc != 0) {
errs++;
fprintf(stderr,
"long double-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
coutbuf[1].loc);
}
if (coutbuf[2].val != size - 1) {
errs++;
fprintf(stderr,
"long double-int MAXLOC(>) test failed, value = %lf, should be %d\n",
(double) coutbuf[2].val, size - 1);
}
if (coutbuf[2].loc != size - 1) {
errs++;
fprintf(stderr,
"long double-int MAXLOC(>) test failed, location of max = %d, should be %d\n",
coutbuf[2].loc, size - 1);
}
}
}
}
#endif
MTest_Finalize(errs);
return MTestReturnValue(errs);
}
|