Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / isp / umpire / comm-bcast-deadlock.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Tue Aug 12 2003 */
3
4 #ifndef lint
5 static char *rcsid =
6   "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/comm-bcast-deadlock.c,v 1.1 2003/09/02 15:57:49 bronis 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   int comm = MPI_COMM_WORLD;
21   char processor_name[128];
22   int namelen = 128;
23   MPI_Comm inverted_comm;
24   int bcast_rank;
25
26   /* init */
27   MPI_Init (&argc, &argv);
28   MPI_Comm_size (comm, &nprocs);
29   MPI_Comm_rank (comm, &rank);
30   MPI_Get_processor_name (processor_name, &namelen);
31   printf ("(%d) is alive on %s\n", rank, processor_name);
32   fflush (stdout);
33
34   MPI_Barrier (MPI_COMM_WORLD);
35
36   if (nprocs != 3)
37     {
38       printf ("Incorrect number of tasks; exactly 3 required\n");
39     }
40   else {
41     /* create inverted communicator... */
42     MPI_Comm_split (comm, 0, nprocs - rank, &inverted_comm);
43
44     if (rank == 1) {
45       MPI_Bcast (&rank, 1, MPI_INT, 1, inverted_comm);
46       MPI_Bcast (&bcast_rank, 1, MPI_INT, 2, comm);
47     }
48     else if (rank == 2) {
49       MPI_Bcast (&rank, 1, MPI_INT, 2, comm);
50       MPI_Bcast (&bcast_rank, 1, MPI_INT, 1, inverted_comm);
51     }
52     else {
53       MPI_Bcast (&bcast_rank, 1, MPI_INT, 2, comm);
54       MPI_Bcast (&bcast_rank, 1, MPI_INT, 1, inverted_comm);
55     }
56   }
57
58   MPI_Barrier (comm);
59
60   printf ("(%d) Finished normally\n", rank);
61
62   MPI_Finalize ();
63 }
64
65 /* EOF */