|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* (C) 2003 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include "mpitestconf.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
static char MTEST_Descrip[] = "Test MPI_SUM operations on optional datatypes dupported by MPICH";
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
typedef struct {
|
|
Packit Service |
c5cf8c |
double r, i;
|
|
Packit Service |
c5cf8c |
} d_complex;
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_LONG_DOUBLE
|
|
Packit Service |
c5cf8c |
typedef struct {
|
|
Packit Service |
c5cf8c |
long double r, i;
|
|
Packit Service |
c5cf8c |
} ld_complex;
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* This test looks at the handling of logical and for types that are not
|
|
Packit Service |
c5cf8c |
* integers or are not required integers (e.g., long long). MPICH allows
|
|
Packit Service |
c5cf8c |
* these as well. A strict MPI test should not include this test.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int errs = 0;
|
|
Packit Service |
c5cf8c |
int rank, size;
|
|
Packit Service |
c5cf8c |
MPI_Comm comm;
|
|
Packit Service |
c5cf8c |
char cinbuf[3], coutbuf[3];
|
|
Packit Service |
c5cf8c |
signed char scinbuf[3], scoutbuf[3];
|
|
Packit Service |
c5cf8c |
unsigned char ucinbuf[3], ucoutbuf[3];
|
|
Packit Service |
c5cf8c |
d_complex dinbuf[3], doutbuf[3];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
comm = MPI_COMM_WORLD;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(comm, &rank;;
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(comm, &size);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifndef USE_STRICT_MPI
|
|
Packit Service |
c5cf8c |
/* char */
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
|
|
Packit Service |
c5cf8c |
cinbuf[0] = 1;
|
|
Packit Service |
c5cf8c |
cinbuf[1] = 0;
|
|
Packit Service |
c5cf8c |
cinbuf[2] = (rank > 0);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
coutbuf[0] = 0;
|
|
Packit Service |
c5cf8c |
coutbuf[1] = 1;
|
|
Packit Service |
c5cf8c |
coutbuf[2] = 1;
|
|
Packit Service |
c5cf8c |
MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_SUM, 0, comm);
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
if (size < 128 && coutbuf[0] != size) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "char SUM(1) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (size < 128 && coutbuf[1] != 0) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "char SUM(0) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (size < 128 && coutbuf[2] != size - 1) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "char SUM(>) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif /* USE_MPI_STRICT */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* signed char */
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
|
|
Packit Service |
c5cf8c |
scinbuf[0] = 1;
|
|
Packit Service |
c5cf8c |
scinbuf[1] = 0;
|
|
Packit Service |
c5cf8c |
scinbuf[2] = (rank > 0);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
scoutbuf[0] = 0;
|
|
Packit Service |
c5cf8c |
scoutbuf[1] = 1;
|
|
Packit Service |
c5cf8c |
scoutbuf[2] = 1;
|
|
Packit Service |
c5cf8c |
MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_SUM, 0, comm);
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
if (size < 128 && scoutbuf[0] != size) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "signed char SUM(1) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (size < 128 && scoutbuf[1] != 0) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "signed char SUM(0) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (size < 128 && scoutbuf[2] != size - 1) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "signed char SUM(>) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* unsigned char */
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
|
|
Packit Service |
c5cf8c |
ucinbuf[0] = 1;
|
|
Packit Service |
c5cf8c |
ucinbuf[1] = 0;
|
|
Packit Service |
c5cf8c |
ucinbuf[2] = (rank > 0);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
ucoutbuf[0] = 0;
|
|
Packit Service |
c5cf8c |
ucoutbuf[1] = 1;
|
|
Packit Service |
c5cf8c |
ucoutbuf[2] = 1;
|
|
Packit Service |
c5cf8c |
MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_SUM, 0, comm);
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
if (size < 128 && ucoutbuf[0] != size) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "unsigned char SUM(1) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (size < 128 && ucoutbuf[1]) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "unsigned char SUM(0) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (size < 128 && ucoutbuf[2] != size - 1) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "unsigned char SUM(>) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#ifndef USE_STRICT_MPI
|
|
Packit Service |
c5cf8c |
/* For some reason, complex is not allowed for sum and prod */
|
|
Packit Service |
c5cf8c |
if (MPI_DOUBLE_COMPLEX != MPI_DATATYPE_NULL) {
|
|
Packit Service |
c5cf8c |
int dc;
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_LONG_DOUBLE
|
|
Packit Service |
c5cf8c |
ld_complex ldinbuf[3], ldoutbuf[3];
|
|
Packit Service |
c5cf8c |
MTEST_VG_MEM_INIT(ldinbuf, 3 * sizeof(ldinbuf[0]));
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
/* Must determine which C type matches this Fortran type */
|
|
Packit Service |
c5cf8c |
MPI_Type_size(MPI_DOUBLE_COMPLEX, &dc);
|
|
Packit Service |
c5cf8c |
if (dc == sizeof(d_complex)) {
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(10, "Reduce of MPI_DOUBLE_COMPLEX\n");
|
|
Packit Service |
c5cf8c |
/* double complex; may be null if we do not have Fortran support */
|
|
Packit Service |
c5cf8c |
dinbuf[0].r = 1;
|
|
Packit Service |
c5cf8c |
dinbuf[1].r = 0;
|
|
Packit Service |
c5cf8c |
dinbuf[2].r = (rank > 0);
|
|
Packit Service |
c5cf8c |
dinbuf[0].i = -1;
|
|
Packit Service |
c5cf8c |
dinbuf[1].i = 0;
|
|
Packit Service |
c5cf8c |
dinbuf[2].i = -(rank > 0);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
doutbuf[0].r = 0;
|
|
Packit Service |
c5cf8c |
doutbuf[1].r = 1;
|
|
Packit Service |
c5cf8c |
doutbuf[2].r = 1;
|
|
Packit Service |
c5cf8c |
doutbuf[0].i = 0;
|
|
Packit Service |
c5cf8c |
doutbuf[1].i = 1;
|
|
Packit Service |
c5cf8c |
doutbuf[2].i = 1;
|
|
Packit Service |
c5cf8c |
MPI_Reduce(dinbuf, doutbuf, 3, MPI_DOUBLE_COMPLEX, MPI_SUM, 0, comm);
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
if (doutbuf[0].r != size || doutbuf[0].i != -size) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "double complex SUM(1) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (doutbuf[1].r != 0 || doutbuf[1].i != 0) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "double complex SUM(0) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (doutbuf[2].r != size - 1 || doutbuf[2].i != 1 - size) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "double complex SUM(>) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_LONG_DOUBLE
|
|
Packit Service |
c5cf8c |
else if (dc == sizeof(ld_complex)) {
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(10, "Reduce of MPI_DOUBLE_COMPLEX\n");
|
|
Packit Service |
c5cf8c |
/* double complex; may be null if we do not have Fortran support */
|
|
Packit Service |
c5cf8c |
ldinbuf[0].r = 1;
|
|
Packit Service |
c5cf8c |
ldinbuf[1].r = 0;
|
|
Packit Service |
c5cf8c |
ldinbuf[2].r = (rank > 0);
|
|
Packit Service |
c5cf8c |
ldinbuf[0].i = -1;
|
|
Packit Service |
c5cf8c |
ldinbuf[1].i = 0;
|
|
Packit Service |
c5cf8c |
ldinbuf[2].i = -(rank > 0);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
ldoutbuf[0].r = 0;
|
|
Packit Service |
c5cf8c |
ldoutbuf[1].r = 1;
|
|
Packit Service |
c5cf8c |
ldoutbuf[2].r = 1;
|
|
Packit Service |
c5cf8c |
ldoutbuf[0].i = 0;
|
|
Packit Service |
c5cf8c |
ldoutbuf[1].i = 1;
|
|
Packit Service |
c5cf8c |
ldoutbuf[2].i = 1;
|
|
Packit Service |
c5cf8c |
MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_DOUBLE_COMPLEX, MPI_SUM, 0, comm);
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
if (ldoutbuf[0].r != size || ldoutbuf[0].i != -size) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "double complex SUM(1) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (ldoutbuf[1].r != 0 || ldoutbuf[1].i != 0) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "double complex SUM(0) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (ldoutbuf[2].r != size - 1 || ldoutbuf[2].i != 1 - size) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "double complex SUM(>) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
/* Implicitly ignore if there is no matching C type */
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif /* USE_STRICT_MPI */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_LONG_DOUBLE
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
long double ldinbuf[3], ldoutbuf[3];
|
|
Packit Service |
c5cf8c |
MTEST_VG_MEM_INIT(ldinbuf, 3 * sizeof(ldinbuf[0]));
|
|
Packit Service |
c5cf8c |
/* long double */
|
|
Packit Service |
c5cf8c |
ldinbuf[0] = 1;
|
|
Packit Service |
c5cf8c |
ldinbuf[1] = 0;
|
|
Packit Service |
c5cf8c |
ldinbuf[2] = (rank > 0);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
ldoutbuf[0] = 0;
|
|
Packit Service |
c5cf8c |
ldoutbuf[1] = 1;
|
|
Packit Service |
c5cf8c |
ldoutbuf[2] = 1;
|
|
Packit Service |
c5cf8c |
if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(10, "Reduce of MPI_LONG_DOUBLE\n");
|
|
Packit Service |
c5cf8c |
MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_SUM, 0, comm);
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
if (ldoutbuf[0] != size) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "long double SUM(1) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (ldoutbuf[1] != 0.0) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "long double SUM(0) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (ldoutbuf[2] != size - 1) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "long double SUM(>) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_LONG_LONG
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
long long llinbuf[3], lloutbuf[3];
|
|
Packit Service |
c5cf8c |
/* long long */
|
|
Packit Service |
c5cf8c |
llinbuf[0] = 1;
|
|
Packit Service |
c5cf8c |
llinbuf[1] = 0;
|
|
Packit Service |
c5cf8c |
llinbuf[2] = (rank > 0);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
lloutbuf[0] = 0;
|
|
Packit Service |
c5cf8c |
lloutbuf[1] = 1;
|
|
Packit Service |
c5cf8c |
lloutbuf[2] = 1;
|
|
Packit Service |
c5cf8c |
if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(10, "Reduce of MPI_LONG_LONG\n");
|
|
Packit Service |
c5cf8c |
MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_SUM, 0, comm);
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
if (lloutbuf[0] != size) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "long long SUM(1) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (lloutbuf[1] != 0) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "long long SUM(0) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (lloutbuf[2] != size - 1) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "long long SUM(>) test failed\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|