|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2015 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 <stdio.h>
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* Test MPI_Dims_create and the choice of decompositions. These should match
|
|
Packit Service |
c5cf8c |
* the definition in MPI, which wants a "balanced" decomposition. There
|
|
Packit Service |
c5cf8c |
* is some ambiguity in the definition, so this test attempts to deal with
|
|
Packit Service |
c5cf8c |
* that.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#define MAX_DIMS 20
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
typedef struct {
|
|
Packit Service |
c5cf8c |
int size, dim;
|
|
Packit Service |
c5cf8c |
int orderedDecomp[MAX_DIMS];
|
|
Packit Service |
c5cf8c |
} DimsTestVal_t;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* MPI 3.1, page 293, line 31, output values of Dims_create are in
|
|
Packit Service |
c5cf8c |
non-increasing order */
|
|
Packit Service |
c5cf8c |
DimsTestVal_t tests[] = {
|
|
Packit Service |
c5cf8c |
#include "baddims.h"
|
|
Packit Service |
c5cf8c |
};
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Forward refs */
|
|
Packit Service |
c5cf8c |
void zeroDims(int, int[]);
|
|
Packit Service |
c5cf8c |
int checkDims(DimsTestVal_t *, const int[]);
|
|
Packit Service |
c5cf8c |
int compareDims(int, const int[], const int[], int);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int i, k, wrank, errs = 0;
|
|
Packit Service |
c5cf8c |
int dims[MAX_DIMS];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(0, 0);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == 0) {
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (k = 0; tests[k].size > 0; k++) {
|
|
Packit Service |
c5cf8c |
zeroDims(tests[k].dim, dims);
|
|
Packit Service |
c5cf8c |
MPI_Dims_create(tests[k].size, tests[k].dim, dims);
|
|
Packit Service |
c5cf8c |
if (checkDims(&tests[k], dims)) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(1, "Test %d failed with mismatched output", k);
|
|
Packit Service |
c5cf8c |
if (errs < 10) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "%d in %dd: ", tests[k].size, tests[k].dim);
|
|
Packit Service |
c5cf8c |
for (i = 0; i < tests[k].dim - 1; i++)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "%d x ", dims[i]);
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "%d != %d", dims[tests[k].dim - 1], tests[k].orderedDecomp[0]);
|
|
Packit Service |
c5cf8c |
for (i = 1; i < tests[k].dim; i++)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, " x %d", tests[k].orderedDecomp[i]);
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
void zeroDims(int dim, int dims[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int k;
|
|
Packit Service |
c5cf8c |
for (k = 0; k < dim; k++)
|
|
Packit Service |
c5cf8c |
dims[k] = 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int checkDims(DimsTestVal_t * test, const int dims[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int k, errs = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (k = 0; k < test->dim; k++) {
|
|
Packit Service |
c5cf8c |
if (dims[k] != test->orderedDecomp[k]) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
return errs;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int compareDims(int dim, const int d1[], const int d2[], int isweak)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int diff = 0, k;
|
|
Packit Service |
c5cf8c |
if (isweak) {
|
|
Packit Service |
c5cf8c |
diff = d1[0] - d1[dim - 1] - (d2[0] - d2[dim - 1]);
|
|
Packit Service |
c5cf8c |
if (diff < 0)
|
|
Packit Service |
c5cf8c |
diff = -diff;
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
for (k = 0; k < dim; k++) {
|
|
Packit Service |
c5cf8c |
int d = d1[k] - d2[k];
|
|
Packit Service |
c5cf8c |
if (d < 0)
|
|
Packit Service |
c5cf8c |
d = -d;
|
|
Packit Service |
c5cf8c |
diff += d;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
return diff;
|
|
Packit Service |
c5cf8c |
}
|