Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[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, "Sizes is wrong in cart communicator.  Is %d, should be 1\n", csize);
42         }
43
44         /* This function is not meaningful, but should not fail */
45         MPI_Dims_create(1, 0, NULL);
46
47         ndims = -1;
48         MPI_Cartdim_get(comm, &ndims);
49         if (ndims != 0) {
50             errs++;
51             fprintf(stderr, "MPI_Cartdim_get: ndims is %d, should be 0\n", ndims);
52         }
53
54         /* this function should not fail */
55         MPI_Cart_get(comm, 0, NULL, NULL, NULL);
56
57         MPI_Cart_rank(comm, NULL, &rank);
58         if (rank != 0) {
59             errs++;
60             fprintf(stderr, "MPI_Cart_rank: rank is %d, should be 0\n", rank);
61         }
62
63         /* this function should not fail */
64         MPI_Cart_coords(comm, 0, 0, NULL);
65
66         MPI_Cart_sub(comm, NULL, &newcomm);
67         ndims = -1;
68         MPI_Cartdim_get(newcomm, &ndims);
69         if (ndims != 0) {
70             errs++;
71             fprintf(stderr, "MPI_Cart_sub did not return zero-dimensional communicator\n");
72         }
73
74         MPI_Barrier(comm);
75
76         MPI_Comm_free(&comm);
77         MPI_Comm_free(&newcomm);
78     }
79     else if (rank == 0) {
80         errs++;
81         fprintf(stderr, "Communicator returned is null!");
82     }
83
84     MTest_Finalize(errs);
85
86     MPI_Finalize();
87
88     return 0;
89 }