Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the compilation of MPICH3 tests with the absolute paranoid flags (enable_maintainer)
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / greq1.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Simple test of generalized requests";
13 */
14
15
16 int query_fn(void *extra_state, MPI_Status * status);
17 int query_fn(void *extra_state, MPI_Status * status)
18 {
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);
24     return 0;
25 }
26
27 int free_fn(void *extra_state);
28 int free_fn(void *extra_state)
29 {
30     int *b = (int *) extra_state;
31     if (b)
32         *b = *b - 1;
33     /* The value returned by the free function is the error code
34      * returned by the wait/test function */
35     return 0;
36 }
37
38 int cancel_fn(void *extra_state, int complete);
39 int cancel_fn(void *extra_state, int complete)
40 {
41     return 0;
42 }
43
44 /*
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.
50  *
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.
54  */
55 int main(int argc, char *argv[])
56 {
57     int errs = 0;
58     int counter, flag;
59     MPI_Status status;
60     MPI_Request request;
61
62     MTest_Init(&argc, &argv);
63
64     MPI_Grequest_start(query_fn, free_fn, cancel_fn, NULL, &request);
65
66     MPI_Test(&request, &flag, &status);
67     if (flag) {
68         errs++;
69         fprintf(stderr, "Generalized request marked as complete\n");
70     }
71
72     MPI_Grequest_complete(request);
73
74     MPI_Wait(&request, &status);
75
76     counter = 1;
77     MPI_Grequest_start(query_fn, free_fn, cancel_fn, &counter, &request);
78     MPI_Grequest_complete(request);
79     MPI_Wait(&request, MPI_STATUS_IGNORE);
80
81     if (counter) {
82         errs++;
83         fprintf(stderr, "Free routine not called, or not called with extra_data");
84     }
85
86     MTest_Finalize(errs);
87     MPI_Finalize();
88     return 0;
89 }