Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[simgrid.git] / teshsuite / smpi / mpich3-test / topo / dims5.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2015 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include "mpitest.h"
9
10 /*
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
14  * that.
15  */
16 #define MAX_DIMS 20
17
18 typedef struct {
19     int size, dim;
20     int orderedDecomp[MAX_DIMS];
21 } DimsTestVal_t;
22
23 /* MPI 3.1, page 293, line 31, output values of Dims_create are in
24    non-increasing order */
25 DimsTestVal_t tests[] = {
26 #include "baddims.h"
27     };
28
29 /* Forward refs */
30 void zeroDims(int, int []);
31 int checkDims(DimsTestVal_t *, const int []);
32 int compareDims(int, const int[], const int[], int);
33
34 int main(int argc, char *argv[])
35 {
36     int i, k, wrank, errs = 0;
37     int dims[MAX_DIMS];
38
39     MTest_Init(0, 0);
40     MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
41
42     if (wrank == 0) {
43
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)) {
48                 errs++;
49                 MTestPrintfMsg(1, "Test %d failed with mismatched output", k);
50                 if (errs < 10) {
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]);
58                     fprintf(stderr,"\n");
59                 }
60             }
61         }
62     }
63
64     MTest_Finalize(errs);
65     MPI_Finalize();
66     return MTestReturnValue(errs);
67 }
68
69 void zeroDims(int dim, int dims[])
70 {
71     int k;
72     for (k=0; k<dim; k++) dims[k] = 0;
73 }
74
75 int checkDims(DimsTestVal_t *test, const int dims[])
76 {
77     int k, errs=0;
78
79     for (k=0; k<test->dim; k++) {
80         if (dims[k] != test->orderedDecomp[k]) {
81             errs ++;
82         }
83     }
84     return errs;
85 }
86
87 int compareDims(int dim, const int d1[], const int d2[], int isweak)
88 {
89     int diff = 0, k;
90     if (isweak) {
91         diff = d1[0] - d1[dim-1] - (d2[0] - d2[dim-1]);
92         if (diff < 0) diff = - diff;
93     }
94     else {
95         for (k=0; k<dim; k++) {
96             int d = d1[k] - d2[k];
97             if (d < 0) d = -d;
98             diff += d;
99         }
100     }
101     return diff;
102 }
103
104