|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* (C) 2003 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
#include "mpi.h"
|
|
Packit |
0848f5 |
#include "mpitestconf.h"
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
#include <string.h>
|
|
Packit |
0848f5 |
#include "mpitest.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
static char MTEST_Descrip[] = "Test MPI_MAXLOC operations on datatypes dupported by MPICH";
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* This test looks at the handling of char and types that are not required
|
|
Packit |
0848f5 |
* integers (e.g., long long). MPICH allows
|
|
Packit |
0848f5 |
* these as well. A strict MPI test should not include this test.
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* The rule on max loc is that if there is a tie in the value, the minimum
|
|
Packit |
0848f5 |
* rank is used (see 4.9.3 in the MPI-1 standard)
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int errs = 0;
|
|
Packit |
0848f5 |
int rank, size;
|
|
Packit |
0848f5 |
MPI_Comm comm;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init(&argc, &argv);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
comm = MPI_COMM_WORLD;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Comm_rank(comm, &rank;;
|
|
Packit |
0848f5 |
MPI_Comm_size(comm, &size);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* 2 int */
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
struct twoint {
|
|
Packit |
0848f5 |
int val;
|
|
Packit |
0848f5 |
int loc;
|
|
Packit |
0848f5 |
} cinbuf[3], coutbuf[3];
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
cinbuf[0].val = 1;
|
|
Packit |
0848f5 |
cinbuf[0].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[1].val = 0;
|
|
Packit |
0848f5 |
cinbuf[1].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[2].val = rank;
|
|
Packit |
0848f5 |
cinbuf[2].loc = rank;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
coutbuf[0].val = 0;
|
|
Packit |
0848f5 |
coutbuf[0].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[1].val = 1;
|
|
Packit |
0848f5 |
coutbuf[1].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[2].val = 1;
|
|
Packit |
0848f5 |
coutbuf[2].loc = -1;
|
|
Packit |
0848f5 |
MPI_Reduce(cinbuf, coutbuf, 3, MPI_2INT, MPI_MAXLOC, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "2int MAXLOC(1) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].val != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "2int MAXLOC(0) test failed, value = %d, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].val);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr,
|
|
Packit |
0848f5 |
"2int MAXLOC(0) test failed, location of max = %d, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].loc);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "2int MAXLOC(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* float int */
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
struct floatint {
|
|
Packit |
0848f5 |
float val;
|
|
Packit |
0848f5 |
int loc;
|
|
Packit |
0848f5 |
} cinbuf[3], coutbuf[3];
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
cinbuf[0].val = 1;
|
|
Packit |
0848f5 |
cinbuf[0].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[1].val = 0;
|
|
Packit |
0848f5 |
cinbuf[1].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[2].val = (float) rank;
|
|
Packit |
0848f5 |
cinbuf[2].loc = rank;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
coutbuf[0].val = 0;
|
|
Packit |
0848f5 |
coutbuf[0].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[1].val = 1;
|
|
Packit |
0848f5 |
coutbuf[1].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[2].val = 1;
|
|
Packit |
0848f5 |
coutbuf[2].loc = -1;
|
|
Packit |
0848f5 |
MPI_Reduce(cinbuf, coutbuf, 3, MPI_FLOAT_INT, MPI_MAXLOC, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "float-int MAXLOC(1) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].val != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "float-int MAXLOC(0) test failed, value = %f, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].val);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr,
|
|
Packit |
0848f5 |
"float-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].loc);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "float-int MAXLOC(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* long int */
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
struct longint {
|
|
Packit |
0848f5 |
long val;
|
|
Packit |
0848f5 |
int loc;
|
|
Packit |
0848f5 |
} cinbuf[3], coutbuf[3];
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
cinbuf[0].val = 1;
|
|
Packit |
0848f5 |
cinbuf[0].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[1].val = 0;
|
|
Packit |
0848f5 |
cinbuf[1].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[2].val = rank;
|
|
Packit |
0848f5 |
cinbuf[2].loc = rank;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
coutbuf[0].val = 0;
|
|
Packit |
0848f5 |
coutbuf[0].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[1].val = 1;
|
|
Packit |
0848f5 |
coutbuf[1].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[2].val = 1;
|
|
Packit |
0848f5 |
coutbuf[2].loc = -1;
|
|
Packit |
0848f5 |
MPI_Reduce(cinbuf, coutbuf, 3, MPI_LONG_INT, MPI_MAXLOC, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "long-int MAXLOC(1) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].val != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "long-int MAXLOC(0) test failed, value = %ld, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].val);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr,
|
|
Packit |
0848f5 |
"long-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].loc);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "long-int MAXLOC(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* short int */
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
struct shortint {
|
|
Packit |
0848f5 |
short val;
|
|
Packit |
0848f5 |
int loc;
|
|
Packit |
0848f5 |
} cinbuf[3], coutbuf[3];
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
cinbuf[0].val = 1;
|
|
Packit |
0848f5 |
cinbuf[0].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[1].val = 0;
|
|
Packit |
0848f5 |
cinbuf[1].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[2].val = rank;
|
|
Packit |
0848f5 |
cinbuf[2].loc = rank;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
coutbuf[0].val = 0;
|
|
Packit |
0848f5 |
coutbuf[0].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[1].val = 1;
|
|
Packit |
0848f5 |
coutbuf[1].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[2].val = 1;
|
|
Packit |
0848f5 |
coutbuf[2].loc = -1;
|
|
Packit |
0848f5 |
MPI_Reduce(cinbuf, coutbuf, 3, MPI_SHORT_INT, MPI_MAXLOC, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "short-int MAXLOC(1) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].val != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "short-int MAXLOC(0) test failed, value = %d, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].val);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr,
|
|
Packit |
0848f5 |
"short-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].loc);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[2].val != size - 1) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "short-int MAXLOC(>) test failed, value = %d, should be %d\n",
|
|
Packit |
0848f5 |
coutbuf[2].val, size - 1);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[2].loc != size - 1) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr,
|
|
Packit |
0848f5 |
"short-int MAXLOC(>) test failed, location of max = %d, should be %d\n",
|
|
Packit |
0848f5 |
coutbuf[2].loc, size - 1);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* double int */
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
struct doubleint {
|
|
Packit |
0848f5 |
double val;
|
|
Packit |
0848f5 |
int loc;
|
|
Packit |
0848f5 |
} cinbuf[3], coutbuf[3];
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
cinbuf[0].val = 1;
|
|
Packit |
0848f5 |
cinbuf[0].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[1].val = 0;
|
|
Packit |
0848f5 |
cinbuf[1].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[2].val = rank;
|
|
Packit |
0848f5 |
cinbuf[2].loc = rank;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
coutbuf[0].val = 0;
|
|
Packit |
0848f5 |
coutbuf[0].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[1].val = 1;
|
|
Packit |
0848f5 |
coutbuf[1].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[2].val = 1;
|
|
Packit |
0848f5 |
coutbuf[2].loc = -1;
|
|
Packit |
0848f5 |
MPI_Reduce(cinbuf, coutbuf, 3, MPI_DOUBLE_INT, MPI_MAXLOC, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "double-int MAXLOC(1) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].val != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "double-int MAXLOC(0) test failed, value = %lf, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].val);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr,
|
|
Packit |
0848f5 |
"double-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].loc);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[2].val != size - 1 || coutbuf[2].loc != size - 1) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "double-int MAXLOC(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#ifdef HAVE_LONG_DOUBLE
|
|
Packit |
0848f5 |
/* long double int */
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
struct longdoubleint {
|
|
Packit |
0848f5 |
long double val;
|
|
Packit |
0848f5 |
int loc;
|
|
Packit |
0848f5 |
} cinbuf[3], coutbuf[3];
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* avoid valgrind warnings about padding bytes in the long double */
|
|
Packit |
0848f5 |
memset(&cinbuf[0], 0, sizeof(cinbuf));
|
|
Packit |
0848f5 |
memset(&coutbuf[0], 0, sizeof(coutbuf));
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
cinbuf[0].val = 1;
|
|
Packit |
0848f5 |
cinbuf[0].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[1].val = 0;
|
|
Packit |
0848f5 |
cinbuf[1].loc = rank;
|
|
Packit |
0848f5 |
cinbuf[2].val = rank;
|
|
Packit |
0848f5 |
cinbuf[2].loc = rank;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
coutbuf[0].val = 0;
|
|
Packit |
0848f5 |
coutbuf[0].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[1].val = 1;
|
|
Packit |
0848f5 |
coutbuf[1].loc = -1;
|
|
Packit |
0848f5 |
coutbuf[2].val = 1;
|
|
Packit |
0848f5 |
coutbuf[2].loc = -1;
|
|
Packit |
0848f5 |
if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
|
|
Packit |
0848f5 |
MPI_Reduce(cinbuf, coutbuf, 3, MPI_LONG_DOUBLE_INT, MPI_MAXLOC, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "long double-int MAXLOC(1) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].val != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr,
|
|
Packit |
0848f5 |
"long double-int MAXLOC(0) test failed, value = %lf, should be zero\n",
|
|
Packit |
0848f5 |
(double) coutbuf[1].val);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1].loc != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr,
|
|
Packit |
0848f5 |
"long double-int MAXLOC(0) test failed, location of max = %d, should be zero\n",
|
|
Packit |
0848f5 |
coutbuf[1].loc);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[2].val != size - 1) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr,
|
|
Packit |
0848f5 |
"long double-int MAXLOC(>) test failed, value = %lf, should be %d\n",
|
|
Packit |
0848f5 |
(double) coutbuf[2].val, size - 1);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[2].loc != size - 1) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr,
|
|
Packit |
0848f5 |
"long double-int MAXLOC(>) test failed, location of max = %d, should be %d\n",
|
|
Packit |
0848f5 |
coutbuf[2].loc, size - 1);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
#endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Finalize(errs);
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|