Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Improve option smpi/wtime
[simgrid.git] / teshsuite / smpi / isp / umpire / any_src-can-deadlock7.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Tue Aug 26 2003 */
3 /* any_src-can-deadlock7.c -- deadlock occurs if task 0 receives */
4 /*                            from task 2 first; pretty random */
5 /*                            as to which is received first... */
6 /*                            same as any_src-can-deadlock4.c */
7 /*                            except tasks 1 and 2 are interchanged */
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       MPI_Irecv (buf0, buf_size, MPI_INT,
43                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &req);
44
45       MPI_Recv (buf1, buf_size, MPI_INT, 2, 0, MPI_COMM_WORLD, &status);
46
47       MPI_Send (buf1, buf_size, MPI_INT, 2, 0, MPI_COMM_WORLD);
48
49       MPI_Recv (buf1, buf_size, MPI_INT,
50                 MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
51
52       MPI_Wait (&req, &status);
53     }
54   else if (rank == 2)
55     {
56       memset (buf0, 0, buf_size);
57
58       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
59
60       MPI_Recv (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
61
62       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
63     }
64   else if (rank == 1)
65     {
66       memset (buf1, 1, buf_size);
67
68       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
69     }
70
71   MPI_Barrier (MPI_COMM_WORLD);
72
73   MPI_Finalize ();
74   printf ("(%d) Finished normally\n", rank);
75 }
76
77 /* EOF */