Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'clean_events' of github.com:Takishipp/simgrid into clean_events
[simgrid.git] / teshsuite / smpi / isp / umpire / any_src-can-deadlock2.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Thu Jan 3 2002 */
3 /* any_src-can-deadlock.c -- deadlock occurs if task 0 receives */
4 /*                           from task 2 first; the likely outcome */
5 /*                           because we sleep task 1 */
6
7 #include <stdio.h>
8 #include "mpi.h"
9
10 #define buf_size 128
11
12 int
13 main (int argc, char **argv)
14 {
15   int nprocs = -1;
16   int rank = -1;
17   char processor_name[128];
18   int namelen = 128;
19   int buf0[buf_size];
20   int buf1[buf_size];
21   MPI_Status status;
22
23   /* init */
24   MPI_Init (&argc, &argv);
25   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
26   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
27   MPI_Get_processor_name (processor_name, &namelen);
28   printf ("(%d) is alive on %s\n", rank, processor_name);
29   fflush (stdout);
30
31   MPI_Barrier (MPI_COMM_WORLD);
32
33   if (nprocs < 3)
34     {
35       printf ("not enough tasks\n");
36     }
37   else if (rank == 0)
38     {
39       MPI_Recv (buf1, buf_size, MPI_INT,
40                 MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
41
42       MPI_Send (buf1, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD);
43
44       MPI_Recv (buf0, buf_size, MPI_INT,
45                 MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
46     }
47   else if (rank == 1)
48     {
49       memset (buf0, 0, buf_size);
50
51      // sleep (60);
52
53       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
54
55       MPI_Recv (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
56     }
57   else if (rank == 2)
58     {
59       memset (buf1, 1, buf_size);
60
61       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
62     }
63
64   MPI_Barrier (MPI_COMM_WORLD);
65
66   MPI_Finalize ();
67   printf ("(%d) Finished normally\n", rank);
68 }
69
70 /* EOF */