Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove unwanted files
[simgrid.git] / teshsuite / smpi / mpich-test / topol / dims.c
1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2
3 #include "mpi.h"
4 #include <stdio.h>
5
6 int main( int argc, char *argv[] )
7 {
8     int dims[10];
9     int i, j, ndims, totnodes, err, errcnt = 0;
10
11     MPI_Init( &argc, &argv );
12
13     MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
14
15     /* Try for error checks */
16     dims[0] = 2;
17     dims[1] = 2;
18     dims[2] = 0;
19     err = MPI_Dims_create( 26, 3, dims );
20     if (err == MPI_SUCCESS) {
21         printf( "The product of the specified dims does not divide the nnodes and MPI_Dims_create did not return an error\n" );
22         for (i=0; i<3; i++) {
23             printf( "dims[%d] = %d\n", i, dims[i] );
24         }
25         errcnt++;
26     }
27
28     /* Check for a few reasonable decompositions */
29     dims[0] = dims[1] = 0;
30     err = MPI_Dims_create( 16, 2, dims );
31     if (err) {
32         char msg[MPI_MAX_ERROR_STRING];
33         int result_len;
34         MPI_Error_string( err, msg, &result_len );
35         printf( "Unexpected error return from dims_create (16,2) %s\n", msg );
36         errcnt++;
37     }
38     else {
39         if (dims[0] * dims[1] != 16) {
40             printf( "Returned dimensions do not match request\n" );
41             errcnt++;
42         }
43 #ifdef MPICH_NAME
44         if (dims[0] != 4) {
45             errcnt++;
46             printf( "Expected 4 x 4, got %d x %d\n", dims[0],dims[1] );
47         }
48 #endif
49     }
50
51     dims[0] = dims[1] = 0;
52     /* 60 = 2 * 2 * 3 * 5 */
53     err = MPI_Dims_create( 60, 2, dims );
54     if (err) {
55         char msg[MPI_MAX_ERROR_STRING];
56         int result_len;
57         MPI_Error_string( err, msg, &result_len );
58         printf( "Unexpected error return from dims_create (16,2) %s\n", msg );
59         errcnt++;
60     }
61     else {
62         if (dims[0] * dims[1] != 60) {
63             printf( "Returned dimensions do not match request (%d)\n",
64                     dims[0] * dims[1] );
65             errcnt++;
66         }
67 #ifdef MPICH_NAME
68         if (dims[0] == 1 || dims[1] == 1) {
69             errcnt++;
70             printf( "Expected rectangular decomp, got %d x %d\n", 
71                     dims[0],dims[1] );
72         }
73 #endif
74     }
75
76     /* Test a range of values */
77     for (ndims=1; ndims<=4; ndims++) {
78         for (i=2; i<64; i++) {
79             for (j=0; j<ndims; j++) {
80                 dims[j] = 0;
81             }
82             MPI_Dims_create( i, ndims, dims );
83             /* Check the results */
84             totnodes = 1;
85             for (j=0; j<ndims; j++) {
86                 totnodes *= dims[j];
87                 if (dims[j] <= 0) {
88                     errcnt++;
89                     printf( "Non positive dims[%d] = %d for %d nodes and %d ndims\n", 
90                             j, dims[j], i, ndims );
91                 }
92             }
93             if (totnodes != i) {
94                 errcnt++;
95                 printf( "Did not correctly partition %d nodes among %d dims (got %d nodes)\n",
96                         i, ndims, totnodes );
97                 if (ndims > 1) {
98                     printf( "Dims = " );
99                     for (j=0; j<ndims; j++) {
100                         printf( " %d", dims[j] );
101                     }
102                     printf( "\n" );
103                 }
104             }
105                 
106         }
107     }
108     /* Summarize the results */
109     if (errcnt) {
110         printf( " %d errors found\n", errcnt );
111     }
112     else {
113         printf( " No Errors\n" );
114     }
115     MPI_Finalize( );
116     return 0;
117 }