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) ||
44 (status.MPI_ERROR != MPI_SUCCESS))
47 fprintf( stderr, "non-empty MPI_Status returned for MPI_REQUEST_NULL\n" );
50 /* also pass MPI_STATUS_IGNORE to make sure the implementation doesn't
51 * blow up when it is passed as the status argument */
52 MPI_Request_get_status( MPI_REQUEST_NULL, &flag, MPI_STATUS_IGNORE );
55 fprintf( stderr, "flag not true for MPI_REQUEST_NULL with MPI_STATUS_IGNORE, flag=%d\n", flag );
62 MPI_Ssend( buf, 2, MPI_INT, dest, 10, comm );
65 MPI_Irecv( buf, 2, MPI_INT, source, 10, comm, &req );
68 /* At this point, we know that the receive has at least started,
69 because of the Ssend. Check the status on the request */
71 status.MPI_SOURCE = -1;
73 MPI_Request_get_status( req, &flag, &status );
75 if (status.MPI_TAG != 10) {
77 fprintf( stderr, "Tag value %d should be 10\n", status.MPI_TAG );
79 if (status.MPI_SOURCE != source) {
81 fprintf( stderr, "Source value %d should be %d\n", status.MPI_SOURCE, source );
83 MPI_Get_count( &status, MPI_INT, &count );
86 fprintf( stderr, "Count value %d should be 2\n", count );
91 fprintf( stderr, "Unexpected flag value from get_status\n" );
93 /* Now, complete the request */
94 MPI_Wait( &req, &status2 );
95 /* Check that the status is correct */
96 if (status2.MPI_TAG != 10) {
98 fprintf( stderr, "(wait)Tag value %d should be 10\n", status2.MPI_TAG );
100 if (status2.MPI_SOURCE != source) {
102 fprintf( stderr, "(wait)Source value %d should be %d\n", status2.MPI_SOURCE, source );
104 MPI_Get_count( &status2, MPI_INT, &count );
107 fprintf( stderr, "(wait)Count value %d should be 2\n", count );
111 MTest_Finalize( errs );