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
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
#include "mpi.h"
#include "mpitestconf.h"
#include <stdio.h>
#include "mpitest.h"
/*
static char MTEST_Descrip[] = "Test MPI_MIN operations on optional 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.
*/
int main(int argc, char *argv[])
{
int errs = 0;
int rank, size;
MPI_Comm comm;
char cinbuf[3], coutbuf[3];
signed char scinbuf[3], scoutbuf[3];
unsigned char ucinbuf[3], ucoutbuf[3];
MTest_Init(&argc, &argv);
comm = MPI_COMM_WORLD;
MPI_Comm_rank(comm, &rank);
MPI_Comm_size(comm, &size);
#ifndef USE_STRICT_MPI
/* char */
MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
cinbuf[0] = 1;
cinbuf[1] = 0;
cinbuf[2] = (rank & 0x7f);
coutbuf[0] = 0;
coutbuf[1] = 1;
coutbuf[2] = 1;
MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_MIN, 0, comm);
if (rank == 0) {
if (coutbuf[0] != 1) {
errs++;
fprintf(stderr, "char MIN(1) test failed\n");
}
if (coutbuf[1] != 0) {
errs++;
fprintf(stderr, "char MIN(0) test failed\n");
}
if (coutbuf[2] != 0) {
errs++;
fprintf(stderr, "char MIN(>) test failed\n");
}
}
#endif /* USE_STRICT_MPI */
/* signed char */
MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
scinbuf[0] = 1;
scinbuf[1] = 0;
scinbuf[2] = (rank & 0x7f);
scoutbuf[0] = 0;
scoutbuf[1] = 1;
scoutbuf[2] = 1;
MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_MIN, 0, comm);
if (rank == 0) {
if (scoutbuf[0] != 1) {
errs++;
fprintf(stderr, "signed char MIN(1) test failed\n");
}
if (scoutbuf[1] != 0) {
errs++;
fprintf(stderr, "signed char MIN(0) test failed\n");
}
if (scoutbuf[2] != 0) {
errs++;
fprintf(stderr, "signed char MIN(>) test failed\n");
}
}
/* unsigned char */
MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
ucinbuf[0] = 1;
ucinbuf[1] = 0;
ucinbuf[2] = (rank & 0x7f);
ucoutbuf[0] = 0;
ucoutbuf[1] = 1;
ucoutbuf[2] = 1;
MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_MIN, 0, comm);
if (rank == 0) {
if (ucoutbuf[0] != 1) {
errs++;
fprintf(stderr, "unsigned char MIN(1) test failed\n");
}
if (ucoutbuf[1]) {
errs++;
fprintf(stderr, "unsigned char MIN(0) test failed\n");
}
if (ucoutbuf[2] != 0) {
errs++;
fprintf(stderr, "unsigned char MIN(>) test failed\n");
}
}
#ifdef HAVE_LONG_DOUBLE
{
long double ldinbuf[3], ldoutbuf[3];
/* long double */
MTEST_VG_MEM_INIT(ldinbuf, 3 * sizeof(ldinbuf[0]));
ldinbuf[0] = 1;
ldinbuf[1] = 0;
ldinbuf[2] = rank;
ldoutbuf[0] = 0;
ldoutbuf[1] = 1;
ldoutbuf[2] = 1;
if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
MTestPrintfMsg(10, "Reduce of MPI_LONG_DOUBLE\n");
MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_MIN, 0, comm);
if (rank == 0) {
if (ldoutbuf[0] != 1) {
errs++;
fprintf(stderr, "long double MIN(1) test failed\n");
}
if (ldoutbuf[1] != 0.0) {
errs++;
fprintf(stderr, "long double MIN(0) test failed\n");
}
if (ldoutbuf[2] != 0.0) {
errs++;
fprintf(stderr, "long double MIN(>) test failed\n");
}
}
}
}
#endif /* HAVE_LONG_DOUBLE */
#ifdef HAVE_LONG_LONG
{
long long llinbuf[3], lloutbuf[3];
/* long long */
llinbuf[0] = 1;
llinbuf[1] = 0;
llinbuf[2] = rank;
lloutbuf[0] = 0;
lloutbuf[1] = 1;
lloutbuf[2] = 1;
if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
MTestPrintfMsg(10, "Reduce of MPI_LONG_LONG\n");
MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_MIN, 0, comm);
if (rank == 0) {
if (lloutbuf[0] != 1) {
errs++;
fprintf(stderr, "long long MIN(1) test failed\n");
}
if (lloutbuf[1] != 0) {
errs++;
fprintf(stderr, "long long MIN(0) test failed\n");
}
if (lloutbuf[2] != 0) {
errs++;
fprintf(stderr, "long long MIN(>) test failed\n");
}
}
}
}
#endif /* HAVE_LONG_LONG */
MTest_Finalize(errs);
return MTestReturnValue(errs);
}
|