Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Ignore stdout/stderr of the umpire tests
[simgrid.git] / teshsuite / smpi / isp / umpire / probe-any_tag-types-can-mismatch.c
1 /* -*- Mode: C; -*- */
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... */
6
7
8 #include <stdio.h>
9 #include "mpi.h"
10
11
12 int
13 main (int argc, char **argv)
14 {
15   int nprocs = -1;
16   int rank = -1;
17   char processor_name[128];
18   int namelen = 128;
19   int i, j;
20   double x;
21   MPI_Status status;
22   MPI_Request req0, req1;
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_TAG, we are not guaranteed that the */
36   /* first recv matches the probed msg, thus types can mismatch... */
37   if (nprocs < 2)
38     {
39       printf ("not enough tasks\n");
40     }
41   else if (rank == 0)
42     {
43       i = 0;
44       x = 1.0;
45
46       MPI_Isend (&i, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &req0);
47
48       MPI_Isend (&x, 1, MPI_DOUBLE, 1, 1, MPI_COMM_WORLD, &req1);
49
50       MPI_Wait (&req1, &status);
51
52       MPI_Wait (&req0, &status);
53     }
54   else if (rank == 1) 
55     {
56       for (j = 0; j < 2; j++) {
57         MPI_Probe (0, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
58       
59         if (status.MPI_TAG == 0) {
60           MPI_Recv (&i, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
61
62           if (status.MPI_TAG != 0)
63             printf ("(%d) Type mismatch from matching other message\n", rank);
64         }
65         else {
66           MPI_Recv (&x, 1, MPI_DOUBLE, 0, 
67                     MPI_ANY_TAG, MPI_COMM_WORLD, &status);
68
69           if (status.MPI_TAG == 0)
70             printf ("(%d) Type mismatch from matching other message\n", rank);
71         }
72       }
73     }
74       
75   MPI_Barrier (MPI_COMM_WORLD);
76
77   MPI_Finalize ();
78   printf ("(%d) Finished normally\n", rank);
79 }
80
81 /* EOF */