File: mtl_portals_send.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 (606 lines) | stat: -rw-r--r-- 16,983 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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
/*
 * 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/communicator/communicator.h"
#include "opal/datatype/opal_convertor.h"
#include "ompi/mca/mtl/base/base.h"
#include "ompi/mca/mtl/base/mtl_base_datatype.h"

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

/* send event callback functions */

/* called when no ack is necessary */
static int
ompi_mtl_portals_medium_callback(ptl_event_t *ev, ompi_mtl_portals_request_t *ptl_request)
{

    switch (ev->type) {

	case PTL_EVENT_SEND_END:

	    if (ptl_request->free_after) {
		free(ev->md.start);
	    }
	    
	    OPAL_OUTPUT_VERBOSE((50, ompi_mtl_base_output,
				 "send complete: 0x%016llx\n",
				 ev->match_bits));
	    
	    ptl_request->is_complete = true;
            if ( NULL != ptl_request->super.ompi_req ) {
		ptl_request->super.ompi_req->req_status.MPI_ERROR = OMPI_SUCCESS;
		ptl_request->super.completion_callback(&ptl_request->super);
	    }

	    
	    break;

	default:
	    opal_output(fileno(stderr)," Unexpected event type %d in ompi_mtl_portals_medium_callback()\n",ev->type); 
	    /* abort(); */
    }

    return OMPI_SUCCESS;
}

/* called when send should wait for an ack or get */
static int
ompi_mtl_portals_long_callback(ptl_event_t *ev, struct ompi_mtl_portals_request_t* ptl_request)
{

    switch (ev->type) {

	case PTL_EVENT_SEND_END:
	case PTL_EVENT_ACK:
	case PTL_EVENT_GET_END:
        /* we only receive an ack if the message was received into an
           expected message.  Otherwise, we don't get an ack, but mark
           completion when the message was pulled (long message). */
	    if ( ++(ptl_request->event_count) == 2 ) {

		if (ptl_request->free_after) {
		    free(ev->md.start);
		}

		OPAL_OUTPUT_VERBOSE((50, ompi_mtl_base_output,
				     "send complete: 0x%016llx\n", 
				     ev->match_bits));

		ptl_request->is_complete = true;
		if ( NULL != ptl_request->super.ompi_req ) {
		    ptl_request->super.ompi_req->req_status.MPI_ERROR = OMPI_SUCCESS;
		    ptl_request->super.completion_callback(&ptl_request->super);
		}
	    }

	    break;

	default:
	    opal_output(fileno(stderr)," Unexpected event type %d in ompi_mtl_portals_long_callback()\n",ev->type); 
	    abort();
    }
    
    return OMPI_SUCCESS;
}

/* called for a rendezvous long send */ 
static int
ompi_mtl_portals_long_rendezvous_callback(ptl_event_t *ev, struct ompi_mtl_portals_request_t* ptl_request)
{

    switch (ev->type) {

	case PTL_EVENT_GET_END:

		if (ptl_request->free_after) {
		    free(ev->md.start);
		}

		OPAL_OUTPUT_VERBOSE((50, ompi_mtl_base_output,
				     "send complete: 0x%016llx\n", 
				     ev->match_bits));

		ptl_request->is_complete = true;
		if ( NULL != ptl_request->super.ompi_req ) {
		    ptl_request->super.ompi_req->req_status.MPI_ERROR = OMPI_SUCCESS;
		    ptl_request->super.completion_callback(&ptl_request->super);
		}

	    break;

	default:
	    opal_output(fileno(stderr)," Unexpected event type %d in ompi_mtl_portals_long_callback()\n",ev->type); 
	    abort();
    }
    
    return OMPI_SUCCESS;
}

/* called when sync send should wait for an ack or put */
static int
ompi_mtl_portals_sync_callback(ptl_event_t *ev, struct ompi_mtl_portals_request_t* ptl_request)
{

    switch (ev->type) {

	case PTL_EVENT_SEND_END:
	case PTL_EVENT_ACK:
	case PTL_EVENT_PUT_END:
        /* we only receive an ack if the message was received into an
           expected message.  Otherwise, we don't get an ack, but mark
           completion when a zero-length put arrrives. */
	    if ( ++(ptl_request->event_count) == 2 ) {

		if (ptl_request->free_after) {
		    free(ev->md.start);
		}

		OPAL_OUTPUT_VERBOSE((50, ompi_mtl_base_output,
				     "send complete: 0x%016llx\n", 
				     ev->match_bits));

		ptl_request->is_complete = true;
		if ( NULL != ptl_request->super.ompi_req ) {
		    ptl_request->super.ompi_req->req_status.MPI_ERROR = OMPI_SUCCESS;
		    ptl_request->super.completion_callback(&ptl_request->super);
		}
	    }

	    break;

	default:
	    opal_output(fileno(stderr)," Unexpected event type %d in ompi_mtl_portals_sync_callback()\n",ev->type); 
	    abort();
    }
    
    return OMPI_SUCCESS;
}

/* internal send functions */

static int
ompi_mtl_portals_zero_send(mca_pml_base_send_mode_t mode, int contextid, int localrank,
			   int tag, ptl_process_id_t dest)
{
    int ret;
    ptl_match_bits_t match_bits;
    ptl_match_bits_t mode_bits;

    mode_bits = (MCA_PML_BASE_SEND_READY != mode) ? PTL_SHORT_MSG : PTL_READY_MSG;

    PTL_SET_SEND_BITS(match_bits, contextid, localrank, tag, mode_bits); 

    ret = PtlPut(ompi_mtl_portals.ptl_zero_md_h,
		 PTL_NO_ACK_REQ,
		 dest,
		 OMPI_MTL_PORTALS_SEND_TABLE_ID,
		 0,
		 match_bits,
		 0,
		 0 );
    if (PTL_OK != ret) {
	return ompi_common_portals_error_ptl_to_ompi(ret);
    }

    return OMPI_SUCCESS;

}

static int
ompi_mtl_portals_short_send(mca_pml_base_send_mode_t mode, void *start, int length,
			    int contextid, int localrank, int tag, ptl_process_id_t dest)
{
    int ret;
    ptl_match_bits_t match_bits;
    ptl_size_t offset;
    void *copyblock;
    ptl_match_bits_t mode_bits;

    mode_bits = (MCA_PML_BASE_SEND_READY != mode) ? PTL_SHORT_MSG : PTL_READY_MSG;

    PTL_SET_SEND_BITS(match_bits, contextid, localrank, tag, mode_bits); 

    offset = ompi_mtl_portals_alloc_short_buf() * ompi_mtl_portals.ptl_copy_block_len;

    copyblock = (char *)ompi_mtl_portals.ptl_short_md.start + offset;
	
    memcpy(copyblock, start, length);

    ret = PtlPutRegion(ompi_mtl_portals.ptl_short_md_h,
		       offset,
		       length,
		       PTL_NO_ACK_REQ,
		       dest,
		       OMPI_MTL_PORTALS_SEND_TABLE_ID,
		       0,
		       match_bits,
		       0,
		       0);
    if (PTL_OK != ret ) {
	return ompi_common_portals_error_ptl_to_ompi(ret);
    }

    return OMPI_SUCCESS;
	
}

static int
ompi_mtl_portals_medium_isend( mca_pml_base_send_mode_t mode, void *start, int length,
			       int contextid, int localrank, int tag, ptl_process_id_t dest,
			       ompi_mtl_portals_request_t *ptl_request )
{
    int ret;
    ptl_match_bits_t match_bits;
    ptl_md_t md;
    ptl_handle_md_t md_h;
    ptl_match_bits_t mode_bits;

    mode_bits = (MCA_PML_BASE_SEND_READY != mode) ? PTL_SHORT_MSG : PTL_READY_MSG;

    PTL_SET_SEND_BITS(match_bits, contextid, localrank, tag, mode_bits); 
    
    md.start = start;
    md.length = length;
    md.threshold = 1; /* send end */
    md.options = PTL_MD_EVENT_START_DISABLE;
    md.user_ptr = ptl_request;
    md.eq_handle = ompi_mtl_portals.ptl_eq_h;
    
    ret = PtlMDBind(ompi_mtl_portals.ptl_ni_h,
		    md,
		    PTL_UNLINK,
		    &md_h);
    if (PTL_OK != ret) {
	if (ptl_request->free_after) free(start);
	return ompi_common_portals_error_ptl_to_ompi(ret);
    }
    
    ret = PtlPut(md_h,
		 PTL_NO_ACK_REQ,
		 dest,
		 OMPI_MTL_PORTALS_SEND_TABLE_ID,
		 0,
		 match_bits,
		 0,
		 0);
    if (PTL_OK != ret) {
	PtlMDUnlink(md_h);
	if (ptl_request->free_after) free(start);
	return ompi_common_portals_error_ptl_to_ompi(ret);
    }

    ptl_request->is_complete = false;
    ptl_request->event_callback = ompi_mtl_portals_medium_callback;
    ptl_request->event_count = 0;
    
    return OMPI_SUCCESS;
    
}

static int
ompi_mtl_portals_long_isend( void *start, int length, int contextid, int localrank, int tag,
			     ptl_process_id_t dest, ompi_mtl_portals_request_t *ptl_request )
{
    int ret;
    ptl_match_bits_t match_bits;
    ptl_md_t md;
    ptl_handle_md_t md_h;
    ptl_handle_me_t me_h;

    PTL_SET_SEND_BITS(match_bits, contextid, localrank, tag, PTL_LONG_MSG);

    md.start = start;
    md.length = length;

    if (ompi_mtl_portals.ptl_use_rendezvous == true) {
        md.threshold = 1; /* get event */
    } else {
        md.threshold = 2; /* sent event, ack or get event */
    }

    md.options = PTL_MD_OP_GET | PTL_MD_EVENT_START_DISABLE;
    md.user_ptr = ptl_request;
    md.eq_handle = ompi_mtl_portals.ptl_eq_h;

    ret = PtlMEMDPost(ompi_mtl_portals.ptl_ni_h,
		      ompi_mtl_portals.ptl_read_catchall_me_h,
		      dest,
		      (ptl_match_bits_t)(uintptr_t)ptl_request,
		      0,
		      PTL_UNLINK,
		      PTL_INS_BEFORE,
		      md,
		      PTL_UNLINK,
		      &me_h,
		      &md_h,
		      ompi_mtl_portals.ptl_empty_eq_h);
    if (PTL_OK != ret) {
	if (ptl_request->free_after) free(start);
	return ompi_common_portals_error_ptl_to_ompi(ret);
    }

    if (ompi_mtl_portals.ptl_use_rendezvous == false) {

        ret = PtlPut(md_h,
		     PTL_ACK_REQ,
		     dest,
		     OMPI_MTL_PORTALS_SEND_TABLE_ID,
		     0,
		     match_bits,
		     0,
		     (ptl_hdr_data_t)(uintptr_t)ptl_request);

	ptl_request->event_callback = ompi_mtl_portals_long_callback;

    } else {

        /* just send a zero-length message */
	ret = PtlPut(ompi_mtl_portals.ptl_zero_md_h,
		     PTL_NO_ACK_REQ,
		     dest,
		     OMPI_MTL_PORTALS_SEND_TABLE_ID,
                     0,
                     match_bits,
                     0,
                     (ptl_hdr_data_t)(uintptr_t)ptl_request);

	ptl_request->event_callback = ompi_mtl_portals_long_rendezvous_callback;

    }

    if (PTL_OK != ret) {
	PtlMEUnlink(me_h);
	if (ptl_request->free_after) free(start);
	return ompi_common_portals_error_ptl_to_ompi(ret);
    }

    ptl_request->is_complete = false;
    ptl_request->event_count = 0;

    return OMPI_SUCCESS;
}

static int
ompi_mtl_portals_sync_isend( void *start, int length, int contextid, int localrank, int tag,
			     ptl_process_id_t dest, ompi_mtl_portals_request_t *ptl_request )
{
    int ret;
    ptl_match_bits_t match_bits;
    ptl_md_t md;
    ptl_handle_md_t md_h;
    ptl_handle_me_t me_h;

    PTL_SET_SEND_BITS(match_bits, contextid, localrank, tag, PTL_SHORT_MSG);

    md.start = start;
    md.length = length;
    md.threshold = 2; /* send, {ack, get} */
    md.options = PTL_MD_OP_PUT | PTL_MD_EVENT_START_DISABLE;
    md.user_ptr = ptl_request;
    md.eq_handle = ompi_mtl_portals.ptl_eq_h;

    ret = PtlMEMDPost(ompi_mtl_portals.ptl_ni_h,
		      ompi_mtl_portals.ptl_ack_catchall_me_h,
		      dest,
		      (ptl_match_bits_t)(uintptr_t)ptl_request,
		      0,
		      PTL_UNLINK,
		      PTL_INS_BEFORE,
		      md,
		      PTL_UNLINK,
		      &me_h,
		      &md_h,
		      ompi_mtl_portals.ptl_empty_eq_h);
    if (PTL_OK != ret) {
	if (ptl_request->free_after) free(start);
	return ompi_common_portals_error_ptl_to_ompi(ret);
    }

    ret = PtlPut(md_h,
		 PTL_ACK_REQ,
		 dest,
		 OMPI_MTL_PORTALS_SEND_TABLE_ID,
		 0,
		 match_bits,
		 0,
		 (ptl_hdr_data_t)(uintptr_t)ptl_request);
    if (PTL_OK != ret) {
	PtlMEUnlink(me_h);
	if (ptl_request->free_after) free(start);
	return ompi_common_portals_error_ptl_to_ompi(ret);
    }

    ptl_request->is_complete = false;
    ptl_request->event_callback = ompi_mtl_portals_sync_callback;
    ptl_request->event_count = 0;

    return OMPI_SUCCESS;
    
}

/* We use a macro for this since the send code is identical for blocking and non-blocking
   sends, but we want both to be as fast as possible. We define it here since it doesn't
   get used anywhere else. */
#define PTL_SEND_CODE									\
{											\
    switch (mode) {									\
	case MCA_PML_BASE_SEND_STANDARD:						\
	case MCA_PML_BASE_SEND_READY:							\
	case MCA_PML_BASE_SEND_BUFFERED:					     	\
											\
	    if (0 == length) {								\
											\
		ret =  ompi_mtl_portals_zero_send(mode,					\
						  comm->c_contextid,			\
						  comm->c_my_rank,			\
						  tag,					\
						  endpoint->ptl_proc);			\
		if (OMPI_SUCCESS != ret) return ret;			        	\
											\
                ptl_request->is_complete = true;                                        \
											\
                break;                                                                  \
											\
	    } else if (length <= ompi_mtl_portals.ptl_copy_block_len) {			\
											\
		ret =  ompi_mtl_portals_short_send(mode,				\
						   start,				\
						   length,				\
						   comm->c_contextid,			\
						   comm->c_my_rank,			\
						   tag,					\
						   endpoint->ptl_proc);			\
		if (OMPI_SUCCESS != ret) return ret;			        	\
											\
                ptl_request->is_complete = true;                                        \
											\
                break;                                                                  \
											\
	    } else if ((length <= ompi_mtl_portals.eager_limit) ||			\
		       (MCA_PML_BASE_SEND_READY == mode)) {				\
											\
		ret = ompi_mtl_portals_medium_isend(mode,				\
						    start,				\
						    length,				\
						    comm->c_contextid,			\
						    comm->c_my_rank,			\
						    tag,				\
						    endpoint->ptl_proc,			\
						    ptl_request );			\
		if (OMPI_SUCCESS != ret) return ret;			        	\
											\
		break;									\
											\
	    }										\
											\
	    /* long standard send case falls through */					\
											\
	case MCA_PML_BASE_SEND_SYNCHRONOUS:						\
											\
	    if (length <= ompi_mtl_portals.eager_limit) {				\
											\
		ret = ompi_mtl_portals_sync_isend(start,				\
						  length,				\
						  comm->c_contextid,			\
						  comm->c_my_rank,			\
						  tag,					\
						  endpoint->ptl_proc,			\
						  ptl_request );			\
		if (OMPI_SUCCESS != ret) return ret;					\
											\
	    } else {									\
	    /* if we got this far, we're either a standard or synchronous long send */	\
		ret = ompi_mtl_portals_long_isend(start,				\
						  length,				\
						  comm->c_contextid,			\
						  comm->c_my_rank,			\
						  tag,					\
						  endpoint->ptl_proc,			\
						  ptl_request );			\
		if (OMPI_SUCCESS != ret) return ret;					\
											\
	    }										\
											\
	    break;									\
											\
	default:									\
	    opal_output(fileno(stderr),"Unexpected msg type %d\n", mode);                        \
            abort();                                                                    \
											\
    }											\
}

/* external send functions */
int
ompi_mtl_portals_send(struct mca_mtl_base_module_t* mtl,
                      struct ompi_communicator_t* comm,
                      int dest,
                      int tag,
                      struct opal_convertor_t *convertor,
                      mca_pml_base_send_mode_t mode)
{
    int ret;
    ompi_proc_t *ompi_proc = ompi_comm_peer_lookup( comm, dest );
    mca_mtl_base_endpoint_t *endpoint = (mca_mtl_base_endpoint_t*) ompi_proc->proc_pml;
    void *start;
    size_t length;
    ompi_mtl_portals_request_t mtl_request;
    ompi_mtl_portals_request_t *ptl_request = (ompi_mtl_portals_request_t*)&mtl_request;

    assert(mtl == &ompi_mtl_portals.base);

    ret = ompi_mtl_datatype_pack(convertor, &start, &length,
				 &(ptl_request->free_after));
    if (OMPI_SUCCESS != ret) return ret;

    ptl_request->is_complete = false;
    ptl_request->super.ompi_req = NULL;

    PTL_SEND_CODE;

    /* wait for send to complete */
    while (ptl_request->is_complete == false) {
	ompi_mtl_portals_progress();
    }

    return OMPI_SUCCESS;
    
}

int
ompi_mtl_portals_isend(struct mca_mtl_base_module_t* mtl,
                       struct ompi_communicator_t* comm,
                       int dest,
                       int tag,
                       struct opal_convertor_t *convertor,
                       mca_pml_base_send_mode_t mode,
                       bool blocking,
                       mca_mtl_request_t *mtl_request)
{
    int ret;
    ompi_proc_t *ompi_proc = ompi_comm_peer_lookup( comm, dest );
    mca_mtl_base_endpoint_t *endpoint = (mca_mtl_base_endpoint_t*)ompi_proc->proc_pml;
    ompi_mtl_portals_request_t *ptl_request = (ompi_mtl_portals_request_t*)mtl_request;
    void *start;
    size_t length;

    assert(mtl == &ompi_mtl_portals.base);

    ret = ompi_mtl_datatype_pack(convertor, &start, &length,
				 &(ptl_request->free_after));
    if (OMPI_SUCCESS != ret) return ret;

    ptl_request->is_complete = false;

    PTL_SEND_CODE;

    if (ptl_request->is_complete == true ) {
        ptl_request->super.ompi_req->req_status.MPI_ERROR = OMPI_SUCCESS;
        ptl_request->super.completion_callback(&ptl_request->super);
    }

    return OMPI_SUCCESS;

}