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... */
14 main (int argc, char **argv)
18 char processor_name[128];
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);
32 MPI_Barrier (MPI_COMM_WORLD);
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... */
39 printf ("not enough tasks\n");
45 MPI_Send (&i, 1, MPI_INT, 2, 0, MPI_COMM_WORLD);
51 MPI_Send (&x, 1, MPI_DOUBLE, 2, 0, MPI_COMM_WORLD);
55 for (j = 0; j < 2; j++) {
56 MPI_Probe (MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
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);
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);
73 MPI_Barrier (MPI_COMM_WORLD);
76 printf ("(%d) Finished normally\n", rank);