Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ignore generated tesh files
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-probe-any_tag.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Wed Oct 30 2002 */
3 /* no-error-probe-any_tag.c -- do some MPI calls without any errors */
4
5
6 #include <stdio.h>
7 #include "mpi.h"
8
9
10 int
11 main (int argc, char **argv)
12 {
13   int nprocs = -1;
14   int rank = -1;
15   char processor_name[128];
16   int namelen = 128;
17   int i, j;
18   double x;
19   MPI_Status status;
20   MPI_Request req0, req1;
21
22   /* init */
23   MPI_Init (&argc, &argv);
24   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
25   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
26   MPI_Get_processor_name (processor_name, &namelen);
27   printf ("(%d) is alive on %s\n", rank, processor_name);
28   fflush (stdout);
29
30   MPI_Barrier (MPI_COMM_WORLD);
31
32   /* use probe to guarantee msg has arrived when blocking recv is called */
33   if (nprocs < 2)
34     {
35       printf ("not enough tasks\n");
36     }
37   else if (rank == 0)
38     {
39       i = 0;
40       x = 1.0;
41
42       MPI_Isend (&i, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &req0);
43
44       MPI_Isend (&x, 1, MPI_DOUBLE, 1, 1, MPI_COMM_WORLD, &req1);
45
46       MPI_Wait (&req1, &status);
47
48       MPI_Wait (&req0, &status);
49     }
50   else if (rank == 1) 
51     {
52       for (j = 0; j < 2; j++) {
53         MPI_Probe (0, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
54       
55         if (status.MPI_TAG == 0)
56           MPI_Recv (&i, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
57         else
58           MPI_Recv (&x, 1, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD, &status);
59       }
60     }
61       
62   MPI_Barrier (MPI_COMM_WORLD);
63
64   MPI_Finalize ();
65   printf ("(%d) Finished normally\n", rank);
66 }
67
68 /* EOF */