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 );
41 if (outdims[i] != dims[i]) {
43 printf( "%d = outdims[%d] != dims[%d] = %d\n", outdims[i],
46 if (outperiods[i] != periods[i]) {
48 printf( "%d = outperiods[%d] != periods[%d] = %d\n",
49 outperiods[i], i, i, periods[i] );
53 MPI_Comm_free( &comm2 );
54 MPI_Comm_free( &comm1 );
56 /* Now do the same with a graph topology */
58 index = (int*)malloc(wsize * sizeof(int) );
59 edges = (int*)malloc(wsize * 2 * sizeof(int) );
60 if (!index || !edges) {
61 printf( "Unable to allocate %d words for index or edges\n",
63 MPI_Abort( MPI_COMM_WORLD, 1 );
66 for (i=1; i<wsize; i++) {
67 index[i] = 2 + index[i-1];
70 for (i=0; i<wsize; i++) {
71 edges[k++] = (i-1+wsize) % wsize;
72 edges[k++] = (i+1) % wsize;
74 MPI_Graph_create( MPI_COMM_WORLD, wsize, index, edges, 0, &comm1 );
75 MPI_Comm_dup( comm1, &comm2 );
76 MPI_Topo_test( comm2, &topo_type );
77 if (topo_type != MPI_GRAPH) {
79 printf( "Topo type of duped graph was not graph\n" );
83 MPI_Graphdims_get( comm2, &nnodes, &nedges );
84 if (nnodes != wsize) {
86 printf( "Nnodes = %d, should be %d\n", nnodes, wsize );
88 if (nedges != 2*wsize) {
90 printf( "Nedges = %d, should be %d\n", nedges, 2*wsize );
92 outindex = (int*)malloc(wsize * sizeof(int) );
93 outedges = (int*)malloc(wsize * 2 * sizeof(int) );
94 if (!outindex || !outedges) {
95 printf( "Unable to allocate %d words for outindex or outedges\n",
97 MPI_Abort( MPI_COMM_WORLD, 1 );
100 MPI_Graph_get( comm2, wsize, 2*wsize, outindex, outedges );
101 for (i=0; i<wsize; i++) {
102 if (index[i] != outindex[i]) {
103 printf( "%d = index[%d] != outindex[%d] = %d\n",
104 index[i], i, i, outindex[i] );
108 for (i=0; i<2*wsize; i++) {
109 if (edges[i] != outedges[i]) {
110 printf( "%d = edges[%d] != outedges[%d] = %d\n",
111 edges[i], i, i, outedges[i] );
121 MPI_Comm_free( &comm2 );
122 MPI_Comm_free( &comm1 );
125 MTest_Finalize( errs );