Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / topo / dims2.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2003 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 int prodof(int, const int[]);
11 /*
12  * Test edge cases of Dims_create
13  */
14 int prodof(int ndims, const int dims[])
15 {
16     int i, prod = 1;
17     for (i = 0; i < ndims; i++)
18         prod *= dims[i];
19     return prod;
20 }
21
22 int main(int argc, char *argv[])
23 {
24     int errs = 0;
25     int dims[4], nnodes;
26
27     MTest_Init(&argc, &argv);
28
29     /* 2 dimensional tests */
30     for (nnodes = 1; nnodes <= 32; nnodes = nnodes * 2) {
31         dims[0] = 0;
32         dims[1] = nnodes;
33
34         MPI_Dims_create(nnodes, 2, dims);
35         if (prodof(2, dims) != nnodes) {
36             errs++;
37             printf("Dims_create returned the wrong decomposition.  ");
38             printf("Is [%d x %d], should be 1 x %d\n", dims[0], dims[1], nnodes);
39         }
40
41         /* Try calling Dims_create with nothing to do (all dimensions
42          * specified) */
43         dims[0] = 1;
44         dims[1] = nnodes;
45         MPI_Dims_create(nnodes, 2, dims);
46         if (prodof(2, dims) != nnodes) {
47             errs++;
48             printf("Dims_create returned the wrong decomposition (all given).  ");
49             printf("Is [%d x %d], should be 1 x %d\n", dims[0], dims[1], nnodes);
50         }
51
52     }
53
54     /* 4 dimensional tests */
55     for (nnodes = 4; nnodes <= 32; nnodes = nnodes * 2) {
56         dims[0] = 0;
57         dims[1] = nnodes / 2;
58         dims[2] = 0;
59         dims[3] = 2;
60
61         MPI_Dims_create(nnodes, 4, dims);
62         if (prodof(4, dims) != nnodes) {
63             errs++;
64             printf("Dims_create returned the wrong decomposition.  ");
65             printf("Is [%d x %d x %d x %d], should be 1 x %d x 1 x 2\n",
66                    dims[0], dims[1], dims[2], dims[3], nnodes / 2);
67         }
68
69         /* Try calling Dims_create with nothing to do (all dimensions
70          * specified) */
71         dims[0] = 1;
72         dims[1] = nnodes / 2;
73         dims[2] = 1;
74         dims[3] = 2;
75         MPI_Dims_create(nnodes, 4, dims);
76         if (prodof(4, dims) != nnodes) {
77             errs++;
78             printf("Dims_create returned the wrong decomposition (all given).  ");
79             printf("Is [%d x %d x %d x %d], should be 1 x %d x 1 x 2\n",
80                    dims[0], dims[1], dims[2], dims[3], nnodes / 2);
81         }
82
83     }
84
85     MTest_Finalize(errs);
86     MPI_Finalize();
87     return 0;
88
89 }