2 This file generates a few communicators for use in the test suite
4 THIS CODE IS FROM mpich/tsuite AND SHOULD BE CHANGED THERE ONLY
11 void MakeComms( comms, maxn, n, make_intercomm )
13 int *n, maxn, make_intercomm;
18 int periods[2], range[1][3];
19 MPI_Group group, newgroup;
21 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
22 MPI_Comm_size( MPI_COMM_WORLD, &size );
24 comms[cnt++] = MPI_COMM_WORLD;
25 if (cnt == maxn) {*n = cnt; return; }
27 /* Construct a communicator with the ranks reversed */
28 MPI_Comm_group( MPI_COMM_WORLD, &group );
32 MPI_Group_range_incl( group, 1, range, &newgroup );
33 MPI_Comm_create( MPI_COMM_WORLD, newgroup, &comms[cnt] );
35 //MPI_Group_free( &group );
36 //MPI_Group_free( &newgroup );
37 if (cnt == maxn) {*n = cnt; return; }
40 /* Divide into odd and even processes */
41 MPI_Comm_split( MPI_COMM_WORLD, rank & 0x1, rank, comms + cnt );
44 /* Use the cartesian constructors */
45 dims[0] = 0; dims[1] = 0;
46 MPI_Dims_create( size, 2, dims );
47 periods[0] = 0; periods[1] = 0;
48 MPI_Cart_create( MPI_COMM_WORLD, 2, dims, periods, 0, comms + cnt );
50 if (cnt == maxn) {*n = cnt; return; }
52 /* Create an intercommunicator (point-to-point operations only)
53 Note that in this case, codes need to use MPI_Comm_remote_size to
54 (added to MPI_Comm_size) to get the size of the full group */
56 /* The remote_leader is rank 1 in MPI_COMM_WORLD if we are even
57 and 0 if we are odd (the remote_leader rank is relative to the
60 MPI_Intercomm_create( comms[2], 0, MPI_COMM_WORLD, !(rank&0x1),
63 if (cnt == maxn) {*n = cnt; return; }
69 void FreeComms( comms, n )
75 if (comms[i] != MPI_COMM_NULL)
76 MPI_Comm_free( comms + i );