File: pml_ob1_irecv.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 (379 lines) | stat: -rw-r--r-- 14,549 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/* -*- 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-2021 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 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) 2007-2016 Los Alamos National Security, LLC.  All rights
 *                         reserved.
 * Copyright (c) 2010-2012 Oracle and/or its affiliates.  All rights reserved.
 * Copyright (c) 2011      Sandia National Laboratories. All rights reserved.
 * Copyright (c) 2012      Oak Ridge National Labs.  All rights reserved.
 * Copyright (c) 2014      Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2016-2017 Research Organization for Information Science
 *                         and Technology (RIST). All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "ompi_config.h"
#include "ompi/request/request.h"
#include "pml_ob1_recvreq.h"
#include "pml_ob1_recvfrag.h"
#include "ompi/peruse/peruse-internal.h"
#include "ompi/message/message.h"
#include "ompi/memchecker.h"

/**
 * Single usage request. As we allow recursive calls to recv
 * (from the request completion callback), we cannot rely on
 * using a global request. Thus, once a recv acquires ownership
 * this global request, it should set it to NULL to prevent
 * the reuse until the first user completes.
 */
mca_pml_ob1_recv_request_t *mca_pml_ob1_recvreq = NULL;

int mca_pml_ob1_irecv_init(void *addr,
                           size_t count,
                           ompi_datatype_t * datatype,
                           int src,
                           int tag,
                           struct ompi_communicator_t *comm,
                           struct ompi_request_t **request)
{
    mca_pml_ob1_recv_request_t *recvreq;
    MCA_PML_OB1_RECV_REQUEST_ALLOC(recvreq);
    if (NULL == recvreq)
        return OMPI_ERR_TEMP_OUT_OF_RESOURCE;

    recvreq->req_recv.req_base.req_type = MCA_PML_REQUEST_RECV;
    MCA_PML_OB1_RECV_REQUEST_INIT(recvreq,
                                   addr,
                                   count, datatype, src, tag, comm, true);

    PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE,
                             &((recvreq)->req_recv.req_base),
                             PERUSE_RECV);

    /* Work around a leak in start by marking this request as complete. The
     * problem occurred because we do not have a way to differentiate an
     * initial request and an incomplete pml request in start. This line
     * allows us to detect this state. */
    recvreq->req_recv.req_base.req_pml_complete = true;

    *request = (ompi_request_t *) recvreq;
    return OMPI_SUCCESS;
}

int mca_pml_ob1_irecv(void *addr,
                      size_t count,
                      ompi_datatype_t * datatype,
                      int src,
                      int tag,
                      struct ompi_communicator_t *comm,
                      struct ompi_request_t **request)
{
    mca_pml_ob1_recv_request_t *recvreq;
    MCA_PML_OB1_RECV_REQUEST_ALLOC(recvreq);
    if (NULL == recvreq)
        return OMPI_ERR_TEMP_OUT_OF_RESOURCE;

    recvreq->req_recv.req_base.req_type = MCA_PML_REQUEST_RECV;
    MCA_PML_OB1_RECV_REQUEST_INIT(recvreq,
                                   addr,
                                   count, datatype, src, tag, comm, false);

    PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE,
                             &((recvreq)->req_recv.req_base),
                             PERUSE_RECV);

    MCA_PML_OB1_RECV_REQUEST_START(recvreq);
    *request = (ompi_request_t *) recvreq;
    return OMPI_SUCCESS;
}


int mca_pml_ob1_recv(void *addr,
                     size_t count,
                     ompi_datatype_t * datatype,
                     int src,
                     int tag,
                     struct ompi_communicator_t *comm,
                     ompi_status_public_t * status)
{
    mca_pml_ob1_recv_request_t *recvreq = NULL;
    int rc;

    if (OPAL_LIKELY(!ompi_mpi_thread_multiple)) {
        recvreq = mca_pml_ob1_recvreq;
        mca_pml_ob1_recvreq = NULL;
    }

    if( OPAL_UNLIKELY(NULL == recvreq) ) {
        MCA_PML_OB1_RECV_REQUEST_ALLOC(recvreq);
        if (NULL == recvreq)
            return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
    }

    recvreq->req_recv.req_base.req_type = MCA_PML_REQUEST_RECV;
    MCA_PML_OB1_RECV_REQUEST_INIT(recvreq, addr, count, datatype,
                                  src, tag, comm, false);

    PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE,
                             &(recvreq->req_recv.req_base),
                             PERUSE_RECV);

    MCA_PML_OB1_RECV_REQUEST_START(recvreq);
    ompi_request_wait_completion(&recvreq->req_recv.req_base.req_ompi);

    if (recvreq->req_recv.req_base.req_pml_complete) {
        /* make buffer defined when the request is completed */
        MEMCHECKER(
            memchecker_call(&opal_memchecker_base_mem_defined,
                            recvreq->req_recv.req_base.req_addr,
                            recvreq->req_recv.req_base.req_count,
                            recvreq->req_recv.req_base.req_datatype);
        );
    }

    if (MPI_STATUS_IGNORE != status) {
        OMPI_COPY_STATUS(status, recvreq->req_recv.req_base.req_ompi.req_status, false);
    }

    rc = recvreq->req_recv.req_base.req_ompi.req_status.MPI_ERROR;
#if OPAL_ENABLE_FT_MPI
    if( OPAL_UNLIKELY( MPI_ERR_PROC_FAILED_PENDING == rc )) {
        ompi_request_cancel(&recvreq->req_recv.req_base.req_ompi);
        ompi_request_wait_completion(&recvreq->req_recv.req_base.req_ompi);
        rc = MPI_ERR_PROC_FAILED;
    }
#endif

    if (recvreq->req_recv.req_base.req_pml_complete) {
        /* make buffer defined when the request is completed,
           and before releasing the objects. */
        MEMCHECKER(
            memchecker_call(&opal_memchecker_base_mem_defined,
                            recvreq->req_recv.req_base.req_addr,
                            recvreq->req_recv.req_base.req_count,
                            recvreq->req_recv.req_base.req_datatype);
        );
    }

    if (OPAL_UNLIKELY(ompi_mpi_thread_multiple || NULL != mca_pml_ob1_recvreq)) {
        MCA_PML_OB1_RECV_REQUEST_RETURN(recvreq);
    } else {
        mca_pml_ob1_recv_request_fini (recvreq);
        mca_pml_ob1_recvreq = recvreq;
    }

    return rc;
}


int
mca_pml_ob1_imrecv( void *buf,
                    size_t count,
                    ompi_datatype_t *datatype,
                    struct ompi_message_t **message,
                    struct ompi_request_t **request )
{
    mca_pml_ob1_recv_frag_t* frag;
    mca_pml_ob1_recv_request_t *recvreq;
    mca_pml_ob1_hdr_t *hdr;
    int src, tag;
    ompi_communicator_t *comm;
    mca_pml_ob1_comm_proc_t* proc;
    uint64_t seq;

    /* get the request from the message and the frag from the request
       before we overwrite everything */
    recvreq = (mca_pml_ob1_recv_request_t*) (*message)->req_ptr;
    frag = (mca_pml_ob1_recv_frag_t*) recvreq->req_recv.req_base.req_addr;
    src = recvreq->req_recv.req_base.req_ompi.req_status.MPI_SOURCE;
    tag = recvreq->req_recv.req_base.req_ompi.req_status.MPI_TAG;
    comm = (*message)->comm;
    seq = recvreq->req_recv.req_base.req_sequence;

    /* make the request a recv request again */
    /* The old request kept pointers to comm and the char datatype.
       We're about to release those, but need to make sure comm
       doesn't go out of scope (we don't care about the char datatype
       anymore).  So retain comm, then release the frag, then reinit
       the frag (which will retain comm), then release comm (but the
       frag still has it's ref, so it'll stay in scope).  Make
       sense? */
    OBJ_RETAIN(comm);
    MCA_PML_BASE_RECV_REQUEST_FINI(&recvreq->req_recv);
    recvreq->req_recv.req_base.req_type = MCA_PML_REQUEST_RECV;
    MCA_PML_OB1_RECV_REQUEST_INIT(recvreq,
                                  buf,
                                  count, datatype,
                                  src, tag, comm, false);
    OBJ_RELEASE(comm);

    PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE,
                             &((recvreq)->req_recv.req_base),
                             PERUSE_RECV);

    /* init/re-init the request */
    recvreq->req_lock = 0;
    recvreq->req_pipeline_depth  = 0;
    recvreq->req_bytes_received  = 0;
    /* What about req_rdma_cnt ? */
    recvreq->req_rdma_idx = 0;
    recvreq->req_pending = false;
    recvreq->req_ack_sent = false;

    MCA_PML_BASE_RECV_START(&recvreq->req_recv);

    /* Note - sequence number already assigned */
    recvreq->req_recv.req_base.req_sequence = seq;

    proc = mca_pml_ob1_peer_lookup (comm, recvreq->req_recv.req_base.req_peer);
    recvreq->req_recv.req_base.req_proc = proc->ompi_proc;
    prepare_recv_req_converter(recvreq);

    /* we can't go through the match, since we already have the match.
       Cheat and do what REQUEST_START does, but without the frag
       search */
    hdr = (mca_pml_ob1_hdr_t*)frag->segments->seg_addr.pval;
    switch(hdr->hdr_common.hdr_type) {
    case MCA_PML_OB1_HDR_TYPE_MATCH:
        mca_pml_ob1_recv_request_progress_match(recvreq, frag->btl, frag->segments,
                                                frag->num_segments);
        break;
    case MCA_PML_OB1_HDR_TYPE_RNDV:
        mca_pml_ob1_recv_request_progress_rndv(recvreq, frag->btl, frag->segments,
                                               frag->num_segments);
        break;
    case MCA_PML_OB1_HDR_TYPE_RGET:
        mca_pml_ob1_recv_request_progress_rget(recvreq, frag->btl, frag->segments,
                                               frag->num_segments);
        break;
    default:
        assert(0);
    }
    MCA_PML_OB1_RECV_FRAG_RETURN(frag);

    ompi_message_return(*message);
    *message = MPI_MESSAGE_NULL;
    *request = (ompi_request_t *) recvreq;

    return OMPI_SUCCESS;
}


int
mca_pml_ob1_mrecv( void *buf,
                   size_t count,
                   ompi_datatype_t *datatype,
                   struct ompi_message_t **message,
                   ompi_status_public_t* status )
{
    mca_pml_ob1_recv_frag_t* frag;
    mca_pml_ob1_recv_request_t *recvreq;
    mca_pml_ob1_hdr_t *hdr;
    int src, tag, rc;
    ompi_communicator_t *comm;
    mca_pml_ob1_comm_proc_t* proc;
    uint64_t seq;

    /* get the request from the message and the frag from the request
       before we overwrite everything */
    comm = (*message)->comm;
    recvreq = (mca_pml_ob1_recv_request_t*) (*message)->req_ptr;
    frag = (mca_pml_ob1_recv_frag_t*) recvreq->req_recv.req_base.req_addr;
    src = recvreq->req_recv.req_base.req_ompi.req_status.MPI_SOURCE;
    tag = recvreq->req_recv.req_base.req_ompi.req_status.MPI_TAG;
    seq = recvreq->req_recv.req_base.req_sequence;

    /* make the request a recv request again */
    /* The old request kept pointers to comm and the char datatype.
       We're about to release those, but need to make sure comm
       doesn't go out of scope (we don't care about the char datatype
       anymore).  So retain comm, then release the frag, then reinit
       the frag (which will retain comm), then release comm (but the
       frag still has it's ref, so it'll stay in scope).  Make
       sense? */
    OBJ_RETAIN(comm);
    MCA_PML_BASE_RECV_REQUEST_FINI(&recvreq->req_recv);
    recvreq->req_recv.req_base.req_type = MCA_PML_REQUEST_RECV;
    MCA_PML_OB1_RECV_REQUEST_INIT(recvreq,
                                  buf,
                                  count, datatype,
                                  src, tag, comm, false);
    OBJ_RELEASE(comm);

    PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE,
                             &((recvreq)->req_recv.req_base),
                             PERUSE_RECV);

    /* init/re-init the request */
    recvreq->req_lock = 0;
    recvreq->req_pipeline_depth  = 0;
    recvreq->req_bytes_received  = 0;
    recvreq->req_rdma_cnt = 0;
    recvreq->req_rdma_idx = 0;
    recvreq->req_pending = false;

    MCA_PML_BASE_RECV_START(&recvreq->req_recv);

    /* Note - sequence number already assigned */
    recvreq->req_recv.req_base.req_sequence = seq;

    proc = mca_pml_ob1_peer_lookup (comm, recvreq->req_recv.req_base.req_peer);
    recvreq->req_recv.req_base.req_proc = proc->ompi_proc;
    prepare_recv_req_converter(recvreq);

    /* we can't go through the match, since we already have the match.
       Cheat and do what REQUEST_START does, but without the frag
       search */
    hdr = (mca_pml_ob1_hdr_t*)frag->segments->seg_addr.pval;
    switch(hdr->hdr_common.hdr_type) {
    case MCA_PML_OB1_HDR_TYPE_MATCH:
        mca_pml_ob1_recv_request_progress_match(recvreq, frag->btl, frag->segments,
                                                frag->num_segments);
        break;
    case MCA_PML_OB1_HDR_TYPE_RNDV:
        mca_pml_ob1_recv_request_progress_rndv(recvreq, frag->btl, frag->segments,
                                               frag->num_segments);
        break;
    case MCA_PML_OB1_HDR_TYPE_RGET:
        mca_pml_ob1_recv_request_progress_rget(recvreq, frag->btl, frag->segments,
                                               frag->num_segments);
        break;
    default:
        assert(0);
    }

    ompi_message_return(*message);
    *message = MPI_MESSAGE_NULL;
    ompi_request_wait_completion(&(recvreq->req_recv.req_base.req_ompi));

    MCA_PML_OB1_RECV_FRAG_RETURN(frag);

    if (MPI_STATUS_IGNORE != status) {
        OMPI_COPY_STATUS(status, recvreq->req_recv.req_base.req_ompi.req_status, false);
    }
    rc = recvreq->req_recv.req_base.req_ompi.req_status.MPI_ERROR;
#if OPAL_ENABLE_FT_MPI
    if( OPAL_UNLIKELY( MPI_ERR_PROC_FAILED_PENDING == rc )) {
        ompi_request_cancel(&recvreq->req_recv.req_base.req_ompi);
        ompi_request_wait_completion(&recvreq->req_recv.req_base.req_ompi);
        rc = MPI_ERR_PROC_FAILED;
    }
#endif
    ompi_request_free( (ompi_request_t**)&recvreq );
    return rc;
}