File: greq1.c

package info (click to toggle)
mpich 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 251,828 kB
  • sloc: ansic: 1,323,147; cpp: 82,869; f90: 72,420; javascript: 40,763; perl: 28,296; sh: 19,399; python: 16,191; xml: 14,418; makefile: 9,468; fortran: 8,046; java: 4,635; pascal: 352; asm: 324; ruby: 176; awk: 27; lisp: 19; php: 8; sed: 4
file content (87 lines) | stat: -rw-r--r-- 2,298 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "mpi.h"
#include <stdio.h>
#include "mpitest.h"

/*
static char MTEST_Descrip[] = "Simple test of generalized requests";
*/


int query_fn(void *extra_state, MPI_Status * status);
int query_fn(void *extra_state, MPI_Status * status)
{
    /* Set a default status */
    status->MPI_SOURCE = MPI_UNDEFINED;
    status->MPI_TAG = MPI_UNDEFINED;
    MPI_Status_set_cancelled(status, 0);
    MPI_Status_set_elements(status, MPI_BYTE, 0);
    return 0;
}

int free_fn(void *extra_state);
int free_fn(void *extra_state)
{
    int *b = (int *) extra_state;
    if (b)
        *b = *b - 1;
    /* The value returned by the free function is the error code
     * returned by the wait/test function */
    return 0;
}

int cancel_fn(void *extra_state, int complete);
int cancel_fn(void *extra_state, int complete)
{
    return 0;
}

/*
 * This is a very simple test of generalized requests.  Normally, the
 * MPI_Grequest_complete function would be called from another routine,
 * often running in a separate thread.  This simple code allows us to
 * check that requests can be created, tested, and waited on in the
 * case where the request is complete before the wait is called.
 *
 * Note that MPI did *not* define a routine that can be called within
 * test or wait to advance the state of a generalized request.
 * Most uses of generalized requests will need to use a separate thread.
 */
int main(int argc, char *argv[])
{
    int errs = 0;
    int counter, flag;
    MPI_Status status;
    MPI_Request request;

    MTest_Init(&argc, &argv);

    MPI_Grequest_start(query_fn, free_fn, cancel_fn, NULL, &request);

    MPI_Test(&request, &flag, &status);
    if (flag) {
        errs++;
        fprintf(stderr, "Generalized request marked as complete\n");
    }

    MPI_Grequest_complete(request);

    MPI_Wait(&request, &status);

    counter = 1;
    MPI_Grequest_start(query_fn, free_fn, cancel_fn, &counter, &request);
    MPI_Grequest_complete(request);
    MPI_Wait(&request, MPI_STATUS_IGNORE);

    if (counter) {
        errs++;
        fprintf(stderr, "Free routine not called, or not called with extra_data");
    }

    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}