Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / topo / cartcreates.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 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 int main(int argc, char *argv[])
12 {
13     int errs = 0;
14     int size, rank;
15     int dims[2], periods[2];
16     MPI_Comm comm;
17
18     MTest_Init(&argc, &argv);
19
20     /* Create a new cartesian communicator in a subset of the processes */
21     MPI_Comm_size(MPI_COMM_WORLD, &size);
22     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23     if (size < 2) {
24         fprintf(stderr, "This test needs at least 2 processes\n");
25         MPI_Abort(MPI_COMM_WORLD, 1);
26     }
27     dims[0] = size - 1;
28     periods[0] = 1;
29     MPI_Cart_create(MPI_COMM_WORLD, 1, dims, periods, 0, &comm);
30
31     if (comm != MPI_COMM_NULL) {
32         int csize;
33         MPI_Comm_size(comm, &csize);
34         if (csize != dims[0]) {
35             errs++;
36             fprintf(stderr,
37                     "Sizes is wrong in cart communicator.  Is %d, should be %d\n", csize, dims[0]);
38         }
39         MPI_Barrier(comm);
40
41         MPI_Comm_free(&comm);
42     }
43     else if (rank < dims[0]) {
44         errs++;
45         fprintf(stderr, "Communicator returned is null!");
46     }
47
48     MTest_Finalize(errs);
49
50     MPI_Finalize();
51
52     return 0;
53 }