1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
12 int main(int argc, char *argv[])
15 int dims[2], periods[2], wsize;
16 int outdims[2], outperiods[2], outcoords[2];
18 int *index, *edges, *outindex, *outedges;
19 MPI_Comm comm1, comm2;
21 MTest_Init(&argc, &argv);
23 MPI_Comm_size(MPI_COMM_WORLD, &wsize);
25 /* Create a cartesian topology, get its characteristics, then
26 * dup it and check that the new communicator has the same properties */
27 dims[0] = dims[1] = 0;
28 MPI_Dims_create(wsize, 2, dims);
29 periods[0] = periods[1] = 0;
30 MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, 0, &comm1);
32 MPI_Comm_dup(comm1, &comm2);
33 MPI_Topo_test(comm2, &topo_type);
34 if (topo_type != MPI_CART) {
36 printf("Topo type of duped cart was not cart\n");
39 MPI_Cart_get(comm2, 2, outdims, outperiods, outcoords);
40 for (i = 0; i < 2; i++) {
41 if (outdims[i] != dims[i]) {
43 printf("%d = outdims[%d] != dims[%d] = %d\n", outdims[i], i, i, dims[i]);
45 if (outperiods[i] != periods[i]) {
47 printf("%d = outperiods[%d] != periods[%d] = %d\n",
48 outperiods[i], i, i, periods[i]);
52 MPI_Comm_free(&comm2);
53 MPI_Comm_free(&comm1);
55 /* Now do the same with a graph topology */
57 index = (int *) malloc(wsize * sizeof(int));
58 edges = (int *) malloc(wsize * 2 * sizeof(int));
59 if (!index || !edges) {
60 printf("Unable to allocate %d words for index or edges\n", 3 * wsize);
61 MPI_Abort(MPI_COMM_WORLD, 1);
64 for (i = 1; i < wsize; i++) {
65 index[i] = 2 + index[i - 1];
68 for (i = 0; i < wsize; i++) {
69 edges[k++] = (i - 1 + wsize) % wsize;
70 edges[k++] = (i + 1) % wsize;
72 MPI_Graph_create(MPI_COMM_WORLD, wsize, index, edges, 0, &comm1);
73 MPI_Comm_dup(comm1, &comm2);
74 MPI_Topo_test(comm2, &topo_type);
75 if (topo_type != MPI_GRAPH) {
77 printf("Topo type of duped graph was not graph\n");
81 MPI_Graphdims_get(comm2, &nnodes, &nedges);
82 if (nnodes != wsize) {
84 printf("Nnodes = %d, should be %d\n", nnodes, wsize);
86 if (nedges != 2 * wsize) {
88 printf("Nedges = %d, should be %d\n", nedges, 2 * wsize);
90 outindex = (int *) malloc(wsize * sizeof(int));
91 outedges = (int *) malloc(wsize * 2 * sizeof(int));
92 if (!outindex || !outedges) {
93 printf("Unable to allocate %d words for outindex or outedges\n", 3 * wsize);
94 MPI_Abort(MPI_COMM_WORLD, 1);
97 MPI_Graph_get(comm2, wsize, 2 * wsize, outindex, outedges);
98 for (i = 0; i < wsize; i++) {
99 if (index[i] != outindex[i]) {
100 printf("%d = index[%d] != outindex[%d] = %d\n", index[i], i, i, outindex[i]);
104 for (i = 0; i < 2 * wsize; i++) {
105 if (edges[i] != outedges[i]) {
106 printf("%d = edges[%d] != outedges[%d] = %d\n", edges[i], i, i, outedges[i]);
116 MPI_Comm_free(&comm2);
117 MPI_Comm_free(&comm1);
120 MTest_Finalize(errs);