Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'clean_events' of github.com:Takishipp/simgrid into clean_events
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-testall.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Fri Mar  17 2000 */
3 /* no-error-testall.c -- use MPI_Testall without any errors */
4
5 #include <stdio.h>
6 #include "mpi.h"
7
8 #define buf_size 128
9
10 int
11 main (int argc, char **argv)
12 {
13   int nprocs = -1;
14   int rank = -1;
15   int flag = 0;
16   char processor_name[128];
17   int namelen = 128;
18   int buf0[buf_size];
19   int buf1[buf_size];
20   MPI_Status statuses[2];
21   MPI_Request reqs[2];
22
23   /* init */
24   MPI_Init (&argc, &argv);
25   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
26   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
27   MPI_Get_processor_name (processor_name, &namelen);
28   printf ("(%d) is alive on %s\n", rank, processor_name);
29   fflush (stdout);
30
31   MPI_Barrier (MPI_COMM_WORLD);
32
33   if (nprocs < 2)
34     {
35       printf ("not enough tasks\n");
36     }
37   else if (rank == 0)
38     {
39       MPI_Irecv (buf0, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD, &reqs[0]);
40
41       MPI_Irecv (buf1, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD, &reqs[1]);
42
43       while (!flag)
44         MPI_Testall (2, reqs, &flag, statuses);
45
46       MPI_Send (buf1, buf_size, MPI_INT, 1, 1, MPI_COMM_WORLD);
47     }
48   else if (rank == 1)
49     {
50       memset (buf0, 0, buf_size);
51
52       MPI_Isend (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &reqs[0]);
53
54       MPI_Isend (buf0, buf_size, MPI_INT, 2, 1, MPI_COMM_WORLD, &reqs[1]);
55
56       while (!flag)
57         MPI_Testall (2, reqs, &flag, statuses);
58
59       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
60
61       MPI_Recv (buf1, buf_size, MPI_INT, 0, 1, MPI_COMM_WORLD, statuses);
62     }
63   else if (rank == 2)
64     {
65       MPI_Recv (buf1, buf_size, MPI_INT, 1, 1, MPI_COMM_WORLD, statuses);
66     }
67
68   MPI_Barrier (MPI_COMM_WORLD);
69
70   MPI_Finalize ();
71   printf ("(%d) Finished normally\n", rank);
72 }
73
74 /* EOF */