Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add fortran tests from mpich-tests, enforce completion of mpich-tests suite with...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / gcomm.c
1 /* 
2     This file generates a few communicators for use in the test suite
3
4     THIS CODE IS FROM mpich/tsuite AND SHOULD BE CHANGED THERE ONLY
5  */
6
7 #include "mpi.h"
8
9 #include "gcomm.h"
10
11 void MakeComms( comms, maxn, n, make_intercomm )
12 MPI_Comm *comms;
13 int      *n, maxn, make_intercomm;
14 {
15 int cnt = 0;
16 int rank, size;
17 int dims[2];
18 int periods[2], range[1][3];
19 MPI_Group group, newgroup;
20
21 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
22 MPI_Comm_size( MPI_COMM_WORLD, &size );
23
24 comms[cnt++] = MPI_COMM_WORLD;
25 if (cnt == maxn) {*n = cnt; return; }
26
27 /* Construct a communicator with the ranks reversed */
28 MPI_Comm_group( MPI_COMM_WORLD, &group );
29 range[0][0] = size-1;
30 range[0][1] = 0;
31 range[0][2] = -1;
32 MPI_Group_range_incl( group, 1, range, &newgroup );
33 MPI_Comm_create( MPI_COMM_WORLD, newgroup, &comms[cnt] );
34 cnt++;
35 //MPI_Group_free( &group );
36 //MPI_Group_free( &newgroup );
37 if (cnt == maxn) {*n = cnt; return; }
38
39 if (size > 3) {
40     /* Divide into odd and even processes */
41     MPI_Comm_split( MPI_COMM_WORLD, rank & 0x1, rank, comms + cnt );
42     cnt ++;
43
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 );
49     cnt ++;
50     if (cnt == maxn) {*n = cnt; return; }
51
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 */
55     if (make_intercomm) {
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
58            peer communicator) 
59          */
60         MPI_Intercomm_create( comms[2], 0, MPI_COMM_WORLD, !(rank&0x1), 
61                               37, comms + cnt );
62         cnt ++;
63         if (cnt == maxn) {*n = cnt; return; }
64         }
65     }
66 *n = cnt;
67 }
68
69 void FreeComms( comms, n )
70 MPI_Comm *comms;
71 int      n;
72 {
73 int i;
74 for (i=1; i<n; i++) {
75     if (comms[i] != MPI_COMM_NULL) 
76         MPI_Comm_free( comms + i );
77     }
78 }