Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ignore generated tesh files
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-waitany-any_src2.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 <assert.h>
7 #include "mpi.h"
8
9 #define buf_size 128
10
11 int
12 main (int argc, char **argv)
13 {
14   int nprocs = -1;
15   int rank = -1;
16   int done;
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 reqs[2];
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   /* this code is very similar to any_src-waitall-deadlock.c */
35   /* but eliminates the deadlock by using MPI_Waitany... */
36   /* also very similar to no-error-waitall-any_src.c but */
37   /* this code is deterministic; buf0 holds result of */
38   /* memset to 0 and buf1 holds the result of memset to */
39   /* in all three tasks since must match the first Irecv first... */
40   if (nprocs < 3)
41     {
42       printf ("not enough tasks\n");
43     }
44   else if (rank == 0)
45     {
46       MPI_Irecv (buf0, buf_size, MPI_INT, 
47                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &reqs[0]);
48
49       MPI_Irecv (buf1, buf_size, MPI_INT, 
50                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &reqs[1]);
51
52       MPI_Waitany (2, reqs, &done, &status);
53
54       assert (done == 0);
55
56       MPI_Send (buf1, buf_size, MPI_INT, 1, 1, MPI_COMM_WORLD);
57
58       MPI_Send (buf0, buf_size, MPI_INT, 2, 2, MPI_COMM_WORLD);
59
60       MPI_Wait (&reqs[1], &status);
61     }
62   else if (rank == 1)
63     {
64       memset (buf0, 0, buf_size);
65
66       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
67
68       MPI_Recv (buf1, buf_size, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
69     }
70   else if (rank == 2)
71     {
72       MPI_Recv (buf0, buf_size, MPI_INT, 0, 2, MPI_COMM_WORLD, &status);
73
74       memset (buf1, 1, buf_size);
75
76       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
77     }
78
79   MPI_Barrier (MPI_COMM_WORLD);
80
81   MPI_Finalize ();
82   printf ("(%d) Finished normally\n", rank);
83 }
84
85 /* EOF */