Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill all trailling whitespaces
[simgrid.git] / teshsuite / smpi / isp / umpire / any_src-waitall-deadlock.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Fri Mar  17 2000 */
3 /* no-error.c -- do some MPI calls without any errors */
4
5 #include <stdio.h>
6 #include "mpi.h"
7
8 #define buf_size 128
9
10 int
11 main (int argc, char **argv)
12 {
13   int nprocs = -1;
14   int rank = -1;
15   char processor_name[128];
16   int namelen = 128;
17   int buf0[buf_size];
18   int buf1[buf_size];
19   MPI_Status statuses[2];
20   MPI_Request reqs[2];
21
22   /* init */
23   MPI_Init (&argc, &argv);
24   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
25   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
26   MPI_Get_processor_name (processor_name, &namelen);
27   printf ("(%d) is alive on %s\n", rank, processor_name);
28   fflush (stdout);
29
30   MPI_Barrier (MPI_COMM_WORLD);
31
32   /* this code is very similar to no-error-waitall-any_src.c */
33   /* but deadlocks since task 2's send and recv are inverted... */
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, &reqs[0]);
42
43       MPI_Irecv (buf1, buf_size, MPI_INT,
44                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &reqs[1]);
45
46       MPI_Waitall (2, reqs, statuses);
47
48       MPI_Send (buf1, buf_size, MPI_INT, 1, 1, MPI_COMM_WORLD);
49
50       MPI_Send (buf0, buf_size, MPI_INT, 2, 2, MPI_COMM_WORLD);
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, 1, MPI_COMM_WORLD, statuses);
59     }
60   else if (rank == 2)
61     {
62       MPI_Recv (buf0, buf_size, MPI_INT, 0, 2, MPI_COMM_WORLD, statuses);
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 */