1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
12 static char MTEST_Descrip[] = "Test Request_get_status";
15 int main(int argc, char *argv[])
18 int rank, size, source, dest;
19 int buf[2], flag, count;
21 MPI_Status status, status2;
24 MTest_Init(&argc, &argv);
26 comm = MPI_COMM_WORLD;
27 /* Determine the sender and receiver */
28 MPI_Comm_rank(comm, &rank);
29 MPI_Comm_size(comm, &size);
34 /* Handling MPI_REQUEST_NULL in MPI_Request_get_status was only required
35 * starting with MPI-2.2. */
36 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
37 MPI_Request_get_status(MPI_REQUEST_NULL, &flag, &status);
40 fprintf(stderr, "flag not true for MPI_REQUEST_NULL, flag=%d\n", flag);
42 if ((status.MPI_SOURCE != MPI_ANY_SOURCE) ||
43 (status.MPI_TAG != MPI_ANY_TAG) || (status.MPI_ERROR != MPI_SUCCESS)) {
45 fprintf(stderr, "non-empty MPI_Status returned for MPI_REQUEST_NULL\n");
48 /* also pass MPI_STATUS_IGNORE to make sure the implementation doesn't
49 * blow up when it is passed as the status argument */
50 MPI_Request_get_status(MPI_REQUEST_NULL, &flag, MPI_STATUS_IGNORE);
53 fprintf(stderr, "flag not true for MPI_REQUEST_NULL with MPI_STATUS_IGNORE, flag=%d\n",
61 MPI_Ssend(buf, 2, MPI_INT, dest, 10, comm);
64 MPI_Irecv(buf, 2, MPI_INT, source, 10, comm, &req);
67 /* At this point, we know that the receive has at least started,
68 * because of the Ssend. Check the status on the request */
70 status.MPI_SOURCE = -1;
72 MPI_Request_get_status(req, &flag, &status);
74 if (status.MPI_TAG != 10) {
76 fprintf(stderr, "Tag value %d should be 10\n", status.MPI_TAG);
78 if (status.MPI_SOURCE != source) {
80 fprintf(stderr, "Source value %d should be %d\n", status.MPI_SOURCE, source);
82 MPI_Get_count(&status, MPI_INT, &count);
85 fprintf(stderr, "Count value %d should be 2\n", count);
90 fprintf(stderr, "Unexpected flag value from get_status\n");
92 /* Now, complete the request */
93 MPI_Wait(&req, &status2);
94 /* Check that the status is correct */
95 if (status2.MPI_TAG != 10) {
97 fprintf(stderr, "(wait)Tag value %d should be 10\n", status2.MPI_TAG);
99 if (status2.MPI_SOURCE != source) {
101 fprintf(stderr, "(wait)Source value %d should be %d\n", status2.MPI_SOURCE, source);
103 MPI_Get_count(&status2, MPI_INT, &count);
106 fprintf(stderr, "(wait)Count value %d should be 2\n", count);
110 MTest_Finalize(errs);