Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #193 from Takishipp/signals
[simgrid.git] / teshsuite / smpi / isp / umpire / any_src-can-deadlock4.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Tue Aug 26 2003 */
3 /* any_src-can-deadlock4.c -- deadlock occurs if task 0 receives */
4 /*                            from task 1 first; pretty random */
5 /*                            as to which is received first... */
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   MPI_Request req;
23
24   /* init */
25   MPI_Init (&argc, &argv);
26   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
27   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
28   MPI_Get_processor_name (processor_name, &namelen);
29   printf ("(%d) is alive on %s\n", rank, processor_name);
30   fflush (stdout);
31
32   MPI_Barrier (MPI_COMM_WORLD);
33
34   if (nprocs < 3)
35     {
36       printf ("not enough tasks\n");
37     }
38   else if (rank == 0)
39     {
40       MPI_Irecv (buf0, buf_size, MPI_INT,
41                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &req);
42
43       MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD, &status);
44
45       MPI_Send (buf1, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD);
46
47       MPI_Recv (buf1, buf_size, MPI_INT,
48                 MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
49
50       MPI_Wait (&req, &status);
51     }
52   else if (rank == 1)
53     {
54       memset (buf0, 0, buf_size);
55
56       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
57
58       MPI_Recv (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
59
60       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
61     }
62   else if (rank == 2)
63     {
64       memset (buf1, 1, buf_size);
65
66       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
67     }
68
69   MPI_Barrier (MPI_COMM_WORLD);
70
71   MPI_Finalize ();
72   printf ("(%d) Finished normally\n", rank);
73 }
74
75 /* EOF */