Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f7102f57493ca5f4abdbc4677f3e1b520e6f36ea
[simgrid.git] / teshsuite / smpi / mpich-test / coll / grouptest.c
1 /*      $Id: grouptest.c,v 1.2 1998/11/28 04:04:56 gropp Exp $   */
2
3 #include "mpi.h"
4 #include <stdio.h>
5 #include "test.h"
6
7 int main( int argc, char **argv )
8 {
9     int rank, size, i;
10     MPI_Group group1, group2, group3, groupall, groupunion, newgroup;
11     MPI_Comm newcomm;
12     int ranks1[100], ranks2[100], ranks3[100];
13     int nranks1=0, nranks2=0, nranks3=0;
14
15     MPI_Init( &argc, &argv );
16     MPI_Barrier( MPI_COMM_WORLD );
17     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
18     MPI_Comm_size( MPI_COMM_WORLD, &size );
19     MPI_Comm_group( MPI_COMM_WORLD, &groupall );
20
21     /* Divide groups */
22     for (i=0; i<size; i++) 
23       if ( (i%3)==0 )
24         ranks1[nranks1++] = i;
25       else if ( (i%3)==1 )
26         ranks2[nranks2++] = i;
27       else
28         ranks3[nranks3++] = i;
29
30     MPI_Group_incl ( groupall, nranks1, ranks1, &group1 );
31     MPI_Group_incl ( groupall, nranks2, ranks2, &group2 );
32     MPI_Group_incl ( groupall, nranks3, ranks3, &group3 );
33
34     MPI_Group_difference ( groupall, group2, &groupunion );
35
36     MPI_Comm_create ( MPI_COMM_WORLD, group3, &newcomm );
37     newgroup = MPI_GROUP_NULL;
38     if (newcomm != MPI_COMM_NULL)
39     {
40         /* If we don't belong to group3, this would fail */
41         MPI_Comm_group ( newcomm, &newgroup );
42     }
43
44     /* Free the groups */
45    /* MPI_Group_free( &groupall );
46     MPI_Group_free( &group1 );
47     MPI_Group_free( &group2 );
48     MPI_Group_free( &group3 );
49     MPI_Group_free( &groupunion );*/
50     if (newgroup != MPI_GROUP_NULL)
51     {
52         //MPI_Group_free( &newgroup );
53     }
54
55     /* Free the communicator */
56     //if (newcomm != MPI_COMM_NULL)
57         //MPI_Comm_free( &newcomm );
58     Test_Waitforall( );
59     MPI_Finalize();
60     return 0;
61 }