File: mtl_portals.c

package info (click to toggle)
openmpi 1.6.5-9.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 91,628 kB
  • ctags: 44,305
  • sloc: ansic: 408,966; cpp: 44,454; sh: 27,828; makefile: 10,486; asm: 3,882; python: 1,239; lex: 805; perl: 549; csh: 253; fortran: 232; f90: 126; tcl: 12
file content (379 lines) | stat: -rw-r--r-- 12,254 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
/*
 * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2005 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$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "ompi_config.h"

#include "ompi/mca/mtl/mtl.h"
#include "opal/class/opal_list.h"

#include "mtl_portals.h"
#include "mtl_portals_endpoint.h"
#include "mtl_portals_request.h"
#include "mtl_portals_recv.h"
#include "mtl_portals_recv_short.h"
#include "mtl_portals_send_short.h"

static ptl_handle_md_t send_catchall_md_h;
static ptl_handle_md_t ack_catchall_md_h;
static ptl_handle_md_t read_catchall_md_h;
static ptl_handle_md_t unex_long_md_h;

static ompi_mtl_portals_request_t catchall_send_request;
static ompi_mtl_portals_request_t catchall_ack_request;
static ompi_mtl_portals_request_t catchall_read_request;

mca_mtl_portals_module_t ompi_mtl_portals = {
    {
        8191,        /* max cid - 2^13 - 1 */
        (1UL << 30), /* max tag value - must allow negatives */
        0,           /* request reserve space */
        0,           /* flags */

        ompi_mtl_portals_add_procs,
        ompi_mtl_portals_del_procs,
        ompi_mtl_portals_finalize,

        ompi_mtl_portals_send,
        ompi_mtl_portals_isend,
        ompi_mtl_portals_irecv,
        ompi_mtl_portals_iprobe,

        NULL,       /* cancel */
        NULL,       /* add_comm */
        NULL        /* del_comm */
    }
};


/* BWB - fix me - this should be an ompi_free_list_item_t */
OBJ_CLASS_INSTANCE(ompi_mtl_portals_event_t, opal_list_item_t,
                   NULL, NULL);


/* catchall callback */
static int
ompi_mtl_portals_catchall_callback(ptl_event_t *ev, 
                                   ompi_mtl_portals_request_t *ptl_request)
{
    if (ptl_request == &catchall_send_request) {
        opal_output(fileno(stderr), "ERROR - received catchall event on send queue"); 
    } else if (ptl_request == &catchall_ack_request) {
        opal_output(fileno(stderr), "ERROR - received catchall event on ack queue");  
    } else if (ptl_request == &catchall_read_request) {
        opal_output(fileno(stderr), "ERROR - received catchall event on read queue");  
    } else {
        opal_output(fileno(stderr), "ERROR - received catchall event of unknown origin");  
    }

    abort();
    return OMPI_ERROR;
} 


int
ompi_mtl_portals_add_procs(struct mca_mtl_base_module_t *mtl,
                           size_t nprocs,
                           struct ompi_proc_t** procs, 
                           struct mca_mtl_base_endpoint_t **mtl_peer_data)
{
    int ret = OMPI_SUCCESS;
    ptl_process_id_t *portals_procs = NULL;
    ptl_md_t md;
    size_t i;
    ptl_match_bits_t match_bits;
    ptl_match_bits_t ignore_bits;
    ptl_process_id_t anyid = { PTL_NID_ANY, PTL_PID_ANY };
    bool accel;
    
    assert(mtl == &ompi_mtl_portals.base);

    /* if we haven't already initialized the network, do so now.  We
       delay until add_procs because if we want the automatic runtime
       environment setup the common code does for the utcp
       implementation, we can't do it until modex information can be
       received. */
    
    if (PTL_INVALID_HANDLE == ompi_mtl_portals.ptl_ni_h) {
        
        ret = ompi_common_portals_ni_initialize(&(ompi_mtl_portals.ptl_ni_h), &accel);
        if (OMPI_SUCCESS != ret) goto cleanup;
    }   
    
    /* event queue for expected events */
    ret = PtlEQAlloc(ompi_mtl_portals.ptl_ni_h,
                     ompi_mtl_portals.ptl_expected_queue_size,
                     PTL_EQ_HANDLER_NONE,
                     &(ompi_mtl_portals.ptl_eq_h));
    assert(ret == PTL_OK);

    /* event queue for unexpected receives */
    ret = PtlEQAlloc(ompi_mtl_portals.ptl_ni_h,
                     ompi_mtl_portals.ptl_unexpected_queue_size,
                     PTL_EQ_HANDLER_NONE,
                     &(ompi_mtl_portals.ptl_unex_eq_h));
    assert(ret == PTL_OK);

    /* empty event queue for PtlMEMDPost() */
    ret = PtlEQAlloc(ompi_mtl_portals.ptl_ni_h,
                     1,
                     PTL_EQ_HANDLER_NONE,
                     &(ompi_mtl_portals.ptl_empty_eq_h));
    assert(ret == PTL_OK);

    /* attach the long unex msg buffer */
    match_bits  = PTL_LONG_MSG;
    ignore_bits = ~(PTL_LONG_MSG);

    ret = PtlMEAttach(ompi_mtl_portals.ptl_ni_h,
                      OMPI_MTL_PORTALS_SEND_TABLE_ID,
                      anyid,
                      match_bits,
                      ignore_bits,
                      PTL_RETAIN,
                      PTL_INS_AFTER,
                      &(ompi_mtl_portals.ptl_unex_long_me_h));
    assert(ret == PTL_OK);

    md.start     = NULL;
    md.length    = 0;
    md.threshold = PTL_MD_THRESH_INF;
    md.max_size  = 0;
    md.options   = PTL_MD_OP_PUT | PTL_MD_TRUNCATE | PTL_MD_ACK_DISABLE;
    md.eq_handle = ompi_mtl_portals.ptl_unex_eq_h;
    md.user_ptr  = NULL;

    ret = PtlMDAttach(ompi_mtl_portals.ptl_unex_long_me_h,
                      md,
                      PTL_RETAIN,
                      &unex_long_md_h);
    assert(ret == PTL_OK);

    /* attach catchalls to the send, ack, and read portals */
    md.eq_handle = ompi_mtl_portals.ptl_eq_h;

    /* catchall for the send portal */
    catchall_send_request.event_callback = ompi_mtl_portals_catchall_callback;
    md.user_ptr = &catchall_send_request;
    ret = PtlMEMDPost(ompi_mtl_portals.ptl_ni_h,
                      ompi_mtl_portals.ptl_unex_long_me_h,
                      anyid,
                      0,
                      ~0,
                      PTL_RETAIN,
                      PTL_INS_AFTER,
                      md,
                      PTL_UNLINK,
                      &(ompi_mtl_portals.ptl_send_catchall_me_h),
                      &send_catchall_md_h,
                      ompi_mtl_portals.ptl_empty_eq_h);
    assert(ret == PTL_OK);

    /* catchall for ack portal */
    catchall_ack_request.event_callback = ompi_mtl_portals_catchall_callback;
    md.user_ptr = &catchall_ack_request;
    ret = PtlMEAttach(ompi_mtl_portals.ptl_ni_h,
                      OMPI_MTL_PORTALS_ACK_TABLE_ID,
                      anyid,
                      0,
                      ~0,
                      PTL_RETAIN,
                      PTL_INS_AFTER,
                      &(ompi_mtl_portals.ptl_ack_catchall_me_h));
    assert(ret == PTL_OK);

    ret = PtlMDAttach(ompi_mtl_portals.ptl_ack_catchall_me_h,
                      md,
                      PTL_UNLINK,
                      &ack_catchall_md_h);
    assert(ret == PTL_OK);

    /* catchall for read portal */
    catchall_read_request.event_callback = ompi_mtl_portals_catchall_callback;
    md.user_ptr = &catchall_read_request;
    ret = PtlMEAttach(ompi_mtl_portals.ptl_ni_h,
                      OMPI_MTL_PORTALS_READ_TABLE_ID,
                      anyid,
                      0,
                      ~0,
                      PTL_RETAIN,
                      PTL_INS_AFTER,
                      &(ompi_mtl_portals.ptl_read_catchall_me_h));
    assert(ret == PTL_OK);

    ret = PtlMDAttach(ompi_mtl_portals.ptl_read_catchall_me_h,
                      md,
                      PTL_RETAIN,
                      &read_catchall_md_h);
    assert(ret == PTL_OK);

    /* attach short unex recv blocks */
    ret = ompi_mtl_portals_recv_short_enable((mca_mtl_portals_module_t*) mtl);

    opal_progress_register(ompi_mtl_portals_progress);

    /* bind zero-length md for sending zero-length msgs and acks */
    md.start     = NULL;
    md.length    = 0;
    md.threshold = PTL_MD_THRESH_INF;
    md.max_size  = 0;
    md.options   = PTL_MD_EVENT_START_DISABLE | PTL_MD_EVENT_END_DISABLE;
    md.user_ptr  = NULL;
    md.eq_handle = PTL_EQ_NONE;

    ret = PtlMDBind(ompi_mtl_portals.ptl_ni_h,
                    md,
                    PTL_RETAIN,
                    &ompi_mtl_portals.ptl_zero_md_h ); 
    assert(ret == PTL_OK);

    /* set up the short copy blocks */
    ompi_mtl_portals_short_setup();

    

    /* get the list of ptl_process_id_t structures for the given proc
       structures.  If the Portals runtime environment supports
       comm_spawn, we'll be able to support it as well. */
    portals_procs = malloc(sizeof(ptl_process_id_t) * nprocs);
    if (NULL == portals_procs) goto cleanup;
    ret = ompi_common_portals_get_procs(nprocs, procs, portals_procs);
    if (OMPI_SUCCESS != ret) goto cleanup;

    /* copy the ptl_process_id_t information into our per-proc data
       store */
    for (i = 0 ; i < nprocs ; ++i) {
        mtl_peer_data[i] = malloc(sizeof(struct mca_mtl_base_endpoint_t));
        if (NULL == mtl_peer_data[i]) goto cleanup;
 
        mtl_peer_data[i]->ptl_proc.nid = portals_procs[i].nid;
        mtl_peer_data[i]->ptl_proc.pid = portals_procs[i].pid;
    }
    
 cleanup:
    if (NULL != portals_procs) free(portals_procs);
    return ret;
}


int
ompi_mtl_portals_del_procs(struct mca_mtl_base_module_t *mtl,
                           size_t nprocs,
                           struct ompi_proc_t** procs, 
                           struct mca_mtl_base_endpoint_t **mtl_peer_data)
{
    size_t i;

    assert(mtl == &ompi_mtl_portals.base);

    for (i = 0 ; i < nprocs ; ++i) {
        if (NULL != mtl_peer_data[i]) {
            free(mtl_peer_data[i]);
        }
    }

    ompi_mtl_portals_recv_short_disable((mca_mtl_portals_module_t *) mtl);

    ompi_mtl_portals_short_cleanup();

    (void)PtlMDUnlink(ompi_mtl_portals.ptl_zero_md_h);

    (void)PtlMDUnlink(send_catchall_md_h);

    (void)PtlMDUnlink(ack_catchall_md_h);

    (void)PtlMDUnlink(read_catchall_md_h);

    (void)PtlMDUnlink(unex_long_md_h);

    (void)PtlMEUnlink(ompi_mtl_portals.ptl_unex_long_me_h);
	
    (void)PtlMEUnlink(ompi_mtl_portals.ptl_send_catchall_me_h);

    (void)PtlMEUnlink(ompi_mtl_portals.ptl_ack_catchall_me_h);

    (void)PtlMEUnlink(ompi_mtl_portals.ptl_read_catchall_me_h);

    return OMPI_SUCCESS;
}


int
ompi_mtl_portals_finalize(struct mca_mtl_base_module_t *mtl)
{
    assert(mtl == &ompi_mtl_portals.base);

    /* Don't try to wait for things to finish if we've never initialized */
    if (PTL_INVALID_HANDLE != ompi_mtl_portals.ptl_ni_h) {
        ptl_event_t ev;
        int ret;

        opal_progress_unregister(ompi_mtl_portals_progress);

        /* Before progressing remaining events, check whether we don't get PTL_EQ_INVALID */
        ret = PtlEQPeek(ompi_mtl_portals.ptl_eq_h, &ev);

        if (PTL_EQ_INVALID != ret) {
            while (0 != ompi_mtl_portals_progress()) { }
        }
    }

    ompi_common_portals_ni_finalize();
    ompi_common_portals_finalize();

    return OMPI_SUCCESS;
}


int
ompi_mtl_portals_progress(void)
{
    int count = 0, ret;
    ptl_event_t ev;
    ompi_mtl_portals_request_t *ptl_request;

    while (true) {

	ret = PtlEQGet(ompi_mtl_portals.ptl_eq_h, &ev);

        if (PTL_OK == ret) {
            if (ev.type == PTL_EVENT_UNLINK) continue;

            if (NULL != ev.md.user_ptr) {
                ptl_request = ev.md.user_ptr;
                ret = ptl_request->event_callback(&ev, ptl_request);

                if (OMPI_SUCCESS != ret) {
                    opal_output(0, " Error returned from the event callback.  Error code - %d \n",ret);
                    abort();
                }
            }
        } else if (PTL_EQ_EMPTY == ret) {
            break;
        } else {
            opal_output(0, " Error returned from PtlEQGet.  Error code - %d \n",ret);
            abort();
        }
    }

    /* clean out the unexpected event queue too */
    if (ompi_mtl_portals.ptl_aggressive_polling == true) {
	while ( NULL != ompi_mtl_portals_search_unex_events(0, ~0, true) );
    }

    return count;
}