Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix umpire issues : MPI_Comm cannot be safely put inside an int
[simgrid.git] / teshsuite / smpi / isp / umpire / group-no-free-exhaustive.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov)  */
3
4 /* group-no-free-exhaustive.c -- use all group constructors without freeing */
5
6 #ifndef lint
7 static char *rcsid =
8   "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/group-no-free-exhaustive.c,v 1.1 2002/05/29 16:09:49 bronis Exp $";
9 #endif
10
11 #include <stdio.h>
12 #include <string.h>
13 #include "mpi.h"
14
15
16 #define GROUP_CONSTRUCTOR_COUNT 9
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
103   MPI_Barrier (comm);
104
105   printf ("(%d) Finished normally\n", rank);
106   MPI_Finalize ();
107 }
108
109 /* EOF */