|
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 "mpitest.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
static char MTEST_Descrip[] = "Test MPI_PROD operations on optional datatypes dupported by MPICH";
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
typedef struct {
|
|
Packit |
0848f5 |
double r, i;
|
|
Packit |
0848f5 |
} d_complex;
|
|
Packit |
0848f5 |
#ifdef HAVE_LONG_DOUBLE
|
|
Packit |
0848f5 |
typedef struct {
|
|
Packit |
0848f5 |
long double r, i;
|
|
Packit |
0848f5 |
} ld_complex;
|
|
Packit |
0848f5 |
#endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* This test looks at the handling of logical and for types that are not
|
|
Packit |
0848f5 |
* integers or are not required 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 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int errs = 0;
|
|
Packit |
0848f5 |
int rank, size, maxsize, result[6] = { 1, 1, 2, 6, 24, 120 };
|
|
Packit |
0848f5 |
MPI_Comm comm;
|
|
Packit |
0848f5 |
char cinbuf[3], coutbuf[3];
|
|
Packit |
0848f5 |
signed char scinbuf[3], scoutbuf[3];
|
|
Packit |
0848f5 |
unsigned char ucinbuf[3], ucoutbuf[3];
|
|
Packit |
0848f5 |
d_complex dinbuf[3], doutbuf[3];
|
|
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 |
if (size > 5)
|
|
Packit |
0848f5 |
maxsize = 5;
|
|
Packit |
0848f5 |
else
|
|
Packit |
0848f5 |
maxsize = size;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* General forumula: If we multiple the values from 1 to n, the
|
|
Packit |
0848f5 |
* product is n!. This grows very fast, so we'll only use the first
|
|
Packit |
0848f5 |
* five (1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120), with n!
|
|
Packit |
0848f5 |
* stored in the array result[n] */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#ifndef USE_STRICT_MPI
|
|
Packit |
0848f5 |
/* char */
|
|
Packit |
0848f5 |
MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
|
|
Packit |
0848f5 |
cinbuf[0] = (rank < maxsize && rank > 0) ? rank : 1;
|
|
Packit |
0848f5 |
cinbuf[1] = 0;
|
|
Packit |
0848f5 |
cinbuf[2] = (rank > 1);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
coutbuf[0] = 0;
|
|
Packit |
0848f5 |
coutbuf[1] = 1;
|
|
Packit |
0848f5 |
coutbuf[2] = 1;
|
|
Packit |
0848f5 |
MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_PROD, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (coutbuf[0] != (char) result[maxsize - 1]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "char PROD(rank) test failed (%d!=%d)\n",
|
|
Packit |
0848f5 |
(int) coutbuf[0], (int) result[maxsize]);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (coutbuf[1]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "char PROD(0) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (size > 1 && coutbuf[2]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "char PROD(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
#endif /* USE_STRICT_MPI */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* signed char */
|
|
Packit |
0848f5 |
MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
|
|
Packit |
0848f5 |
scinbuf[0] = (rank < maxsize && rank > 0) ? rank : 1;
|
|
Packit |
0848f5 |
scinbuf[1] = 0;
|
|
Packit |
0848f5 |
scinbuf[2] = (rank > 1);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
scoutbuf[0] = 0;
|
|
Packit |
0848f5 |
scoutbuf[1] = 1;
|
|
Packit |
0848f5 |
scoutbuf[2] = 1;
|
|
Packit |
0848f5 |
MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_PROD, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (scoutbuf[0] != (signed char) result[maxsize - 1]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "signed char PROD(rank) test failed (%d!=%d)\n",
|
|
Packit |
0848f5 |
(int) scoutbuf[0], (int) result[maxsize]);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (scoutbuf[1]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "signed char PROD(0) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (size > 1 && scoutbuf[2]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "signed char PROD(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* unsigned char */
|
|
Packit |
0848f5 |
MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
|
|
Packit |
0848f5 |
ucinbuf[0] = (rank < maxsize && rank > 0) ? rank : 1;
|
|
Packit |
0848f5 |
ucinbuf[1] = 0;
|
|
Packit |
0848f5 |
ucinbuf[2] = (rank > 0);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
ucoutbuf[0] = 0;
|
|
Packit |
0848f5 |
ucoutbuf[1] = 1;
|
|
Packit |
0848f5 |
ucoutbuf[2] = 1;
|
|
Packit |
0848f5 |
MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_PROD, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (ucoutbuf[0] != (unsigned char) result[maxsize - 1]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "unsigned char PROD(rank) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (ucoutbuf[1]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "unsigned char PROD(0) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (size > 1 && ucoutbuf[2]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "unsigned char PROD(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#ifndef USE_STRICT_MPI
|
|
Packit |
0848f5 |
/* For some reason, complex is not allowed for sum and prod */
|
|
Packit |
0848f5 |
if (MPI_DOUBLE_COMPLEX != MPI_DATATYPE_NULL) {
|
|
Packit |
0848f5 |
int dc;
|
|
Packit |
0848f5 |
#ifdef HAVE_LONG_DOUBLE
|
|
Packit |
0848f5 |
ld_complex ldinbuf[3], ldoutbuf[3];
|
|
Packit |
0848f5 |
MTEST_VG_MEM_INIT(ldinbuf, 3* sizeof(ldinbuf[0]));
|
|
Packit |
0848f5 |
#endif
|
|
Packit |
0848f5 |
/* Must determine which C type matches this Fortran type */
|
|
Packit |
0848f5 |
MPI_Type_size(MPI_DOUBLE_COMPLEX, &dc);
|
|
Packit |
0848f5 |
if (dc == sizeof(d_complex)) {
|
|
Packit |
0848f5 |
/* double complex; may be null if we do not have Fortran support */
|
|
Packit |
0848f5 |
dinbuf[0].r = (rank < maxsize && rank > 0) ? rank : 1;
|
|
Packit |
0848f5 |
dinbuf[1].r = 0;
|
|
Packit |
0848f5 |
dinbuf[2].r = (rank > 0);
|
|
Packit |
0848f5 |
dinbuf[0].i = 0;
|
|
Packit |
0848f5 |
dinbuf[1].i = 1;
|
|
Packit |
0848f5 |
dinbuf[2].i = -(rank > 0);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
doutbuf[0].r = 0;
|
|
Packit |
0848f5 |
doutbuf[1].r = 1;
|
|
Packit |
0848f5 |
doutbuf[2].r = 1;
|
|
Packit |
0848f5 |
doutbuf[0].i = 0;
|
|
Packit |
0848f5 |
doutbuf[1].i = 1;
|
|
Packit |
0848f5 |
doutbuf[2].i = 1;
|
|
Packit |
0848f5 |
MPI_Reduce(dinbuf, doutbuf, 3, MPI_DOUBLE_COMPLEX, MPI_PROD, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
double imag, real;
|
|
Packit |
0848f5 |
if (doutbuf[0].r != (double) result[maxsize - 1] || doutbuf[0].i != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "double complex PROD(rank) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
/* Multiplying the imaginary part depends on size mod 4 */
|
|
Packit |
0848f5 |
imag = 1.0;
|
|
Packit |
0848f5 |
real = 0.0; /* Make compiler happy */
|
|
Packit |
0848f5 |
switch (size % 4) {
|
|
Packit |
0848f5 |
case 1:
|
|
Packit |
0848f5 |
imag = 1.0;
|
|
Packit |
0848f5 |
real = 0.0;
|
|
Packit |
0848f5 |
break;
|
|
Packit |
0848f5 |
case 2:
|
|
Packit |
0848f5 |
imag = 0.0;
|
|
Packit |
0848f5 |
real = -1.0;
|
|
Packit |
0848f5 |
break;
|
|
Packit |
0848f5 |
case 3:
|
|
Packit |
0848f5 |
imag = -1.0;
|
|
Packit |
0848f5 |
real = 0.0;
|
|
Packit |
0848f5 |
break;
|
|
Packit |
0848f5 |
case 0:
|
|
Packit |
0848f5 |
imag = 0.0;
|
|
Packit |
0848f5 |
real = 1.0;
|
|
Packit |
0848f5 |
break;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (doutbuf[1].r != real || doutbuf[1].i != imag) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "double complex PROD(i) test failed (%f,%f)!=(%f,%f)\n",
|
|
Packit |
0848f5 |
doutbuf[1].r, doutbuf[1].i, real, imag);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (doutbuf[2].r != 0 || doutbuf[2].i != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "double complex PROD(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
#ifdef HAVE_LONG_DOUBLE
|
|
Packit |
0848f5 |
else if (dc == sizeof(ld_complex)) {
|
|
Packit |
0848f5 |
/* double complex; may be null if we do not have Fortran support */
|
|
Packit |
0848f5 |
ldinbuf[0].r = (rank < maxsize && rank > 0) ? rank : 1;
|
|
Packit |
0848f5 |
ldinbuf[1].r = 0;
|
|
Packit |
0848f5 |
ldinbuf[2].r = (rank > 0);
|
|
Packit |
0848f5 |
ldinbuf[0].i = 0;
|
|
Packit |
0848f5 |
ldinbuf[1].i = 1;
|
|
Packit |
0848f5 |
ldinbuf[2].i = -(rank > 0);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
ldoutbuf[0].r = 0;
|
|
Packit |
0848f5 |
ldoutbuf[1].r = 1;
|
|
Packit |
0848f5 |
ldoutbuf[2].r = 1;
|
|
Packit |
0848f5 |
ldoutbuf[0].i = 0;
|
|
Packit |
0848f5 |
ldoutbuf[1].i = 1;
|
|
Packit |
0848f5 |
ldoutbuf[2].i = 1;
|
|
Packit |
0848f5 |
MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_DOUBLE_COMPLEX, MPI_PROD, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
long double imag, real;
|
|
Packit |
0848f5 |
if (ldoutbuf[0].r != (double) result[maxsize - 1] || ldoutbuf[0].i != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "double complex PROD(rank) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
/* Multiplying the imaginary part depends on size mod 4 */
|
|
Packit |
0848f5 |
imag = 1.0;
|
|
Packit |
0848f5 |
real = 0.0; /* Make compiler happy */
|
|
Packit |
0848f5 |
switch (size % 4) {
|
|
Packit |
0848f5 |
case 1:
|
|
Packit |
0848f5 |
imag = 1.0;
|
|
Packit |
0848f5 |
real = 0.0;
|
|
Packit |
0848f5 |
break;
|
|
Packit |
0848f5 |
case 2:
|
|
Packit |
0848f5 |
imag = 0.0;
|
|
Packit |
0848f5 |
real = -1.0;
|
|
Packit |
0848f5 |
break;
|
|
Packit |
0848f5 |
case 3:
|
|
Packit |
0848f5 |
imag = -1.0;
|
|
Packit |
0848f5 |
real = 0.0;
|
|
Packit |
0848f5 |
break;
|
|
Packit |
0848f5 |
case 0:
|
|
Packit |
0848f5 |
imag = 0.0;
|
|
Packit |
0848f5 |
real = 1.0;
|
|
Packit |
0848f5 |
break;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (ldoutbuf[1].r != real || ldoutbuf[1].i != imag) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "double complex PROD(i) test failed (%Lf,%Lf)!=(%Lf,%Lf)\n",
|
|
Packit |
0848f5 |
ldoutbuf[1].r, ldoutbuf[1].i, real, imag);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (ldoutbuf[2].r != 0 || ldoutbuf[2].i != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "double complex PROD(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
#endif /* HAVE_LONG_DOUBLE */
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
#endif /* USE_STRICT_MPI */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#ifdef HAVE_LONG_DOUBLE
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
long double ldinbuf[3], ldoutbuf[3];
|
|
Packit |
0848f5 |
MTEST_VG_MEM_INIT(ldinbuf, 3 * sizeof(ldinbuf[0]));
|
|
Packit |
0848f5 |
/* long double */
|
|
Packit |
0848f5 |
ldinbuf[0] = (rank < maxsize && rank > 0) ? rank : 1;
|
|
Packit |
0848f5 |
ldinbuf[1] = 0;
|
|
Packit |
0848f5 |
ldinbuf[2] = (rank > 0);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
ldoutbuf[0] = 0;
|
|
Packit |
0848f5 |
ldoutbuf[1] = 1;
|
|
Packit |
0848f5 |
ldoutbuf[2] = 1;
|
|
Packit |
0848f5 |
if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
|
|
Packit |
0848f5 |
MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_PROD, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (ldoutbuf[0] != (long double) result[maxsize - 1]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "long double PROD(rank) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (ldoutbuf[1]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "long double PROD(0) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (size > 1 && ldoutbuf[2] != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "long double PROD(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
#endif /* HAVE_LONG_DOUBLE */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#ifdef HAVE_LONG_LONG
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
long long llinbuf[3], lloutbuf[3];
|
|
Packit |
0848f5 |
/* long long */
|
|
Packit |
0848f5 |
llinbuf[0] = (rank < maxsize && rank > 0) ? rank : 1;
|
|
Packit |
0848f5 |
llinbuf[1] = 0;
|
|
Packit |
0848f5 |
llinbuf[2] = (rank > 0);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
lloutbuf[0] = 0;
|
|
Packit |
0848f5 |
lloutbuf[1] = 1;
|
|
Packit |
0848f5 |
lloutbuf[2] = 1;
|
|
Packit |
0848f5 |
if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
|
|
Packit |
0848f5 |
MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_PROD, 0, comm);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (lloutbuf[0] != (long long) result[maxsize - 1]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "long long PROD(rank) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (lloutbuf[1]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "long long PROD(0) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (size > 1 && lloutbuf[2]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "long long PROD(>) test failed\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
#endif /* HAVE_LONG_LONG */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Finalize(errs);
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|