Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #237 from oar-team/upstream
[simgrid.git] / teshsuite / smpi / isp / umpire / comm-translate-ranks.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Jeffrey Vetter (vetter3@llnl.gov) Thu Feb 24 2000 */
3
4 #ifndef lint
5 static char *rcsid =
6   "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/comm-translate-ranks.c,v 1.1.1.1 2000/08/23 17:28:26 vetter Exp $";
7 #endif
8
9 #include <stdio.h>
10 #include <string.h>
11 #include "mpi.h"
12
13 #define buf_size 128
14
15 int
16 main (int argc, char **argv)
17 {
18   int nprocs = -1;
19   int rank = -1;
20   MPI_Comm comm = MPI_COMM_WORLD;
21   char processor_name[128];
22   int namelen = 128;
23   MPI_Comm newcomm;
24   int key = -1;
25   int nrank;
26   int nsize;
27   int color = -1;
28
29
30   /* init */
31   MPI_Init (&argc, &argv);
32   MPI_Comm_size (comm, &nprocs);
33   MPI_Comm_rank (comm, &rank);
34   MPI_Get_processor_name (processor_name, &namelen);
35   printf ("(%d) is alive on %s\n", rank, processor_name);
36   fflush (stdout);
37
38   MPI_Barrier (comm);
39
40   {
41     color = rank % 2;
42     key = 1;
43     MPI_Comm_split (comm, color, key, &newcomm);
44
45     MPI_Comm_size (newcomm, &nsize);
46     MPI_Comm_rank (newcomm, &nrank);
47     printf ("world task %p/%d/%d maps to new comm task %p/%d/%d\n",
48             comm, nprocs, rank, newcomm, nsize, nrank);
49   }
50
51   MPI_Barrier (comm);
52
53   /* after every comm constructor, fetch the rank translation from the
54      0 rank of that comm (assume that there is a 0). */
55
56   if (nrank == 0)
57     {
58       int i;
59       MPI_Group wcGroup;
60       int wcRanks[128];
61       MPI_Group ncGroup;
62       int ncRanks[128];
63
64       MPI_Comm_group (comm, &wcGroup);
65       MPI_Comm_group (newcomm, &ncGroup);
66
67       for (i = 0; i < nprocs; i++)
68         {
69           wcRanks[i] = i;
70         }
71
72       MPI_Group_translate_ranks (wcGroup, nprocs, wcRanks, ncGroup, ncRanks);
73
74       for (i = 0; i < nprocs; i++)
75         {
76           if (ncRanks[i] == MPI_UNDEFINED)
77             {
78               printf ("World rank %d ->\tUNDEFINED\n", wcRanks[i]);
79             }
80           else
81             {
82               printf ("World rank %d ->\t%d\n", wcRanks[i], ncRanks[i]);
83             }
84         }
85     }
86
87   MPI_Barrier (comm);
88
89   printf ("(%d) Finished normally\n", rank);
90   MPI_Finalize ();
91 }
92
93 /* EOF */