File: vprotocol_pessimist_wait.c

package info (click to toggle)
openmpi 5.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 202,312 kB
  • sloc: ansic: 612,441; makefile: 42,495; sh: 11,230; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,154; python: 1,856; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (170 lines) | stat: -rw-r--r-- 5,440 bytes parent folder | download | duplicates (2)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * Copyright (c) 2004-2007 The Trustees of the University of Tennessee.
 *                         All rights reserved.
 * Copyright (c) 2021      Cisco Systems, Inc.  All rights reserved
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "ompi_config.h"
#include "vprotocol_pessimist.h"
#include "vprotocol_pessimist_wait.h"


/* Helpers to prevent requests from being freed by the real wait/test */
static int vprotocol_pessimist_request_no_free(ompi_request_t **req) {
    return OMPI_SUCCESS;
}

#define PREPARE_REQUESTS_WITH_NO_FREE(count, requests) do { \
    for (typeof(count) i = 0; i < count; i++)     \
    { \
        if(requests[i] == MPI_REQUEST_NULL) continue; \
        requests[i]->req_free = vprotocol_pessimist_request_no_free; \
    } \
} while(0)


int mca_vprotocol_pessimist_test(ompi_request_t ** rptr, int *completed,
                                 ompi_status_public_t * status)
{
    int ret;
    int index;

    VPROTOCOL_PESSIMIST_DELIVERY_REPLAY(1, rptr, completed, &index, status);

    ret = mca_pml_v.host_request_fns.req_test(rptr, completed, status);
    if(completed)
        vprotocol_pessimist_delivery_log(*rptr);
    else
        vprotocol_pessimist_delivery_log(NULL);
    return ret;
}

int mca_vprotocol_pessimist_test_all(size_t count, ompi_request_t ** requests,
                                     int *completed,
                                     ompi_status_public_t * statuses)
{
    int ret;
    int index;

    /* /!\ this is not correct until I upgrade DELIVERY_REPLAY to manage several requests at once */
    VPROTOCOL_PESSIMIST_DELIVERY_REPLAY(1, requests, completed, &index, statuses);

    ret = mca_pml_v.host_request_fns.req_test_all(count, requests, completed,
                                                   statuses);
#if 0
/* This is not correct :/ */
    if(completed)
        vprotocol_pessimist_delivery_log(requests); /* /!\ need to make sure this is correct: what if first is request_null ? */
    else
        vprotocol_pessimist_delivery_log(NULL);
#endif
    return ret;
}


/* TESTANY and WAITANY */

int mca_vprotocol_pessimist_test_any(size_t count, ompi_request_t ** requests,
                                     int *index, int *completed,
                                     ompi_status_public_t * status)
{
    int ret;

    VPROTOCOL_PESSIMIST_DELIVERY_REPLAY(count, requests, completed, index, status);

    PREPARE_REQUESTS_WITH_NO_FREE(count, requests);

    /* Call the real one to do the job */
    ret = mca_pml_v.host_request_fns.req_test_any(count, requests, index, completed,
                                                  status);

    if(completed)
    {   /* Parse the result */
        for(size_t i = 0; i < count; i++)
        {
            ompi_request_t *req = requests[i];
            if(req == MPI_REQUEST_NULL) continue;

            /* Restore requests and store they've been delivered */
            req->req_free = mca_vprotocol_pessimist_request_free;
            if(i == (size_t) *index)
            {
                vprotocol_pessimist_delivery_log(req);
                /* only free request without error status */
                if(req->req_status.MPI_ERROR == MPI_SUCCESS)
                    ompi_request_free(&(requests[i]));
                else
                    ret = req->req_status.MPI_ERROR;
            }
        }
    }
    else
    {
        /* No request delivered this time, log it */
        vprotocol_pessimist_delivery_log(NULL);
    }
    return ret;
}

int mca_vprotocol_pessimist_wait_any(size_t count, ompi_request_t ** requests,
                                     int *index, ompi_status_public_t * status)
{
    int ret;
    int dummy;

    VPROTOCOL_PESSIMIST_DELIVERY_REPLAY(count, requests, &dummy, index, status);

    PREPARE_REQUESTS_WITH_NO_FREE(count, requests);

    /* Call the real one to do the job */
    ret = mca_pml_v.host_request_fns.req_wait_any(count, requests, index, status);

    /* Parse the result */
    for(size_t i = 0; i < count; i++)
    {
        ompi_request_t *req = requests[i];
        if(req == MPI_REQUEST_NULL) continue;

        /* Restore requests and store they've been delivered */
        req->req_free = mca_vprotocol_pessimist_request_free;
        if(i == (size_t) *index)
        {
            vprotocol_pessimist_delivery_log(req);
            /* only free request without error status */
            if(req->req_status.MPI_ERROR == MPI_SUCCESS)
                ompi_request_free(&(requests[i]));
            else
                ret = req->req_status.MPI_ERROR;
        }
    }
    return ret;
}


/* TESTSOME and WAITSOME */

int mca_vprotocol_pessimist_test_some(size_t count, ompi_request_t ** requests,
                                      int * outcount, int * indices,
                                      ompi_status_public_t * statuses)
{
    int ret;
    ret = mca_vprotocol_pessimist_test_any(count, requests, indices, outcount, statuses);
    if(*outcount) *outcount = 1;
    return ret;
}

int mca_vprotocol_pessimist_wait_some(size_t count, ompi_request_t ** requests,
                                      int *outcount, int *indexes,
                                      ompi_status_public_t * statuses)
{
    int ret;
    ret = mca_vprotocol_pessimist_wait_any(count, requests, indexes, statuses);
    if(MPI_UNDEFINED == *indexes) *outcount = 0;
    else *outcount = 1;
    return ret;
}