File: btl_portals_send.c

package info (click to toggle)
openmpi 1.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 60,812 kB
  • sloc: ansic: 307,904; sh: 39,104; cpp: 19,228; makefile: 8,573; asm: 3,627; lex: 901; perl: 362; yacc: 275; csh: 188; fortran: 175; f90: 126; tcl: 12
file content (255 lines) | stat: -rw-r--r-- 10,574 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
/*
 * Copyright (c) 2004-2005 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 (c) 2008      UT-Battelle, LLC. All rights reserved.
 * $COPYRIGHT$
 * 
 * Additional copyrights may follow
 * 
 * $HEADER$
 */


#include "ompi_config.h"

#include <assert.h>

#include "ompi/constants.h"
#include "ompi/datatype/convertor.h"
#include "ompi/datatype/datatype.h"

#include "btl_portals.h"
#include "btl_portals_send.h"


int
mca_btl_portals_send(struct mca_btl_base_module_t* btl_base,
                     struct mca_btl_base_endpoint_t* endpoint,
                     struct mca_btl_base_descriptor_t* descriptor, 
                     mca_btl_base_tag_t tag)
{
    mca_btl_portals_frag_t *frag = (mca_btl_portals_frag_t*) descriptor;
    int ret;
    unsigned char hdr_data[8];
    
    assert(&mca_btl_portals_module == (mca_btl_portals_module_t*) btl_base);

    frag->endpoint = endpoint;
    hdr_data[7] = frag->hdr.tag = tag;

    OPAL_OUTPUT_VERBOSE((90, mca_btl_portals_component.portals_output,
                         "PtlPut (send) fragment %lx",
                         (unsigned long) frag));

    if (OPAL_THREAD_ADD32(&mca_btl_portals_module.portals_outstanding_ops, 1) >
        mca_btl_portals_module.portals_max_outstanding_ops) {
        /* no space - queue and continute */
        opal_output_verbose(50, mca_btl_portals_component.portals_output,
                            "no space for message 0x%lx.  Adding to back of queue",
                            (unsigned long) frag);
        OPAL_THREAD_ADD32(&mca_btl_portals_module.portals_outstanding_ops, -1);
        opal_list_append(&(mca_btl_portals_module.portals_queued_sends),
                         (opal_list_item_t*) frag);
    }

    if (frag->md_h == PTL_INVALID_HANDLE) {
        /* setup the send - always describe entire fragment */
        mca_btl_portals_module.md_send.start = frag->segments[0].seg_addr.pval;
        mca_btl_portals_module.md_send.length = 
            0 == frag->size ? frag->segments[0].seg_len : frag->size;
#if OMPI_ENABLE_DEBUG 
        mca_btl_portals_module.md_send.options = 
            PTL_MD_EVENT_START_DISABLE;
#else 
        /* optimized build, we can get rid of the END event */
        /*  if we are using portals ACK's for completion */
        mca_btl_portals_module.md_send.options = 
            (PTL_MD_EVENT_START_DISABLE | 
             (mca_btl_portals_component.portals_need_ack ? PTL_MD_EVENT_END_DISABLE : 0));
#endif
        mca_btl_portals_module.md_send.user_ptr = frag; /* keep a pointer to ourselves */

        /* make a free-floater */
        ret = PtlMDBind(mca_btl_portals_module.portals_ni_h,
                        mca_btl_portals_module.md_send,
                        PTL_UNLINK,
                        &frag->md_h);
        if (ret != PTL_OK) {
            opal_output(mca_btl_portals_component.portals_output,
                        "PtlMDBind failed with error %d", ret);
            return OMPI_ERROR;
        }
    } 

    OPAL_OUTPUT_VERBOSE((90, mca_btl_portals_component.portals_output,
                         "fragment info:\n"
                         "\tstart: 0x%lx\n"
                         "\tlen: %d",
                         (unsigned long) frag->segments[0].seg_addr.pval,
                         frag->segments[0].seg_len)); 
    
    ret = PtlPutRegion(frag->md_h,                /* memory descriptor */
                       0,                         /* fragment offset */
                       frag->segments[0].seg_len, /* fragment length */
                       (mca_btl_portals_component.portals_need_ack ? PTL_ACK_REQ : PTL_NO_ACK_REQ),
                       *((mca_btl_base_endpoint_t*) endpoint),
                       OMPI_BTL_PORTALS_SEND_TABLE_ID,
                       0,                         /* ac_index - not used */
                       0,                         /* match bits */
                       0,                         /* remote offset - not used */
                       *((ptl_hdr_data_t*) hdr_data));            /* hdr_data: tag */
    if (ret != PTL_OK) {
        opal_output(mca_btl_portals_component.portals_output,
                    "send: PtlPut failed with error %d", ret);
        return OMPI_ERROR;
    }

    return OMPI_SUCCESS;
}



int mca_btl_portals_sendi(struct mca_btl_base_module_t* btl_base,
                          struct mca_btl_base_endpoint_t* endpoint,
                          struct ompi_convertor_t* convertor,
                          void* header,
                          size_t header_size,
                          size_t payload_size,
                          uint8_t order,
                          uint32_t flags,
                          mca_btl_base_tag_t tag, 
                          mca_btl_base_descriptor_t** des)
{
    mca_btl_portals_frag_t *frag = NULL;
    struct iovec iov;
    unsigned int iov_count;
    unsigned char match_bits[8];
    unsigned char hdr_data[8];
    int ret;
    size_t max_data;
    
    assert(&mca_btl_portals_module == (mca_btl_portals_module_t*) btl_base);
    *des = NULL; 
    if (OPAL_THREAD_ADD32(&mca_btl_portals_module.portals_outstanding_ops, 1) >
        mca_btl_portals_module.portals_max_outstanding_ops) {
        /* no space - queue and continue */
        opal_output_verbose(50, mca_btl_portals_component.portals_output,
                            "no resources left for send inline");
        
        OPAL_THREAD_ADD32(&mca_btl_portals_module.portals_outstanding_ops, -1);
        *des = mca_btl_portals_alloc(btl_base, endpoint, order, 
                                     payload_size + header_size, flags);
        return OMPI_ERR_RESOURCE_BUSY;
        
    } else if(14 < header_size) { 
        /* header is too big */
        *des = mca_btl_portals_alloc(btl_base, endpoint, order, 
                                     payload_size + header_size, flags);
        OPAL_THREAD_ADD32(&mca_btl_portals_module.portals_outstanding_ops, -1);
        return OMPI_ERR_RESOURCE_BUSY;
    }
    
    assert (payload_size <= mca_btl_portals_module.super.btl_eager_limit);
    
    OMPI_BTL_PORTALS_FRAG_ALLOC_EAGER(&mca_btl_portals_module, frag, ret); 
    if (OMPI_SUCCESS != ret) { 
        OPAL_THREAD_ADD32(&mca_btl_portals_module.portals_outstanding_ops, -1);
        return OMPI_ERR_RESOURCE_BUSY;
    }
    frag->segments[0].seg_len = payload_size;
    frag->base.des_src_cnt = 1;
    frag->base.des_flags = flags; 
    frag->base.order = MCA_BTL_NO_ORDER;
    frag->endpoint = endpoint;

    if(payload_size) { 
        /* pack the data into the supplied buffer */
        iov.iov_base = (IOVBASE_TYPE*)((unsigned char*)frag->segments[0].seg_addr.pval);
        iov.iov_len  = max_data = payload_size;
        iov_count    = 1;
        
        (void)ompi_convertor_pack( convertor,
                                   &iov, &iov_count, &max_data);
        
        assert(max_data == payload_size);
    }
    
    if(header_size) { 
        memcpy(match_bits, header, header_size > 8 ? 8 : header_size);
    }
    if(header_size > 8 ) { 
        memcpy(hdr_data, ((unsigned char*) header) + 8, header_size - 8);
    }
    hdr_data[6] = header_size;
    hdr_data[7] = frag->hdr.tag = tag;
    
    
    OPAL_OUTPUT_VERBOSE((90, mca_btl_portals_component.portals_output,
                         "PtlPut (send) fragment %lx",
                         (unsigned long) frag));
    


    if (frag->md_h == PTL_INVALID_HANDLE) {
        /* setup the send - always describe entire fragment */
        mca_btl_portals_module.md_send.start = frag->segments[0].seg_addr.pval;
        mca_btl_portals_module.md_send.length = 
            0 == frag->size ? frag->segments[0].seg_len : frag->size;
#if OMPI_ENABLE_DEBUG 
        mca_btl_portals_module.md_send.options = 
            PTL_MD_EVENT_START_DISABLE;
#else 
        /* optimized build, we can get rid of the END event */
        /*  if we are using portals ACK's for completion */
        mca_btl_portals_module.md_send.options = 
            (PTL_MD_EVENT_START_DISABLE | 
             (mca_btl_portals_component.portals_need_ack ? PTL_MD_EVENT_END_DISABLE : 0));
#endif
        mca_btl_portals_module.md_send.user_ptr = frag; /* keep a pointer to ourselves */

        /* make a free-floater */
        ret = PtlMDBind(mca_btl_portals_module.portals_ni_h,
                        mca_btl_portals_module.md_send,
                        PTL_UNLINK,
                        &frag->md_h);
        if (ret != PTL_OK) {
            opal_output(mca_btl_portals_component.portals_output,
                        "PtlMDBind failed with error %d", ret);
            return OMPI_ERROR;
        }
    } 

    OPAL_OUTPUT_VERBOSE((90, mca_btl_portals_component.portals_output,
                         "fragment info:\n"
                         "\tstart: 0x%lx\n"
                         "\tlen: %d",
                         (unsigned long) frag->segments[0].seg_addr.pval,
                         frag->segments[0].seg_len)); 
    
    ret = PtlPutRegion(frag->md_h,                /* memory descriptor */
                       0,                         /* fragment offset */
                       frag->segments[0].seg_len, /* fragment length */
                       (mca_btl_portals_component.portals_need_ack ? PTL_ACK_REQ : PTL_NO_ACK_REQ),
                       *((mca_btl_base_endpoint_t*) endpoint),
                       OMPI_BTL_PORTALS_SEND_TABLE_ID,
                       0,                         /* ac_index - not used */
                       *((ptl_match_bits_t*) match_bits),                /* match bits */
                       0,                         /* remote offset - not used */
                       *((ptl_hdr_data_t*) hdr_data));            /* hdr_data: tag */
    
    if (ret != PTL_OK) {
        opal_output(mca_btl_portals_component.portals_output,
                    "send: PtlPut failed with error %d", ret);
        return OMPI_ERROR;
    }

    return OMPI_SUCCESS;
}