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++) {
38 const int msg_size = 1 << msg_size_lg;
41 MTestPrintfMsg(2, "testing messages of size %d\n", msg_size);
42 for (msg_cnt = 0; msg_cnt < NUM_MSGS_PER_BUF_SIZE; msg_cnt++) {
44 const int tag = msg_size_lg * NUM_MSGS_PER_BUF_SIZE + msg_cnt;
46 MTestPrintfMsg(2, "Message count %d\n", msg_cnt);
50 for (p = 1; p < p_size; p++) {
51 /* Wait for synchronization message */
52 mpi_errno = MPI_Recv(NULL, 0, MPI_BYTE, MPI_ANY_SOURCE,
53 tag, MPI_COMM_WORLD, &status);
54 if (mpi_errno != MPI_SUCCESS && errs++ < 10) {
55 MTestPrintError(mpi_errno);
58 if (status.MPI_TAG != tag && errs++ < 10) {
60 ("ERROR: unexpected message tag from MPI_Recv(): lp=0, rp=%d, expected=%d, actual=%d, count=%d\n",
61 status.MPI_SOURCE, status.MPI_TAG, tag, msg_cnt);
66 printf("sending message: p=%d s=%d c=%d\n",
67 status.MPI_SOURCE, msg_size, msg_cnt);
71 /* Send unexpected message which hopefully MPI_Probe() is
72 * already waiting for at the remote process */
73 mpi_errno = MPI_Send(buf, msg_size, MPI_BYTE,
74 status.MPI_SOURCE, status.MPI_TAG, MPI_COMM_WORLD);
75 if (mpi_errno != MPI_SUCCESS && errs++ < 10) {
76 MTestPrintError(mpi_errno);
81 int incoming_msg_size;
83 /* Send synchronization message */
84 mpi_errno = MPI_Send(NULL, 0, MPI_BYTE, 0, tag, MPI_COMM_WORLD);
85 if (mpi_errno != MPI_SUCCESS && errs++ < 10) {
86 MTestPrintError(mpi_errno);
89 /* Perform probe, hopefully before the master process can
91 mpi_errno = MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
92 if (mpi_errno != MPI_SUCCESS && errs++ < 10) {
93 MTestPrintError(mpi_errno);
95 mpi_errno = MPI_Get_count(&status, MPI_BYTE, &incoming_msg_size);
96 if (mpi_errno != MPI_SUCCESS && errs++ < 10) {
97 MTestPrintError(mpi_errno);
99 if (status.MPI_SOURCE != 0 && errs++ < 10) {
101 ("ERROR: unexpected message source from MPI_Probe(): p=%d, expected=0, actual=%d, count=%d\n",
102 p_rank, status.MPI_SOURCE, msg_cnt);
104 if (status.MPI_TAG != tag && errs++ < 10) {
106 ("ERROR: unexpected message tag from MPI_Probe(): p=%d, expected=%d, actual=%d, count=%d\n",
107 p_rank, tag, status.MPI_TAG, msg_cnt);
109 if (incoming_msg_size != msg_size && errs++ < 10) {
111 ("ERROR: unexpected message size from MPI_Probe(): p=%d, expected=%d, actual=%d, count=%d\n",
112 p_rank, msg_size, incoming_msg_size, msg_cnt);
115 /* Receive the probed message from the master process */
116 mpi_errno = MPI_Recv(buf, msg_size, MPI_BYTE, 0, tag, MPI_COMM_WORLD, &status);
117 if (mpi_errno != MPI_SUCCESS && errs++ < 10) {
118 MTestPrintError(mpi_errno);
120 mpi_errno = MPI_Get_count(&status, MPI_BYTE, &incoming_msg_size);
121 if (mpi_errno != MPI_SUCCESS && errs++ < 10) {
122 MTestPrintError(mpi_errno);
124 if (status.MPI_SOURCE != 0 && errs++ < 10) {
126 ("ERROR: unexpected message source from MPI_Recv(): p=%d, expected=0, actual=%d, count=%d\n",
127 p_rank, status.MPI_SOURCE, msg_cnt);
129 if (status.MPI_TAG != tag && errs++ < 10) {
131 ("ERROR: unexpected message tag from MPI_Recv(): p=%d, expected=%d, actual=%d, count=%d\n",
132 p_rank, tag, status.MPI_TAG, msg_cnt);
134 if (incoming_msg_size != msg_size && errs++ < 10) {
136 ("ERROR: unexpected message size from MPI_Recv(): p=%d, expected=%d, actual=%d, count=%d\n",
137 p_rank, msg_size, incoming_msg_size, msg_cnt);
143 MTest_Finalize(errs);