Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c8e601ee3e8f6221ae298cd607ae402b74c8afb7
[simgrid.git] / teshsuite / smpi / mpich3-test / topo / cartzero.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2008 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 /*  
12     Check that the MPI implementation properly handles zero-dimensional
13     Cartesian communicators - the original standard implies that these
14     should be consistent with higher dimensional topologies and thus 
15     these should work with any MPI implementation.  MPI 2.1 made this
16     requirement explicit.
17 */
18 int main( int argc, char *argv[] )
19 {
20     int errs = 0;
21     int size, rank, ndims;
22     MPI_Comm comm, newcomm;
23
24     MTest_Init( &argc, &argv );
25
26     /* Create a new cartesian communicator in a subset of the processes */
27     MPI_Comm_size( MPI_COMM_WORLD, &size );
28     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
29     if (size < 2) {
30         fprintf( stderr, "This test needs at least 2 processes\n" );
31         MPI_Abort( MPI_COMM_WORLD, 1 );
32     }
33
34     MPI_Cart_create( MPI_COMM_WORLD, 0, NULL, NULL, 0, &comm );
35
36     if (comm != MPI_COMM_NULL) {
37         int csize;
38         MPI_Comm_size( comm, &csize );
39         if (csize != 1) {
40             errs++;
41             fprintf( stderr, 
42              "Sizes is wrong in cart communicator.  Is %d, should be 1\n", 
43              csize ); 
44         }
45
46         /* This function is not meaningful, but should not fail */
47         MPI_Dims_create(1, 0, NULL);
48
49         ndims = -1;
50         MPI_Cartdim_get(comm, &ndims);
51         if (ndims != 0) {
52             errs++;
53             fprintf(stderr, "MPI_Cartdim_get: ndims is %d, should be 0\n", ndims);
54         }
55
56         /* this function should not fail */
57         MPI_Cart_get(comm, 0, NULL, NULL, NULL);
58
59         MPI_Cart_rank(comm, NULL, &rank);
60         if (rank != 0) {
61             errs++;
62             fprintf(stderr, "MPI_Cart_rank: rank is %d, should be 0\n", rank);
63         }
64
65         /* this function should not fail */
66         MPI_Cart_coords(comm, 0, 0, NULL);
67
68         MPI_Cart_sub(comm, NULL, &newcomm);
69         ndims = -1;
70         MPI_Cartdim_get(newcomm, &ndims);
71         if (ndims != 0) {
72             errs++;
73             fprintf(stderr, 
74                "MPI_Cart_sub did not return zero-dimensional communicator\n");
75         }
76
77         MPI_Barrier( comm );
78
79         MPI_Comm_free( &comm );
80         MPI_Comm_free( &newcomm );
81     } 
82     else if (rank == 0) {
83         errs++;
84         fprintf( stderr, "Communicator returned is null!" );
85     }
86
87     MTest_Finalize( errs );
88
89     MPI_Finalize();
90
91     return 0;
92 }