Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Try to avoid rare bug on one ci node.
[simgrid.git] / teshsuite / smpi / mpich3-test / topo / graphcr2.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 <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Create a communicator with a graph that contains null edges and one that contains duplicate edges";
14 */
15
16 int main(int argc, char *argv[])
17 {
18     int errs = 0;
19     int *index = 0, *edges = 0;
20     int rank, size, i, j, crank, csize;
21     MPI_Comm comm;
22
23     MTest_Init(&argc, &argv);
24
25     MPI_Comm_size(MPI_COMM_WORLD, &size);
26     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
27
28     index = (int *) malloc(size * sizeof(int));
29     edges = (int *) malloc(size * sizeof(int));
30     for (i = 0; i < size; i++) {
31         index[i] = 1;
32         edges[i] = i;
33     }
34     /* As of MPI 2.1, self edges are permitted */
35     MPI_Graph_create(MPI_COMM_WORLD, size, index, edges, 0, &comm);
36     MPI_Comm_rank(comm, &crank);
37     MPI_Comm_size(comm, &csize);
38     if (csize != size) {
39         errs++;
40         fprintf(stderr, "Graph create with self links has size %d should be %d", csize, size);
41     }
42     free(index);
43     free(edges);
44     MPI_Comm_free(&comm);
45
46     /* Create a graph with duplicate links */
47     index = (int *) malloc(size * sizeof(int));
48     edges = (int *) malloc(size * 2 * sizeof(int));
49     j = 0;
50     for (i = 0; i < size; i++) {
51         index[i] = j + 2;
52         edges[j++] = (i + 1) % size;
53         edges[j++] = (i + 1) % size;
54     }
55     /* As of MPI 2.1, duplicate edges are permitted */
56     MPI_Graph_create(MPI_COMM_WORLD, size, index, edges, 0, &comm);
57     MPI_Comm_rank(comm, &crank);
58     MPI_Comm_size(comm, &csize);
59     if (csize != size) {
60         errs++;
61         fprintf(stderr, "Graph create with duplicate links has size %d should be %d", csize, size);
62     }
63     free(index);
64     free(edges);
65     MPI_Comm_free(&comm);
66
67     MTest_Finalize(errs);
68     MPI_Finalize();
69     return 0;
70 }