Logo AND Algorithmique Numérique Distribuée

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