Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ignore generated tesh files
[simgrid.git] / teshsuite / smpi / isp / umpire / probe-any_src-types-can-mismatch.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Wed Oct 30 2002 */
3 /* probe-any_src-types-can-mismatch.c -- do nondeterministic recv after */
4 /* Probe; types can mismatch as a result but may not; require that we */
5 /* detect the mismatch if occurs; OK to detect  (or not) if it doesn't... */
6 /* adapted from MPI The Complete Reference, p. 78... */
7
8
9 #include <stdio.h>
10 #include "mpi.h"
11
12
13 int
14 main (int argc, char **argv)
15 {
16   int nprocs = -1;
17   int rank = -1;
18   char processor_name[128];
19   int namelen = 128;
20   int i, j;
21   double x;
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   /* because the probe and the receives both use */
35   /* MPI_ANY_SOURCE, we are not guaranteed that the */
36   /* first recv matches the probed msg, thus types can mismatch... */
37   if (nprocs < 3)
38     {
39       printf ("not enough tasks\n");
40     }
41   else if (rank == 0)
42     {
43       i = 0;
44
45       MPI_Send (&i, 1, MPI_INT, 2, 0, MPI_COMM_WORLD);
46     }
47   else if (rank == 1)
48     {
49       x = 1.0;
50
51       MPI_Send (&x, 1, MPI_DOUBLE, 2, 0, MPI_COMM_WORLD);
52     }
53   else if (rank == 2)
54     {
55       for (j = 0; j < 2; j++) {
56         MPI_Probe (MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
57       
58         if (status.MPI_SOURCE == 0) {
59           MPI_Recv (&i, 1, MPI_INT, 
60                     MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
61           if (status.MPI_SOURCE != 0)
62             printf ("(%d) Type mismatch from matching other message\n", rank);
63         }
64         else {
65           MPI_Recv (&x, 1, MPI_DOUBLE, 
66                     MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
67           if (status.MPI_SOURCE == 0)
68             printf ("(%d) Type mismatch from matching other message\n", rank);
69         }
70       }
71     }
72       
73   MPI_Barrier (MPI_COMM_WORLD);
74
75   MPI_Finalize ();
76   printf ("(%d) Finished normally\n", rank);
77 }
78
79 /* EOF */