Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Multiply memset size by size of element in umpire.
[simgrid.git] / teshsuite / smpi / isp / umpire / any_src-waitany-deadlock2.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   int done;
20   MPI_Status statuses[2];
21   MPI_Request reqs[2];
22
23   /* init */
24   MPI_Init (&argc, &argv);
25   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
26   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
27   MPI_Get_processor_name (processor_name, &namelen);
28   printf ("(%d) is alive on %s\n", rank, processor_name);
29   fflush (stdout);
30
31   MPI_Barrier (MPI_COMM_WORLD);
32
33   /* this code is very similar to no-error-waitall-any_src.c */
34   /* but deadlocks since task 2's send and recv are inverted... */
35   if (nprocs < 3)
36     {
37       printf ("not enough tasks\n");
38     }
39   else if (rank == 0)
40     {
41       MPI_Irecv (buf0, buf_size, MPI_INT,
42                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &reqs[0]);
43
44       MPI_Irecv (buf1, buf_size, MPI_INT,
45                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &reqs[1]);
46
47       MPI_Waitall (2, reqs, statuses);
48
49       MPI_Send (buf1, buf_size, MPI_INT, 1, 1, MPI_COMM_WORLD);
50     }
51   else if (rank == 1)
52     {
53       memset (buf0, 0, buf_size*sizeof(int));
54
55       MPI_Isend (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &reqs[0]);
56
57       MPI_Isend (buf0, buf_size, MPI_INT, 2, 1, MPI_COMM_WORLD, &reqs[1]);
58
59       MPI_Waitany (2, reqs, &done, statuses);
60
61       MPI_Recv (buf1, buf_size, MPI_INT, 0, 1, MPI_COMM_WORLD, statuses);
62
63       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
64
65       MPI_Wait (&reqs[(done + 1) % 2], statuses);
66     }
67   else if (rank == 2)
68     {
69     //  sleep (60);
70
71       MPI_Recv (buf1, buf_size, MPI_INT, 1, 1, MPI_COMM_WORLD, statuses);
72     }
73
74   MPI_Barrier (MPI_COMM_WORLD);
75
76   MPI_Finalize ();
77   printf ("(%d) Finished normally\n", rank);
78 }
79
80 /* EOF */