File: request.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 (274 lines) | stat: -rw-r--r-- 10,416 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2017 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2006-2013 Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2009      Sun Microsystems, Inc.  All rights reserved.
 * Copyright (c) 2012      Oak Ridge National Labs.  All rights reserved.
 * Copyright (c) 2015      Los Alamos National Security, LLC.  All rights
 *                         reserved.
 * Copyright (c) 2015      Research Organization for Information Science
 *                         and Technology (RIST). All rights reserved.
 * Copyright (c) 2018      FUJITSU LIMITED.  All rights reserved.
 * Copyright (c) 2018      Triad National Security, LLC. All rights
 *                         reserved.
 * Copyright (c) 2022      IBM Corporation.  All rights reserved.
 * Copyright (c) 2024      NVIDIA Corporation.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "ompi_config.h"

#include "ompi/communicator/communicator.h"
#include "opal/class/opal_object.h"
#include "ompi/request/request.h"
#include "ompi/request/request_default.h"
#include "ompi/constants.h"
#if MPI_VERSION >= 4
#include "ompi/mca/pml/base/pml_base_sendreq.h"
#endif

opal_pointer_array_t             ompi_request_f_to_c_table = {{0}};
ompi_predefined_request_t        ompi_request_null = {{{{{0}}}}};
ompi_predefined_request_t        *ompi_request_null_addr = &ompi_request_null;
ompi_request_t                   ompi_request_empty = {{{{0}}}};
#if MPI_VERSION >= 4
ompi_request_t                   ompi_request_empty_send = {{{{0}}}};
#endif
ompi_status_public_t             ompi_status_empty = {0};
ompi_request_fns_t               ompi_request_functions = {
    ompi_request_default_test,
    ompi_request_default_test_any,
    ompi_request_default_test_all,
    ompi_request_default_test_some,
    ompi_request_default_wait,
    ompi_request_default_wait_any,
    ompi_request_default_wait_all,
    ompi_request_default_wait_some
};

static void ompi_request_construct(ompi_request_t* req)
{
    /* don't call _INIT, we don't to set the request to _INACTIVE and there will
     * be no matching _FINI invocation */
    req->req_state        = OMPI_REQUEST_INVALID;
    req->req_complete     = REQUEST_COMPLETED;
    req->req_persistent   = false;
    req->req_start        = NULL;
    req->req_free         = NULL;
    req->req_cancel       = NULL;
    req->req_complete_cb  = NULL;
    req->req_complete_cb_data = NULL;
    req->req_f_to_c_index = MPI_UNDEFINED;
    req->req_mpi_object.comm = (struct ompi_communicator_t*) NULL;
}

static void ompi_request_destruct(ompi_request_t* req)
{
    assert( MPI_UNDEFINED == req->req_f_to_c_index );
    assert( OMPI_REQUEST_INVALID == req->req_state );
}

static int ompi_request_null_free(ompi_request_t** request)
{
    return OMPI_SUCCESS;
}

static int ompi_request_null_cancel(ompi_request_t* request, int flag)
{
    return OMPI_SUCCESS;
}

static int ompi_request_empty_free(ompi_request_t** request)
{
    *request = &ompi_request_null.request;
    return OMPI_SUCCESS;
}

static int ompi_request_persistent_noop_free(ompi_request_t** request)
{
    OMPI_REQUEST_FINI(*request);
    (*request)->req_state = OMPI_REQUEST_INVALID;
    OBJ_RELEASE(*request);
    *request = &ompi_request_null.request;
    return OMPI_SUCCESS;
}


OBJ_CLASS_INSTANCE(
    ompi_request_t,
    opal_free_list_item_t,
    ompi_request_construct,
    ompi_request_destruct);


static int ompi_request_finalize (void)
{
    OMPI_REQUEST_FINI( &ompi_request_null.request );
    OBJ_DESTRUCT( &ompi_request_null.request );
    OMPI_REQUEST_FINI( &ompi_request_empty );
    OBJ_DESTRUCT( &ompi_request_empty );
    OBJ_DESTRUCT( &ompi_request_f_to_c_table );
    return OMPI_SUCCESS;
}

int ompi_request_init(void)
{

    OBJ_CONSTRUCT(&ompi_request_null, ompi_request_t);
    OBJ_CONSTRUCT(&ompi_request_f_to_c_table, opal_pointer_array_t);
    if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_request_f_to_c_table,
                                                0, OMPI_FORTRAN_HANDLE_MAX, 32) ) {
        return OMPI_ERROR;
    }
    ompi_request_null.request.req_type = OMPI_REQUEST_NULL;
    ompi_request_null.request.req_status.MPI_SOURCE = MPI_ANY_SOURCE;
    ompi_request_null.request.req_status.MPI_TAG = MPI_ANY_TAG;
    ompi_request_null.request.req_status.MPI_ERROR = MPI_SUCCESS;
    ompi_request_null.request.req_status._ucount = 0;
    ompi_request_null.request.req_status._cancelled = 0;

    ompi_request_null.request.req_complete = REQUEST_COMPLETED;
    ompi_request_null.request.req_state = OMPI_REQUEST_INACTIVE;
    ompi_request_null.request.req_persistent = false;
    ompi_request_null.request.req_f_to_c_index =
        opal_pointer_array_add(&ompi_request_f_to_c_table, &ompi_request_null);
    ompi_request_null.request.req_start = NULL; /* should not be called */
    ompi_request_null.request.req_free = ompi_request_null_free;
    ompi_request_null.request.req_cancel = ompi_request_null_cancel;
    ompi_request_null.request.req_mpi_object.comm = &ompi_mpi_comm_world.comm;

    if (0 != ompi_request_null.request.req_f_to_c_index) {
        return OMPI_ERR_REQUEST;
    }

    /* We need a way to distinguish between the user provided
     * MPI_REQUEST_NULL to MPI_Wait* and a non-active (MPI_PROC_NULL)
     * request passed to any P2P non-blocking function.
     *
     * The main difference to ompi_request_null is
     * req_state being OMPI_REQUEST_ACTIVE, so that MPI_Waitall
     * does not set the status to ompi_status_empty and the different
     * req_free function, which resets the
     * request to MPI_REQUEST_NULL.
     * The req_cancel function need not be changed.
     */
    OBJ_CONSTRUCT(&ompi_request_empty, ompi_request_t);
    ompi_request_empty.req_type = OMPI_REQUEST_NULL;
    ompi_request_empty.req_status.MPI_SOURCE = MPI_PROC_NULL;
    ompi_request_empty.req_status.MPI_TAG = MPI_ANY_TAG;
    ompi_request_empty.req_status.MPI_ERROR = MPI_SUCCESS;
    ompi_request_empty.req_status._ucount = 0;
    ompi_request_empty.req_status._cancelled = 0;

    ompi_request_empty.req_complete = REQUEST_COMPLETED;
    ompi_request_empty.req_state = OMPI_REQUEST_ACTIVE;
    ompi_request_empty.req_persistent = false;
    ompi_request_empty.req_f_to_c_index =
        opal_pointer_array_add(&ompi_request_f_to_c_table, &ompi_request_empty);
    ompi_request_empty.req_start = NULL; /* should not be called */
    ompi_request_empty.req_free = ompi_request_empty_free;
    ompi_request_empty.req_cancel = ompi_request_null_cancel;
    ompi_request_empty.req_mpi_object.comm = &ompi_mpi_comm_world.comm;

    if (1 != ompi_request_empty.req_f_to_c_index) {
        return OMPI_ERR_REQUEST;
    }

#if MPI_VERSION >= 4
    /*
     * This is a copy of the ompi_request_empty object where the only difference
     * is that the req_cancel callback is set to a callback which issues a
     * message that calling MPI_Cancel on a non-blocking send request is
     * deprecated.
     */
    OBJ_CONSTRUCT(&ompi_request_empty_send, ompi_request_t);
    ompi_request_empty_send.req_type = OMPI_REQUEST_NULL;
    ompi_request_empty_send.req_status.MPI_SOURCE = MPI_PROC_NULL;
    ompi_request_empty_send.req_status.MPI_TAG = MPI_ANY_TAG;
    ompi_request_empty_send.req_status.MPI_ERROR = MPI_SUCCESS;
    ompi_request_empty_send.req_status._ucount = 0;
    ompi_request_empty_send.req_status._cancelled = 0;

    ompi_request_empty_send.req_complete = REQUEST_COMPLETED;
    ompi_request_empty_send.req_state = OMPI_REQUEST_ACTIVE;
    ompi_request_empty_send.req_persistent = false;
    ompi_request_empty_send.req_f_to_c_index =
        opal_pointer_array_add(&ompi_request_f_to_c_table, &ompi_request_empty_send);
    ompi_request_empty_send.req_start = NULL; /* should not be called */
    ompi_request_empty_send.req_free = ompi_request_empty_free;
    ompi_request_empty_send.req_cancel = mca_pml_cancel_send_callback;
    ompi_request_empty_send.req_mpi_object.comm = &ompi_mpi_comm_world.comm;

    if (2 != ompi_request_empty_send.req_f_to_c_index) {
        return OMPI_ERR_REQUEST;
    }
#endif

    ompi_status_empty.MPI_SOURCE = MPI_ANY_SOURCE;
    ompi_status_empty.MPI_TAG = MPI_ANY_TAG;
    ompi_status_empty.MPI_ERROR = MPI_SUCCESS;
    ompi_status_empty._ucount = 0;
    ompi_status_empty._cancelled = 0;

    ompi_mpi_instance_append_finalize (ompi_request_finalize);

    return OMPI_SUCCESS;
}

int ompi_request_persistent_noop_create(ompi_request_t** request)
{
    ompi_request_t *req;

    req = OBJ_NEW(ompi_request_t);
    if (NULL == req) {
        return OMPI_ERR_OUT_OF_RESOURCE;
    }

    /* Other fields were initialized by the constructor for
       ompi_request_t */
    req->req_type = OMPI_REQUEST_NOOP;
    req->req_status = ompi_request_empty.req_status;
    req->req_complete = REQUEST_COMPLETED;
    req->req_state = OMPI_REQUEST_INACTIVE;
    req->req_persistent = true;
    req->req_free = ompi_request_persistent_noop_free;

    *request = req;
    return OMPI_SUCCESS;
}

bool ompi_request_check_same_instance(ompi_request_t** requests,
                                      int count)
{
    ompi_instance_t* base_instance = NULL;
    ompi_request_t *req;

    for(int idx = 0; idx < count; idx++ ) {
        req = requests[idx];
        if(OMPI_REQUEST_NULL == req->req_type)  /* predefined requests are generic */
            continue;
        /* Only PML requests have support for MPI sessions */
        if(OMPI_REQUEST_PML != req->req_type)
            continue;
        if(NULL == base_instance) {
            base_instance = req->req_mpi_object.comm->instance;
            continue;
        }
        if(base_instance != req->req_mpi_object.comm->instance)
            return false;
    }
    return true;
}