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[] = "Simple test of generalized requests";
16 int query_fn( void *extra_state, MPI_Status *status );
17 int query_fn( void *extra_state, MPI_Status *status )
19 /* Set a default status */
20 status->MPI_SOURCE = MPI_UNDEFINED;
21 status->MPI_TAG = MPI_UNDEFINED;
22 MPI_Status_set_cancelled( status, 0 );
23 MPI_Status_set_elements( status, MPI_BYTE, 0 );
26 int free_fn( void *extra_state );
27 int free_fn( void *extra_state )
29 int *b = (int *)extra_state;
31 /* The value returned by the free function is the error code
32 returned by the wait/test function */
35 int cancel_fn( void *extra_state, int complete );
36 int cancel_fn( void *extra_state, int complete )
42 * This is a very simple test of generalized requests. Normally, the
43 * MPI_Grequest_complete function would be called from another routine,
44 * often running in a separate thread. This simple code allows us to
45 * check that requests can be created, tested, and waited on in the
46 * case where the request is complete before the wait is called.
48 * Note that MPI did *not* define a routine that can be called within
49 * test or wait to advance the state of a generalized request.
50 * Most uses of generalized requests will need to use a separate thread.
52 int main( int argc, char *argv[] )
59 MTest_Init( &argc, &argv );
61 MPI_Grequest_start( query_fn, free_fn, cancel_fn, NULL, &request );
63 MPI_Test( &request, &flag, &status );
66 fprintf( stderr, "Generalized request marked as complete\n" );
69 MPI_Grequest_complete( request );
71 MPI_Wait( &request, &status );
74 MPI_Grequest_start( query_fn, free_fn, cancel_fn, &counter, &request );
75 MPI_Grequest_complete( request );
76 MPI_Wait( &request, MPI_STATUS_IGNORE );
80 fprintf( stderr, "Free routine not called, or not called with extra_data" );
83 MTest_Finalize( errs );