Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7de46f9303e9b303b60b175abaf1047f5df4f788
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-waitany2.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Mon Jan 21 2003 */
3 /* no-error-waitany2.c -- test behavior with MPI_Waitany & MPI_REQUEST_NULL */
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       /* first just try MPI_Waitany on explicit MPI_REQUEST_NULL set... */
43       reqs[0] = reqs[1] = reqs[2] = MPI_REQUEST_NULL;
44
45       MPI_Waitany (3, reqs, &done, &status);
46
47       assert (done < 0);
48
49       MPI_Irecv (buf0, buf_size, MPI_INT, 1, 1, MPI_COMM_WORLD, &reqs[0]);
50       MPI_Irecv (buf1, buf_size, MPI_INT, 1, 2, MPI_COMM_WORLD, &reqs[1]);
51       MPI_Irecv (buf2, buf_size, MPI_INT, 1, 3, MPI_COMM_WORLD, &reqs[2]);
52
53       for (i = 3; i >= 0; i--) {
54         MPI_Send (&flipbit, 1, MPI_INT, 1, i, MPI_COMM_WORLD);
55
56         MPI_Waitany (3, reqs, &done, &status);
57 printf ("Done = %d\n", done);
58
59         if (i > 0) {
60           assert (done == (i - 1));
61         }
62         else {
63           assert (done < 0);
64         }
65       }
66     }
67   else if (rank == 1)
68     {
69       memset (buf0, 1, buf_size);
70
71       for (i = 3; i >= 0; i--) {
72         MPI_Recv (&flipbit, 1, MPI_INT, 0, i, MPI_COMM_WORLD, &status);
73         
74         if (i > 0) {
75           MPI_Send (buf0, buf_size, MPI_INT, 0, i, MPI_COMM_WORLD);
76         }
77       }
78     }
79
80   MPI_Barrier (MPI_COMM_WORLD);
81
82   MPI_Finalize ();
83   printf ("(%d) Finished normally\n", rank);
84 }
85
86 /* EOF */