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);
27 int free_fn(void *extra_state);
28 int free_fn(void *extra_state)
30 int *b = (int *) extra_state;
33 /* The value returned by the free function is the error code
34 * returned by the wait/test function */
38 int cancel_fn(void *extra_state, int complete);
39 int cancel_fn(void *extra_state, int complete)
45 * This is a very simple test of generalized requests. Normally, the
46 * MPI_Grequest_complete function would be called from another routine,
47 * often running in a separate thread. This simple code allows us to
48 * check that requests can be created, tested, and waited on in the
49 * case where the request is complete before the wait is called.
51 * Note that MPI did *not* define a routine that can be called within
52 * test or wait to advance the state of a generalized request.
53 * Most uses of generalized requests will need to use a separate thread.
55 int main(int argc, char *argv[])
62 MTest_Init(&argc, &argv);
64 MPI_Grequest_start(query_fn, free_fn, cancel_fn, NULL, &request);
66 MPI_Test(&request, &flag, &status);
69 fprintf(stderr, "Generalized request marked as complete\n");
72 MPI_Grequest_complete(request);
74 MPI_Wait(&request, &status);
77 MPI_Grequest_start(query_fn, free_fn, cancel_fn, &counter, &request);
78 MPI_Grequest_complete(request);
79 MPI_Wait(&request, MPI_STATUS_IGNORE);
83 fprintf(stderr, "Free routine not called, or not called with extra_data");