1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
10 #define MAX_BUF_SIZE_LG 22
11 #define NUM_MSGS_PER_BUF_SIZE 5
12 char buf[1 << MAX_BUF_SIZE_LG];
15 * This program verifies that MPI_Probe() is operating properly in the face of
16 * unexpected messages arriving after MPI_Probe() has
17 * been called. This program may hang if MPI_Probe() does not return when the
18 * message finally arrives (see req #375).
20 int main(int argc, char **argv)
28 MTest_Init(&argc, &argv);
30 MPI_Comm_size(MPI_COMM_WORLD, &p_size);
31 MPI_Comm_rank(MPI_COMM_WORLD, &p_rank);
32 /* To improve reporting of problems about operations, we
33 change the error handler to errors return */
34 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
37 for (msg_size_lg = 0; msg_size_lg <= MAX_BUF_SIZE_LG; msg_size_lg++)
39 const int msg_size = 1 << msg_size_lg;
42 MTestPrintfMsg( 2, "testing messages of size %d\n", msg_size );
43 for (msg_cnt = 0; msg_cnt < NUM_MSGS_PER_BUF_SIZE; msg_cnt++)
46 const int tag = msg_size_lg * NUM_MSGS_PER_BUF_SIZE + msg_cnt;
48 MTestPrintfMsg( 2, "Message count %d\n", msg_cnt );
53 for (p = 1; p < p_size; p ++)
55 /* Wait for synchronization message */
56 mpi_errno = MPI_Recv(NULL, 0, MPI_BYTE, MPI_ANY_SOURCE,
57 tag, MPI_COMM_WORLD, &status);
58 if (mpi_errno != MPI_SUCCESS && errs++ < 10)
60 MTestPrintError(mpi_errno);
63 if (status.MPI_TAG != tag && errs++ < 10)
65 printf("ERROR: unexpected message tag from MPI_Recv(): lp=0, rp=%d, expected=%d, actual=%d, count=%d\n",
66 status.MPI_SOURCE, status.MPI_TAG, tag, msg_cnt);
71 printf("sending message: p=%d s=%d c=%d\n",
72 status.MPI_SOURCE, msg_size, msg_cnt);
76 /* Send unexpected message which hopefully MPI_Probe() is
77 already waiting for at the remote process */
78 mpi_errno = MPI_Send (buf, msg_size, MPI_BYTE,
79 status.MPI_SOURCE, status.MPI_TAG, MPI_COMM_WORLD);
80 if (mpi_errno != MPI_SUCCESS && errs++ < 10)
82 MTestPrintError(mpi_errno);
88 int incoming_msg_size;
90 /* Send synchronization message */
91 mpi_errno = MPI_Send(NULL, 0, MPI_BYTE, 0, tag, MPI_COMM_WORLD);
92 if (mpi_errno != MPI_SUCCESS && errs++ < 10)
94 MTestPrintError(mpi_errno);
97 /* Perform probe, hopefully before the master process can
99 mpi_errno = MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG,
100 MPI_COMM_WORLD, &status);
101 if (mpi_errno != MPI_SUCCESS && errs++ < 10)
103 MTestPrintError(mpi_errno);
105 mpi_errno = MPI_Get_count(&status, MPI_BYTE, &incoming_msg_size);
106 if (mpi_errno != MPI_SUCCESS && errs++ < 10)
108 MTestPrintError(mpi_errno);
110 if (status.MPI_SOURCE != 0 && errs++ < 10)
112 printf("ERROR: unexpected message source from MPI_Probe(): p=%d, expected=0, actual=%d, count=%d\n",
113 p_rank, status.MPI_SOURCE, msg_cnt);
115 if (status.MPI_TAG != tag && errs++ < 10)
117 printf("ERROR: unexpected message tag from MPI_Probe(): p=%d, expected=%d, actual=%d, count=%d\n",
118 p_rank, tag, status.MPI_TAG, msg_cnt);
120 if (incoming_msg_size != msg_size && errs++ < 10)
122 printf("ERROR: unexpected message size from MPI_Probe(): p=%d, expected=%d, actual=%d, count=%d\n",
123 p_rank, msg_size, incoming_msg_size, msg_cnt);
126 /* Receive the probed message from the master process */
127 mpi_errno = MPI_Recv(buf, msg_size, MPI_BYTE, 0, tag,
128 MPI_COMM_WORLD, &status);
129 if (mpi_errno != MPI_SUCCESS && errs++ < 10)
131 MTestPrintError(mpi_errno);
133 mpi_errno = MPI_Get_count(&status, MPI_BYTE, &incoming_msg_size);
134 if (mpi_errno != MPI_SUCCESS && errs++ < 10)
136 MTestPrintError(mpi_errno);
138 if (status.MPI_SOURCE != 0 && errs++ < 10)
140 printf("ERROR: unexpected message source from MPI_Recv(): p=%d, expected=0, actual=%d, count=%d\n",
141 p_rank, status.MPI_SOURCE, msg_cnt);
143 if (status.MPI_TAG != tag && errs++ < 10)
145 printf("ERROR: unexpected message tag from MPI_Recv(): p=%d, expected=%d, actual=%d, count=%d\n",
146 p_rank, tag, status.MPI_TAG, msg_cnt);
148 if (incoming_msg_size != msg_size && errs++ < 10)
150 printf("ERROR: unexpected message size from MPI_Recv(): p=%d, expected=%d, actual=%d, count=%d\n",
151 p_rank, msg_size, incoming_msg_size, msg_cnt);
157 MTest_Finalize( errs );