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-can-deadlock10_mod.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Tue Sep 30 2003 */
3 /* any_src-can-deadlock10.c -- deadlock occurs if task 0 receives */
4 /*                             from task 1 first; sleeps generally */
5 /*                             make order 1 before 2 with all task */
6 /*                             0 ops being posted before both 1 and 2 */
7
8
9 #include <stdio.h>
10 #include <stdlib.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       MPI_Irecv (buf0, buf_size, MPI_INT,
44                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &req);
45
46       MPI_Recv (buf1, buf_size, MPI_INT, 2, 0, MPI_COMM_WORLD, &status);
47
48       MPI_Send (buf1, buf_size, MPI_INT, 2, 0, MPI_COMM_WORLD);
49
50       MPI_Recv (buf1, buf_size, MPI_INT,
51                 MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
52
53       MPI_Wait (&req, &status);
54     }
55   else if (rank == 2)
56     {
57       memset (buf0, 0, buf_size*sizeof(int));
58
59     //  sleep (30);
60
61       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
62
63       MPI_Recv (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
64
65       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
66     }
67   else if (rank == 1)
68     {
69       memset (buf1, 1, buf_size*sizeof(int));
70
71      // sleep (60);
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 */