1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2015 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
11 * Test MPI_Dims_create and the choice of decompositions. These should match
12 * the definition in MPI, which wants a "balanced" decomposition. There
13 * is some ambiguity in the definition, so this test attempts to deal with
20 int orderedDecomp[MAX_DIMS];
23 /* MPI 3.1, page 293, line 31, output values of Dims_create are in
24 non-increasing order */
25 DimsTestVal_t tests[] = {
30 void zeroDims(int, int []);
31 int checkDims(DimsTestVal_t *, const int []);
32 int compareDims(int, const int[], const int[], int);
34 int main(int argc, char *argv[])
36 int i, k, wrank, errs = 0;
40 MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
44 for (k=0; tests[k].size > 0; k++) {
45 zeroDims(tests[k].dim, dims);
46 MPI_Dims_create(tests[k].size, tests[k].dim, dims);
47 if (checkDims(&tests[k], dims)) {
49 MTestPrintfMsg(1, "Test %d failed with mismatched output", k);
51 fprintf(stderr, "%d in %dd: ", tests[k].size, tests[k].dim);
52 for (i=0; i<tests[k].dim-1; i++)
53 fprintf(stderr, "%d x ", dims[i]);
54 fprintf(stderr, "%d != %d", dims[tests[k].dim-1],
55 tests[k].orderedDecomp[0]);
56 for (i=1; i<tests[k].dim; i++)
57 fprintf(stderr," x %d", tests[k].orderedDecomp[i]);
66 return MTestReturnValue(errs);
69 void zeroDims(int dim, int dims[])
72 for (k=0; k<dim; k++) dims[k] = 0;
75 int checkDims(DimsTestVal_t *test, const int dims[])
79 for (k=0; k<test->dim; k++) {
80 if (dims[k] != test->orderedDecomp[k]) {
87 int compareDims(int dim, const int d1[], const int d2[], int isweak)
91 diff = d1[0] - d1[dim-1] - (d2[0] - d2[dim-1]);
92 if (diff < 0) diff = - diff;
95 for (k=0; k<dim; k++) {
96 int d = d1[k] - d2[k];