Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Ignore stdout/stderr of the umpire tests
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-probe-any_src.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Wed Oct 30 2002 */
3 /* no-error-probe-any_src.c -- do some MPI calls without any errors */
4 /* adapted from MPI The Complete Reference, p. 77... */
5
6
7 #include <stdio.h>
8 #include "mpi.h"
9
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 i, j;
19   double x;
20   MPI_Status status;
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 < 3)
34     {
35       printf ("not enough tasks\n");
36     }
37   else if (rank == 0)
38     {
39       i = 0;
40
41       MPI_Send (&i, 1, MPI_INT, 2, 0, MPI_COMM_WORLD);
42     }
43   else if (rank == 1)
44     {
45       x = 1.0;
46
47       MPI_Send (&x, 1, MPI_DOUBLE, 2, 0, MPI_COMM_WORLD);
48     }
49   else if (rank == 2)
50     {
51       for (j = 0; j < 2; j++) {
52         MPI_Probe (MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
53       
54         if (status.MPI_SOURCE == 0)
55           MPI_Recv (&i, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
56         else 
57           MPI_Recv (&x, 1, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD, &status);
58       }
59     }
60       
61   MPI_Barrier (MPI_COMM_WORLD);
62
63   MPI_Finalize ();
64   printf ("(%d) Finished normally\n", rank);
65 }
66
67 /* EOF */