Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc++'
[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], 
39                     nnodes );
40         }
41         
42         /* Try calling Dims_create with nothing to do (all dimensions
43            specified) */
44         dims[0] = 1;
45         dims[1] = nnodes;
46         MPI_Dims_create( nnodes, 2, dims );
47         if (prodof(2, dims) != nnodes) {
48             errs++;
49             printf( "Dims_create returned the wrong decomposition (all given).  " );
50             printf( "Is [%d x %d], should be 1 x %d\n", dims[0], dims[1], 
51                     nnodes );
52         }
53
54     }
55
56     /* 4 dimensional tests */
57     for (nnodes=4; nnodes <= 32; nnodes = nnodes * 2) {
58         dims[0] = 0;
59         dims[1] = nnodes/2;
60         dims[2] = 0;
61         dims[3] = 2;
62         
63         MPI_Dims_create( nnodes, 4, dims );
64         if (prodof(4, dims) != nnodes) {
65             errs++;
66             printf( "Dims_create returned the wrong decomposition.  " );
67             printf( "Is [%d x %d x %d x %d], should be 1 x %d x 1 x 2\n", 
68                     dims[0], dims[1], dims[2], dims[3],
69                     nnodes/2 );
70         }
71         
72         /* Try calling Dims_create with nothing to do (all dimensions
73            specified) */
74         dims[0] = 1;
75         dims[1] = nnodes/2;
76         dims[2] = 1;
77         dims[3] = 2;
78         MPI_Dims_create( nnodes, 4, dims );
79         if (prodof(4, dims) != nnodes) {
80             errs++;
81             printf( "Dims_create returned the wrong decomposition (all given).  " );
82             printf( "Is [%d x %d x %d x %d], should be 1 x %d x 1 x 2\n", 
83                     dims[0], dims[1], dims[2], dims[3],
84                     nnodes/2 );
85         }
86
87     }
88
89     MTest_Finalize( errs );
90     MPI_Finalize();
91     return 0;
92   
93 }