Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ignore generated tesh files
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-waitany-any_src.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Fri Mar  17 2000 */
3 /* no-error-waitany.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   char processor_name[128];
17   int namelen = 128;
18   int buf0[buf_size];
19   int buf1[buf_size];
20   int buf2[buf_size];
21   int i, flipbit, done;
22   MPI_Status status;
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   if (nprocs < 2)
35     {
36       printf ("not enough tasks\n");
37     }
38   else if (rank == 0)
39     {
40       MPI_Request reqs[3];
41
42       MPI_Irecv (buf0, buf_size, MPI_INT, 
43                  MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &reqs[0]);
44       MPI_Irecv (buf1, buf_size, MPI_INT, 
45                  MPI_ANY_SOURCE, 2, MPI_COMM_WORLD, &reqs[1]);
46       MPI_Irecv (buf2, buf_size, MPI_INT, 
47                  MPI_ANY_SOURCE, 3, MPI_COMM_WORLD, &reqs[2]);
48
49       for (i = 3; i > 0; i--) {
50         MPI_Send (&flipbit, 1, MPI_INT, 1, i, MPI_COMM_WORLD);
51
52         MPI_Waitany (i, reqs, &done, &status);
53
54         assert (done == (i - 1));
55       }
56     }
57   else if (rank == 1)
58     {
59       memset (buf0, 1, buf_size);
60
61       for (i = 3; i > 0; i--) {
62         MPI_Recv (&flipbit, 1, MPI_INT, 
63                   MPI_ANY_SOURCE, i, MPI_COMM_WORLD, &status);
64         
65         MPI_Send (buf0, buf_size, MPI_INT, 0, i, MPI_COMM_WORLD);
66       }
67     }
68
69   MPI_Barrier (MPI_COMM_WORLD);
70
71   MPI_Finalize ();
72   printf ("(%d) Finished normally\n", rank);
73 }
74
75 /* EOF */