Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / isp / umpire / group-no-error-exhaustive.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov)  */
3
4 /* type-no-error-exhaustive.c -- use all group constructors correctly */
5
6 #ifndef lint
7 static char *rcsid =
8   "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/group-no-error-exhaustive.c,v 1.2 2002/07/30 21:34:42 bronis Exp $";
9 #endif
10
11 #include <stdio.h>
12 #include <string.h>
13 #include "mpi.h"
14
15
16 #define GROUP_CONSTRUCTOR_COUNT 8
17 #define INTERCOMM_CREATE_TAG 666
18
19
20 int
21 main (int argc, char **argv)
22 {
23   int nprocs = -1;
24   int rank = -1;
25   MPI_Comm comm = MPI_COMM_WORLD;
26   char processor_name[128];
27   int namelen = 128;
28   int i;
29   int ranks[2], ranges[1][3];
30   MPI_Group newgroup[GROUP_CONSTRUCTOR_COUNT]; 
31   MPI_Group newgroup2[GROUP_CONSTRUCTOR_COUNT]; 
32   MPI_Comm temp;
33   MPI_Comm intercomm = MPI_COMM_NULL;
34
35   /* init */
36   MPI_Init (&argc, &argv);
37   MPI_Comm_size (comm, &nprocs);
38   MPI_Comm_rank (comm, &rank);
39   MPI_Get_processor_name (processor_name, &namelen);
40   printf ("(%d) is alive on %s\n", rank, processor_name);
41   fflush (stdout);
42
43   ranks[0] = 0;
44   ranks[1] = 1;
45
46   ranges[0][0] = 0;
47   ranges[0][1] = 2;
48   ranges[0][2] = 2;
49
50   MPI_Barrier (comm);
51
52   if (nprocs < 3) {
53       printf ("requires at least 3 tasks\n");
54   }
55   else {
56     /* create the groups */
57     if (GROUP_CONSTRUCTOR_COUNT > 0)
58       MPI_Comm_group (MPI_COMM_WORLD, &newgroup[0]);
59
60     if (GROUP_CONSTRUCTOR_COUNT > 1)
61       MPI_Group_incl (newgroup[0], 2, ranks, &newgroup[1]);    
62
63     if (GROUP_CONSTRUCTOR_COUNT > 2)
64       MPI_Group_excl (newgroup[0], 2, ranks, &newgroup[2]);
65
66     if (GROUP_CONSTRUCTOR_COUNT > 3)
67       MPI_Group_range_incl (newgroup[0], 1, ranges, &newgroup[3]);    
68
69     if (GROUP_CONSTRUCTOR_COUNT > 4)
70       MPI_Group_range_excl (newgroup[0], 1, ranges, &newgroup[4]);    
71
72     if (GROUP_CONSTRUCTOR_COUNT > 5)
73       MPI_Group_union (newgroup[1], newgroup[3], &newgroup[5]);
74
75     if (GROUP_CONSTRUCTOR_COUNT > 6)
76       MPI_Group_intersection (newgroup[5], newgroup[2], &newgroup[6]);
77
78     if (GROUP_CONSTRUCTOR_COUNT > 7)
79       MPI_Group_difference (newgroup[5], newgroup[2], &newgroup[7]);
80
81     if (GROUP_CONSTRUCTOR_COUNT > 8) {
82       /* need lots of stuff for this constructor... */
83       MPI_Comm_split (MPI_COMM_WORLD, rank % 3, nprocs - rank, &temp);
84
85       if (rank % 3) {
86         MPI_Intercomm_create (temp, 0, MPI_COMM_WORLD, 
87                               (((nprocs % 3) == 2) && ((rank % 3) == 2)) ?
88                               nprocs - 1 : nprocs - (rank % 3) - (nprocs % 3),
89                               INTERCOMM_CREATE_TAG, &intercomm);
90
91         MPI_Comm_remote_group (intercomm, &newgroup[8]);
92
93         MPI_Comm_free (&intercomm);
94       }
95       else {
96         MPI_Comm_group (temp, &newgroup[8]);
97       }
98
99       MPI_Comm_free (&temp);
100     }
101       
102     for (i = 0; i < GROUP_CONSTRUCTOR_COUNT; i++)
103       MPI_Group_free (&newgroup[i]);
104
105     MPI_Barrier (comm);
106
107     /* create the groups again and free with an alias... */
108     if (GROUP_CONSTRUCTOR_COUNT > 0)
109       MPI_Comm_group (MPI_COMM_WORLD, &newgroup[0]);
110
111     if (GROUP_CONSTRUCTOR_COUNT > 1)
112       MPI_Group_incl (newgroup[0], 2, ranks, &newgroup[1]);    
113
114     if (GROUP_CONSTRUCTOR_COUNT > 2)
115       MPI_Group_excl (newgroup[0], 2, ranks, &newgroup[2]);
116
117     if (GROUP_CONSTRUCTOR_COUNT > 3)
118       MPI_Group_range_incl (newgroup[0], 1, ranges, &newgroup[3]);    
119
120     if (GROUP_CONSTRUCTOR_COUNT > 4)
121       MPI_Group_range_excl (newgroup[0], 1, ranges, &newgroup[4]);    
122
123     if (GROUP_CONSTRUCTOR_COUNT > 5)
124       MPI_Group_union (newgroup[1], newgroup[3], &newgroup[5]);
125
126     if (GROUP_CONSTRUCTOR_COUNT > 6)
127       MPI_Group_intersection (newgroup[5], newgroup[2], &newgroup[6]);
128
129     if (GROUP_CONSTRUCTOR_COUNT > 7)
130       MPI_Group_difference (newgroup[5], newgroup[2], &newgroup[7]);
131
132     if (GROUP_CONSTRUCTOR_COUNT > 8) {
133       /* need lots of stuff for this constructor... */
134       MPI_Comm_split (MPI_COMM_WORLD, rank % 3, nprocs - rank, &temp);
135
136       if (rank % 3) {
137         MPI_Intercomm_create (temp, 0, MPI_COMM_WORLD, 
138                               (((nprocs % 3) == 2) && ((rank % 3) == 2)) ?
139                               nprocs - 1 : nprocs - (rank % 3) - (nprocs % 3),
140                               INTERCOMM_CREATE_TAG, &intercomm);
141
142         MPI_Comm_remote_group (intercomm, &newgroup[8]);
143
144         MPI_Comm_free (&intercomm);
145       }
146       else {
147         MPI_Comm_group (temp, &newgroup[8]);
148       }
149
150       MPI_Comm_free (&temp);
151     }
152       
153     for (i = 0; i < GROUP_CONSTRUCTOR_COUNT; i++) {
154       newgroup2[i] = newgroup[i];
155       MPI_Group_free (&newgroup2[i]);
156     }
157   }
158
159   MPI_Barrier (comm);
160
161   printf ("(%d) Finished normally\n", rank);
162   MPI_Finalize ();
163 }
164
165 /* EOF */