2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Wed Oct 30 2002 */
3 /* probe-any_tag-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... */
13 main (int argc, char **argv)
17 char processor_name[128];
22 MPI_Request req0, req1;
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_TAG, we are not guaranteed that the */
36 /* first recv matches the probed msg, thus types can mismatch... */
39 printf ("not enough tasks\n");
46 MPI_Isend (&i, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &req0);
48 MPI_Isend (&x, 1, MPI_DOUBLE, 1, 1, MPI_COMM_WORLD, &req1);
50 MPI_Wait (&req1, &status);
52 MPI_Wait (&req0, &status);
56 for (j = 0; j < 2; j++) {
57 MPI_Probe (0, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
59 if (status.MPI_TAG == 0) {
60 MPI_Recv (&i, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
62 if (status.MPI_TAG != 0)
63 printf ("(%d) Type mismatch from matching other message\n", rank);
66 MPI_Recv (&x, 1, MPI_DOUBLE, 0,
67 MPI_ANY_TAG, MPI_COMM_WORLD, &status);
69 if (status.MPI_TAG == 0)
70 printf ("(%d) Type mismatch from matching other message\n", rank);
75 MPI_Barrier (MPI_COMM_WORLD);
78 printf ("(%d) Finished normally\n", rank);