Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] ISP tests integration
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-testany.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, flag;
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, 1, 1, MPI_COMM_WORLD, &reqs[0]);
43       MPI_Irecv (buf1, buf_size, MPI_INT, 1, 2, MPI_COMM_WORLD, &reqs[1]);
44       MPI_Irecv (buf2, buf_size, MPI_INT, 1, 3, MPI_COMM_WORLD, &reqs[2]);
45
46       for (i = 3; i > 0; i--) {
47         MPI_Send (&flipbit, 1, MPI_INT, 1, i, MPI_COMM_WORLD);
48
49         flag = 0;
50 printf ("req = %0x", (unsigned int)reqs);
51         while (!flag)
52             MPI_Testany (i, reqs, &done, &flag, &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, 0, i, MPI_COMM_WORLD, &status);
63         
64         MPI_Send (buf0, buf_size, MPI_INT, 0, i, MPI_COMM_WORLD);
65       }
66     }
67
68   MPI_Barrier (MPI_COMM_WORLD);
69
70   MPI_Finalize ();
71   printf ("(%d) Finished normally\n", rank);
72 }
73
74 /* EOF */