File: greq_wait.c

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 423,384 kB
  • sloc: ansic: 1,088,434; cpp: 71,364; javascript: 40,763; f90: 22,829; sh: 17,463; perl: 14,773; xml: 14,418; python: 10,265; makefile: 9,246; fortran: 8,008; java: 4,355; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (113 lines) | stat: -rw-r--r-- 2,770 bytes parent folder | download | duplicates (4)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

/* Based on test code provided by Lisandro DalcĂ­. */
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include "mpithreadtest.h"
#include "mpitest.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

/*
static char MTEST_Descrip[] = "threaded generalized request tests";
*/

#define IF_VERBOSE(a) \
do { \
    if (verbose) { \
        printf a ; \
        fflush(stdout); \
    } \
} while (0)

static int verbose = 0;

int query_fn(void *extra_state, MPI_Status * status);
int query_fn(void *extra_state, MPI_Status * 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)
{
    return 0;
}

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


MPI_Request grequest;

MTEST_THREAD_RETURN_TYPE do_work(void *arg);
MTEST_THREAD_RETURN_TYPE do_work(void *arg)
{
    MPI_Request *req = (MPI_Request *) arg;
    IF_VERBOSE(("Starting work in thread ...\n"));
    MTestSleep(3);
    IF_VERBOSE(("Work in thread done !!!\n"));
    MPI_Grequest_complete(*req);
    return MTEST_THREAD_RETVAL_IGN;
}

int main(int argc, char *argv[])
{
    int provided;
    MPI_Request request;
    int outcount = -1;
    int indices[1] = { -1 };
    MPI_Status status;
    char *env;

    env = getenv("MPITEST_VERBOSE");
    if (env) {
        if (*env != '0')
            verbose = 1;
    }

    MTest_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
    if (provided != MPI_THREAD_MULTIPLE) {
        printf("This test requires MPI_THREAD_MULTIPLE\n");
        MPI_Abort(MPI_COMM_WORLD, 1);
    }

    IF_VERBOSE(("Post Init ...\n"));

    MPI_Grequest_start(query_fn, free_fn, cancel_fn, NULL, &request);
    grequest = request; /* copy the handle */
    MTest_Start_thread(do_work, &grequest);
    IF_VERBOSE(("Waiting ...\n"));
    MPI_Wait(&request, &status);
    MTest_Join_threads();

    MPI_Grequest_start(query_fn, free_fn, cancel_fn, NULL, &request);
    grequest = request; /* copy the handle */
    MTest_Start_thread(do_work, &grequest);
    IF_VERBOSE(("Waiting ...\n"));
    MPI_Waitsome(1, &request, &outcount, indices, &status);
    MTest_Join_threads();

    MPI_Grequest_start(query_fn, free_fn, cancel_fn, NULL, &request);
    grequest = request; /* copy the handle */
    MTest_Start_thread(do_work, &grequest);
    IF_VERBOSE(("Waiting ...\n"));
    MPI_Waitall(1, &request, &status);
    MTest_Join_threads();

    IF_VERBOSE(("Goodbye !!!\n"));
    MTest_Finalize(0);
    return 0;
}