Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ignore generated tesh files
[simgrid.git] / teshsuite / smpi / isp / umpire / any_src-can-deadlock6.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Tue Aug 26 2003 */
3 /* any_src-can-deadlock5.c -- deadlock occurs if task 0 receives */
4 /*                            from task 1 first; sleeps generally */
5 /*                            make order 2 before 1 with all task */
6 /*                            0 ops being posted after both 1 and 2 */
7
8
9 #include <stdio.h>
10 #include "mpi.h"
11
12 #define buf_size 128
13
14 int
15 main (int argc, char **argv)
16 {
17   int nprocs = -1;
18   int rank = -1;
19   char processor_name[128];
20   int namelen = 128;
21   int buf0[buf_size];
22   int buf1[buf_size];
23   MPI_Status status;
24   MPI_Request req;
25
26   /* init */
27   MPI_Init (&argc, &argv);
28   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
29   MPI_Comm_rank (MPI_COMM_WORLD, &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 ("not enough tasks\n");
39     }
40   else if (rank == 0)
41     {
42 //      sleep (60);
43
44       MPI_Irecv (buf0, buf_size, MPI_INT, 
45                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &req);
46
47       MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD, &status);
48
49       MPI_Send (buf1, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD);
50
51       MPI_Recv (buf1, buf_size, MPI_INT, 
52                 MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
53
54       MPI_Wait (&req, &status);
55     }
56   else if (rank == 1)
57     {
58       memset (buf0, 0, buf_size);
59
60  //     sleep (30);
61
62       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
63
64       MPI_Recv (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
65
66       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
67     }
68   else if (rank == 2)
69     {
70       memset (buf1, 1, buf_size);
71
72       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
73     }
74
75   MPI_Barrier (MPI_COMM_WORLD);
76
77   MPI_Finalize ();
78   printf ("(%d) Finished normally\n", rank);
79 }
80
81 /* EOF */