Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #193 from Takishipp/signals
[simgrid.git] / teshsuite / smpi / isp / umpire / remote_group-no-error.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/remote_group-no-error.c,v 1.1 2002/07/30 21:34:43 bronis Exp $";
9 #endif
10
11 #include <stdio.h>
12 #include <string.h>
13 #include "mpi.h"
14
15
16 #define INTERCOMM_CREATE_TAG 666
17
18
19 int
20 main (int argc, char **argv)
21 {
22   int nprocs = -1;
23   int rank = -1;
24   MPI_Comm comm = MPI_COMM_WORLD;
25   char processor_name[128];
26   int namelen = 128;
27   int i;
28   MPI_Group newgroup;
29   MPI_Group newgroup2;
30   MPI_Comm temp;
31   MPI_Comm intercomm = MPI_COMM_NULL;
32
33   /* init */
34   MPI_Init (&argc, &argv);
35   MPI_Comm_size (comm, &nprocs);
36   MPI_Comm_rank (comm, &rank);
37   MPI_Get_processor_name (processor_name, &namelen);
38   printf ("(%d) is alive on %s\n", rank, processor_name);
39   fflush (stdout);
40
41   MPI_Barrier (comm);
42
43   if (nprocs < 3) {
44       printf ("requires at least 3 tasks\n");
45   }
46   else {
47     /* create the groups */
48     /* need lots of stuff for this constructor... */
49     MPI_Comm_split (MPI_COMM_WORLD, rank % 3, nprocs - rank, &temp);
50
51     if (rank % 3) {
52       MPI_Intercomm_create (temp, 0, MPI_COMM_WORLD,
53                             (((nprocs % 3) == 2) && ((rank % 3) == 2)) ?
54                             nprocs - 1 : nprocs - (rank % 3) - (nprocs % 3),
55                             INTERCOMM_CREATE_TAG, &intercomm);
56
57       MPI_Comm_remote_group (intercomm, &newgroup);
58
59       MPI_Comm_free (&intercomm);
60     }
61     else {
62       MPI_Comm_group (temp, &newgroup);
63     }
64
65     MPI_Comm_free (&temp);
66
67     MPI_Group_free (&newgroup);
68
69     MPI_Barrier (comm);
70
71     /* create the groups again and free with an alias... */
72     /* need lots of stuff for this constructor... */
73     MPI_Comm_split (MPI_COMM_WORLD, rank % 3, nprocs - rank, &temp);
74
75     if (rank % 3) {
76       MPI_Intercomm_create (temp, 0, MPI_COMM_WORLD,
77                             (((nprocs % 3) == 2) && ((rank % 3) == 2)) ?
78                             nprocs - 1 : nprocs - (rank % 3) - (nprocs % 3),
79                             INTERCOMM_CREATE_TAG, &intercomm);
80
81       MPI_Comm_remote_group (intercomm, &newgroup);
82
83       MPI_Comm_free (&intercomm);
84     }
85     else {
86       MPI_Comm_group (temp, &newgroup);
87     }
88
89     MPI_Comm_free (&temp);
90
91     newgroup2 = newgroup;
92     MPI_Group_free (&newgroup2);
93   }
94
95   MPI_Barrier (comm);
96
97   printf ("(%d) Finished normally\n", rank);
98   MPI_Finalize ();
99 }
100
101 /* EOF */