root/mpich2/trunk/src/mpid/ch3/channels/nemesis/nemesis/src/mpid_nem_lmt.c @ 4888

Revision 4888, 19.0 KB (checked in by buntinas, 5 months ago)

squashed more warnings

Line 
1/* -*- Mode: C; c-basic-offset:4 ; -*- */
2/*
3 *  (C) 2006 by Argonne National Laboratory.
4 *      See COPYRIGHT in top-level directory.
5 */
6
7#include "mpid_nem_impl.h"
8
9#define set_request_info(rreq_, pkt_, msg_type_)                \
10{                                                               \
11    (rreq_)->status.MPI_SOURCE = (pkt_)->match.parts.rank;      \
12    (rreq_)->status.MPI_TAG = (pkt_)->match.parts.tag;          \
13    (rreq_)->status.count = (pkt_)->data_sz;                    \
14    (rreq_)->dev.sender_req_id = (pkt_)->sender_req_id;         \
15    (rreq_)->dev.recv_data_sz = (pkt_)->data_sz;                \
16    MPIDI_Request_set_seqnum((rreq_), (pkt_)->seqnum);          \
17    MPIDI_Request_set_msg_type((rreq_), (msg_type_));           \
18}
19
20/* request completion actions */
21static int do_cts(MPIDI_VC_t *vc, MPID_Request *rreq, int *complete);
22static int do_send(MPIDI_VC_t *vc, MPID_Request *rreq, int *complete);
23static int do_cookie(MPIDI_VC_t *vc, MPID_Request *rreq, int *complete);
24
25/* packet handlers */
26static int pkt_RTS_handler(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt, MPIDI_msg_sz_t *buflen, MPID_Request **rreqp);
27static int pkt_CTS_handler(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt, MPIDI_msg_sz_t *buflen, MPID_Request **rreqp);
28static int pkt_DONE_handler(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt, MPIDI_msg_sz_t *buflen, MPID_Request **rreqp);
29static int pkt_COOKIE_handler(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt, MPIDI_msg_sz_t *buflen, MPID_Request **rreqp);
30
31#undef FUNCNAME
32#define FUNCNAME MPID_nem_lmt_pkthandler_init
33#undef FCNAME
34#define FCNAME MPIDI_QUOTE(FUNCNAME)
35int MPID_nem_lmt_pkthandler_init(MPIDI_CH3_PktHandler_Fcn *pktArray[], int arraySize)
36{
37    int mpi_errno = MPI_SUCCESS;
38    MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_LMT_PKTHANDLER_INIT);
39
40    MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_LMT_PKTHANDLER_INIT);
41
42    /* Check that the array is large enough */
43    if (arraySize <= MPIDI_NEM_PKT_END) {
44        MPIU_ERR_SETFATALANDJUMP(mpi_errno,MPI_ERR_INTERN, "**ch3|pktarraytoosmall");
45    }
46
47    pktArray[MPIDI_NEM_PKT_LMT_RTS] = pkt_RTS_handler;
48    pktArray[MPIDI_NEM_PKT_LMT_CTS] = pkt_CTS_handler;
49    pktArray[MPIDI_NEM_PKT_LMT_DONE] = pkt_DONE_handler;
50    pktArray[MPIDI_NEM_PKT_LMT_COOKIE] = pkt_COOKIE_handler;
51
52 fn_exit:
53    MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_LMT_PKTHANDLER_INIT);
54    return mpi_errno;
55 fn_fail:
56    goto fn_exit;
57}
58
59/* MPID_nem_lmt_RndvSend - Send a request to perform a rendezvous send */
60#undef FUNCNAME
61#define FUNCNAME MPID_nem_lmt_RndvSend
62#undef FCNAME
63#define FCNAME MPIDI_QUOTE(FUNCNAME)
64int MPID_nem_lmt_RndvSend(MPID_Request **sreq_p, const void * buf, int count, MPI_Datatype datatype, int dt_contig,
65                          MPIDI_msg_sz_t data_sz, MPI_Aint dt_true_lb, int rank, int tag, MPID_Comm * comm, int context_offset)
66{
67    int mpi_errno = MPI_SUCCESS;
68    MPID_PKT_DECL_CAST(upkt, MPID_nem_pkt_lmt_rts_t, rts_pkt);
69    MPIDI_VC_t *vc;
70    MPID_Request *sreq =*sreq_p;
71    MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_LMT_RNDVSEND);
72
73    MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_LMT_RNDVSEND);
74
75    MPIDI_Comm_get_vc_set_active(comm, rank, &vc);
76
77    /* if the lmt functions are not set, fall back to the default rendezvous code */
78    if (((MPIDI_CH3I_VC *)vc->channel_private)->lmt_initiate_lmt == NULL)
79    {
80        mpi_errno = MPIDI_CH3_RndvSend(sreq_p, buf, count, datatype, dt_contig, data_sz, dt_true_lb, rank, tag, comm, context_offset);
81        if (mpi_errno) MPIU_ERR_POP(mpi_errno);
82        goto fn_exit;
83    }
84
85    MPIU_DBG_MSG_D(CH3_OTHER,VERBOSE,
86                   "sending lmt RTS, data_sz=" MPIDI_MSG_SZ_FMT, data_sz);
87    sreq->partner_request = NULL;
88    sreq->ch.lmt_tmp_cookie.MPID_IOV_LEN = 0;
89       
90    MPIDI_Pkt_init(rts_pkt, MPIDI_NEM_PKT_LMT_RTS);
91    rts_pkt->match.parts.rank         = comm->rank;
92    rts_pkt->match.parts.tag          = tag;
93    rts_pkt->match.parts.context_id = comm->context_id + context_offset;
94    rts_pkt->sender_req_id    = sreq->handle;
95    rts_pkt->data_sz          = data_sz;
96
97    MPIDI_VC_FAI_send_seqnum(vc, seqnum);
98    MPIDI_Pkt_set_seqnum(rts_pkt, seqnum);
99    MPIDI_Request_set_seqnum(sreq, seqnum);
100
101    mpi_errno = ((MPIDI_CH3I_VC *)vc->channel_private)->lmt_initiate_lmt(vc, &upkt.p, sreq);
102    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
103
104 fn_exit:
105    MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_LMT_RNDVSEND);
106    return mpi_errno;
107 fn_fail:
108    goto fn_exit;
109}
110
111/*
112 * This routine processes a rendezvous message once the message is matched.
113 * It is used in mpid_recv and mpid_irecv.
114 */
115#undef FUNCNAME
116#define FUNCNAME MPID_nem_lmt_RndvRecv
117#undef FCNAME
118#define FCNAME MPIDI_QUOTE(FUNCNAME)
119int MPID_nem_lmt_RndvRecv(MPIDI_VC_t *vc, MPID_Request *rreq)
120{
121    int mpi_errno = MPI_SUCCESS;
122    int complete = 0;
123    MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_LMT_RNDVRECV);
124
125    MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_LMT_RNDVRECV);
126
127    /* if the lmt functions are not set, fall back to the default rendezvous code */
128    if (((MPIDI_CH3I_VC *)vc->channel_private)->lmt_initiate_lmt == NULL)
129    {
130        mpi_errno = MPIDI_CH3_RecvRndv(vc, rreq);
131        if (mpi_errno) MPIU_ERR_POP(mpi_errno);
132        goto fn_exit;
133    }
134
135    MPIU_DBG_MSG(CH3_OTHER,VERBOSE, "lmt RTS in the request");
136
137    mpi_errno = do_cts(vc, rreq, &complete);
138    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
139
140    MPIU_Assert(complete);
141
142 fn_exit:
143    MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_LMT_RNDVRECV);
144    return mpi_errno;
145 fn_fail:
146    goto fn_exit;
147}
148
149#undef FUNCNAME
150#define FUNCNAME pkt_RTS_handler
151#undef FCNAME
152#define FCNAME MPIDI_QUOTE(FUNCNAME)
153static int pkt_RTS_handler(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt, MPIDI_msg_sz_t *buflen, MPID_Request **rreqp)
154{
155    int mpi_errno = MPI_SUCCESS;
156    MPID_Request * rreq;
157    int found;
158    MPID_nem_pkt_lmt_rts_t * const rts_pkt = (MPID_nem_pkt_lmt_rts_t *)pkt;
159    char *data_buf;
160    MPIDI_msg_sz_t data_len;
161    MPIU_CHKPMEM_DECL(1);
162    MPIDI_STATE_DECL(MPID_STATE_PKT_RTS_HANDLER);
163
164    MPIDI_FUNC_ENTER(MPID_STATE_PKT_RTS_HANDLER);
165
166    MPIU_DBG_MSG_FMT(CH3_OTHER,VERBOSE,(MPIU_DBG_FDEST, "received LMT RTS pkt, sreq=0x%08x, rank=%d, tag=%d, context=%d, data_sz=" MPIDI_MSG_SZ_FMT,
167                                        rts_pkt->sender_req_id, rts_pkt->match.parts.rank, rts_pkt->match.parts.tag, rts_pkt->match.parts.context_id,
168                                        rts_pkt->data_sz));
169
170    rreq = MPIDI_CH3U_Recvq_FDP_or_AEU(&rts_pkt->match, &found);
171    MPIU_ERR_CHKANDJUMP1(!rreq, mpi_errno,MPI_ERR_OTHER, "**nomemreq", "**nomemuereq %d", MPIDI_CH3U_Recvq_count_unexp());
172
173    set_request_info(rreq, rts_pkt, MPIDI_REQUEST_RNDV_MSG);
174
175    rreq->ch.lmt_req_id = rts_pkt->sender_req_id;
176    rreq->ch.lmt_data_sz = rts_pkt->data_sz;
177
178    data_len = *buflen - sizeof(MPIDI_CH3_Pkt_t);
179    data_buf = (char *)pkt + sizeof(MPIDI_CH3_Pkt_t);
180
181
182
183    if (data_len < rts_pkt->cookie_len)
184    {
185        /* set for the cookie to be received into the tmp_cookie in the request */
186        MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"haven't received entire cookie");
187        MPIU_CHKPMEM_MALLOC(rreq->ch.lmt_tmp_cookie.MPID_IOV_BUF, char *, rts_pkt->cookie_len, mpi_errno, "tmp cookie buf");
188        rreq->ch.lmt_tmp_cookie.MPID_IOV_LEN = rts_pkt->cookie_len;
189
190        rreq->dev.iov[0] = rreq->ch.lmt_tmp_cookie;
191        rreq->dev.iov_count = 1;
192        *rreqp = rreq;
193        *buflen = sizeof(MPIDI_CH3_Pkt_t);
194
195        if (found)
196        {
197            /* set do_cts() to be called once we've received the entire cookie */
198            MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"posted request found");
199            rreq->dev.OnDataAvail = do_cts;
200        }
201        else
202        {
203            /* receive the rest of the cookie and wait for a match */
204            MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"unexpected request allocated");
205            rreq->dev.OnDataAvail = 0;
206            MPIDI_CH3_Progress_signal_completion();
207        }
208    }
209    else
210    {
211        if (rts_pkt->cookie_len == 0)
212        {
213            /* there's no cookie to receive */
214            rreq->ch.lmt_tmp_cookie.MPID_IOV_LEN = 0;
215            rreq->dev.iov_count = 0;
216            *buflen = sizeof(MPIDI_CH3_Pkt_t);
217            *rreqp = NULL;
218        }
219        else
220        {
221            /* receive cookie into tmp_cookie in the request */
222            MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"received entire cookie");
223            MPIU_CHKPMEM_MALLOC(rreq->ch.lmt_tmp_cookie.MPID_IOV_BUF, char *, rts_pkt->cookie_len, mpi_errno, "tmp cookie buf");
224            rreq->ch.lmt_tmp_cookie.MPID_IOV_LEN = rts_pkt->cookie_len;
225       
226            MPIU_Memcpy(rreq->ch.lmt_tmp_cookie.MPID_IOV_BUF, data_buf, rts_pkt->cookie_len);
227            *buflen = sizeof(MPIDI_CH3_Pkt_t) + rts_pkt->cookie_len;
228            *rreqp = NULL;
229        }
230       
231        if (found)
232        {
233            /* have a matching request and the entire cookie (if any), call do_cts() */
234            int complete;
235            MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"posted request found");
236            mpi_errno = do_cts(vc, rreq, &complete);
237            if (mpi_errno) MPIU_ERR_POP(mpi_errno);
238            MPIU_Assert(complete);
239        }
240        else
241        {
242            MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"unexpected request allocated");
243            rreq->dev.OnDataAvail = 0;
244            MPIDI_CH3_Progress_signal_completion();
245        }
246
247    }
248
249   
250    MPIU_CHKPMEM_COMMIT();
251 fn_exit:
252    MPIDI_FUNC_EXIT(MPID_STATE_PKT_RTS_HANDLER);
253    return mpi_errno;
254 fn_fail:
255    MPIU_CHKPMEM_REAP();
256    goto fn_exit;
257}
258
259#undef FUNCNAME
260#define FUNCNAME pkt_CTS_handler
261#undef FCNAME
262#define FCNAME MPIDI_QUOTE(FUNCNAME)
263static int pkt_CTS_handler(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt, MPIDI_msg_sz_t *buflen, MPID_Request **rreqp)
264{
265    MPID_nem_pkt_lmt_cts_t * const cts_pkt = (MPID_nem_pkt_lmt_cts_t *)pkt;
266    MPID_Request *sreq;
267    MPID_Request *rts_sreq;
268    char *data_buf;
269    MPIDI_msg_sz_t data_len;
270    int mpi_errno = MPI_SUCCESS;
271    MPIU_CHKPMEM_DECL(1);
272    MPIDI_STATE_DECL(MPID_STATE_PKT_CTS_HANDLER);
273
274    MPIDI_FUNC_ENTER(MPID_STATE_PKT_CTS_HANDLER);
275
276    MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"received rndv CTS pkt");
277
278    data_len = *buflen - sizeof(MPIDI_CH3_Pkt_t);
279    data_buf = (char *)pkt + sizeof(MPIDI_CH3_Pkt_t);
280
281    MPID_Request_get_ptr(cts_pkt->sender_req_id, sreq);
282
283    sreq->ch.lmt_req_id = cts_pkt->receiver_req_id;
284    sreq->ch.lmt_data_sz = cts_pkt->data_sz;
285
286    /* Release the RTS request if one exists.
287       MPID_Request_fetch_and_clear_rts_sreq() needs to be atomic to
288       prevent cancel send from cancelling the wrong (future) request.
289       If MPID_Request_fetch_and_clear_rts_sreq() returns a NULL
290       rts_sreq, then MPID_Cancel_send() is responsible for releasing
291       the RTS request object. */
292    MPIDI_Request_fetch_and_clear_rts_sreq(sreq, &rts_sreq);
293    if (rts_sreq != NULL)
294        MPID_Request_release(rts_sreq);
295
296    if (cts_pkt->cookie_len != 0)
297    {
298        if (data_len >= cts_pkt->cookie_len)
299        {
300            /* if whole cookie has been received, start the send */
301            sreq->ch.lmt_tmp_cookie.MPID_IOV_BUF = data_buf;
302            sreq->ch.lmt_tmp_cookie.MPID_IOV_LEN = cts_pkt->cookie_len;
303            mpi_errno = ((MPIDI_CH3I_VC *)vc->channel_private)->lmt_start_send(vc, sreq, sreq->ch.lmt_tmp_cookie);
304            if (mpi_errno) MPIU_ERR_POP (mpi_errno);
305            sreq->ch.lmt_tmp_cookie.MPID_IOV_LEN = 0;
306            *buflen = sizeof(MPIDI_CH3_Pkt_t) + cts_pkt->cookie_len;
307            *rreqp = NULL;
308        }
309        else
310        {
311            /* create a recv req and set up to receive the cookie into the sreq's tmp_cookie */
312            MPID_Request *rreq;
313
314            MPIU_CHKPMEM_MALLOC(sreq->ch.lmt_tmp_cookie.MPID_IOV_BUF, char *, cts_pkt->cookie_len, mpi_errno, "tmp cookie buf");
315            sreq->ch.lmt_tmp_cookie.MPID_IOV_LEN = cts_pkt->cookie_len;
316
317            MPIDI_Request_create_rreq(rreq, mpi_errno, goto fn_fail);
318            /* FIXME:  where does this request get freed? */
319
320            rreq->dev.iov[0] = sreq->ch.lmt_tmp_cookie;
321            rreq->dev.iov_count = 1;
322            rreq->ch.lmt_req = sreq;
323            rreq->dev.OnDataAvail = do_send;
324            *buflen = sizeof(MPIDI_CH3_Pkt_t);
325            *rreqp = rreq;
326        }
327    }
328    else
329    {
330        MPID_IOV cookie = {0,0};
331        mpi_errno = ((MPIDI_CH3I_VC *)vc->channel_private)->lmt_start_send(vc, sreq, cookie);
332        if (mpi_errno) MPIU_ERR_POP (mpi_errno);
333        *buflen = sizeof(MPIDI_CH3_Pkt_t);
334        *rreqp = NULL;
335    }
336
337 fn_exit:
338    MPIU_CHKPMEM_COMMIT();
339    MPIDI_FUNC_EXIT(MPID_STATE_PKT_CTS_HANDLER);
340    return mpi_errno;
341 fn_fail:
342    MPIU_CHKPMEM_REAP();
343    goto fn_exit;
344}
345
346#undef FUNCNAME
347#define FUNCNAME pkt_DONE_handler
348#undef FCNAME
349#define FCNAME MPIDI_QUOTE(FUNCNAME)
350static int pkt_DONE_handler(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt, MPIDI_msg_sz_t *buflen, MPID_Request **rreqp)
351{
352    int mpi_errno = MPI_SUCCESS;
353    MPID_nem_pkt_lmt_done_t * const done_pkt = (MPID_nem_pkt_lmt_done_t *)pkt;
354    MPID_Request *req;
355    MPIDI_STATE_DECL(MPID_STATE_PKT_DONE_HANDLER);
356
357    MPIDI_FUNC_ENTER(MPID_STATE_PKT_DONE_HANDLER);
358
359    *buflen = sizeof(MPIDI_CH3_Pkt_t);
360    MPID_Request_get_ptr(done_pkt->req_id, req);
361
362    switch (MPIDI_Request_get_type(req))
363    {
364    case MPIDI_REQUEST_TYPE_RECV:
365        mpi_errno = ((MPIDI_CH3I_VC *)vc->channel_private)->lmt_done_recv(vc, req);
366        if (mpi_errno) MPIU_ERR_POP(mpi_errno);
367        break;
368    case MPIDI_REQUEST_TYPE_SEND:
369        mpi_errno = ((MPIDI_CH3I_VC *)vc->channel_private)->lmt_done_send(vc, req);
370        if (mpi_errno) MPIU_ERR_POP(mpi_errno);
371        break;
372    default:
373        MPIU_ERR_SETANDJUMP1(mpi_errno, MPI_ERR_OTHER, "**intern", "**intern %s", "unexpected request type");
374        break;
375    }
376
377    *rreqp = NULL;
378
379 fn_exit:
380    MPIDI_FUNC_EXIT(MPID_STATE_PKT_DONE_HANDLER);
381    return mpi_errno;
382 fn_fail:
383    goto fn_exit;
384}
385
386#undef FUNCNAME
387#define FUNCNAME pkt_COOKIE_handler
388#undef FCNAME
389#define FCNAME MPIDI_QUOTE(FUNCNAME)
390static int pkt_COOKIE_handler(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt, MPIDI_msg_sz_t *buflen, MPID_Request **rreqp)
391{
392    int mpi_errno = MPI_SUCCESS;
393    MPID_nem_pkt_lmt_cookie_t * const cookie_pkt = (MPID_nem_pkt_lmt_cookie_t *)pkt;
394    MPID_Request *req;
395    char *data_buf;
396    MPIDI_msg_sz_t data_len;
397    MPIU_CHKPMEM_DECL(1);
398    MPIDI_STATE_DECL(MPID_STATE_PKT_COOKIE_HANDLER);
399
400    MPIDI_FUNC_ENTER(MPID_STATE_PKT_COOKIE_HANDLER);
401
402    data_len = *buflen - sizeof(MPIDI_CH3_Pkt_t);
403    data_buf = (char *)pkt + sizeof(MPIDI_CH3_Pkt_t);
404
405    if (cookie_pkt->from_sender) {
406        MPID_Request_get_ptr(cookie_pkt->receiver_req_id, req);
407        req->ch.lmt_req_id = cookie_pkt->sender_req_id;
408    }
409    else {
410        MPID_Request_get_ptr(cookie_pkt->sender_req_id, req);
411        req->ch.lmt_req_id = cookie_pkt->receiver_req_id;
412    }
413    MPIU_Assert(req != NULL);
414
415    if (cookie_pkt->cookie_len != 0)
416    {
417        if (data_len >= cookie_pkt->cookie_len)
418        {
419            /* call handle cookie with cookie data in receive buffer */
420            MPID_IOV cookie;
421
422            cookie.MPID_IOV_BUF = data_buf;
423            cookie.MPID_IOV_LEN = cookie_pkt->cookie_len;
424            mpi_errno = ((MPIDI_CH3I_VC *)vc->channel_private)->lmt_handle_cookie(vc, req, cookie);
425            if (mpi_errno) MPIU_ERR_POP(mpi_errno);
426
427            *rreqp = NULL;
428            *buflen = sizeof(MPIDI_CH3_Pkt_t) + cookie_pkt->cookie_len;
429        }
430        else
431        {
432            /* create a recv req and set up to receive the cookie into the rreq's tmp_cookie */
433            MPID_Request *rreq;
434
435            MPIDI_Request_create_rreq(rreq, mpi_errno, goto fn_fail);
436            MPIU_CHKPMEM_MALLOC(rreq->ch.lmt_tmp_cookie.MPID_IOV_BUF, char *, cookie_pkt->cookie_len, mpi_errno, "tmp cookie buf");
437            /* FIXME:  where does this request get freed? */
438            rreq->ch.lmt_tmp_cookie.MPID_IOV_LEN = cookie_pkt->cookie_len;
439
440            rreq->dev.iov[0] = rreq->ch.lmt_tmp_cookie;
441            rreq->dev.iov_count = 1;
442            rreq->ch.lmt_req = req;
443            rreq->dev.OnDataAvail = do_cookie;
444            *rreqp = rreq;
445            *buflen = sizeof(MPIDI_CH3_Pkt_t);
446        }
447    }
448    else
449    {
450        MPID_IOV cookie = {0,0};
451
452        mpi_errno = ((MPIDI_CH3I_VC *)vc->channel_private)->lmt_handle_cookie(vc, req, cookie);
453        if (mpi_errno) MPIU_ERR_POP(mpi_errno);
454        *buflen = sizeof(MPIDI_CH3_Pkt_t);
455        *rreqp = NULL;
456    }
457
458 fn_exit:
459    MPIU_CHKPMEM_COMMIT();
460    MPIDI_FUNC_EXIT(MPID_STATE_PKT_COOKIE_HANDLER);
461    return mpi_errno;
462 fn_fail:
463    MPIU_CHKPMEM_REAP();
464    goto fn_exit;
465}
466
467
468#undef FUNCNAME
469#define FUNCNAME do_cts
470#undef FCNAME
471#define FCNAME MPIDI_QUOTE(FUNCNAME)
472static int do_cts(MPIDI_VC_t *vc, MPID_Request *rreq, int *complete)
473{
474    int mpi_errno = MPI_SUCCESS;
475    MPIDI_msg_sz_t data_sz;
476    int dt_contig;
477    MPI_Aint dt_true_lb;
478    MPID_Datatype * dt_ptr;
479    MPID_IOV s_cookie;
480    MPIDI_STATE_DECL(MPID_STATE_DO_CTS);
481
482    MPIDI_FUNC_ENTER(MPID_STATE_DO_CTS);
483
484    MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"posted request found");
485
486    /* determine amount of data to be transfered and check for truncation */
487    MPIDI_Datatype_get_info(rreq->dev.user_count, rreq->dev.datatype, dt_contig, data_sz, dt_ptr, dt_true_lb);
488    if (rreq->ch.lmt_data_sz > data_sz)
489    {
490        MPIU_ERR_SET2(rreq->status.MPI_ERROR, MPI_ERR_TRUNCATE, "**truncate", "**truncate %d %d", rreq->ch.lmt_data_sz, data_sz);
491        rreq->ch.lmt_data_sz = data_sz;
492    }
493
494    s_cookie = rreq->ch.lmt_tmp_cookie;
495
496    mpi_errno = ((MPIDI_CH3I_VC *)vc->channel_private)->lmt_start_recv(vc, rreq, s_cookie);
497    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
498
499    /* free cookie buffer allocated in RTS handler */
500    if (rreq->ch.lmt_tmp_cookie.MPID_IOV_LEN)
501    {
502        MPIU_Free(rreq->ch.lmt_tmp_cookie.MPID_IOV_BUF);
503        rreq->ch.lmt_tmp_cookie.MPID_IOV_LEN = 0;
504    }
505
506    *complete = TRUE;
507
508 fn_exit:
509    MPIDI_FUNC_EXIT(MPID_STATE_DO_CTS);
510    return mpi_errno;
511 fn_fail:
512    goto fn_exit;
513}
514
515#undef FUNCNAME
516#define FUNCNAME do_send
517#undef FCNAME
518#define FCNAME MPIDI_QUOTE(FUNCNAME)
519static int do_send(MPIDI_VC_t *vc, MPID_Request *rreq, int *complete)
520{
521    int mpi_errno = MPI_SUCCESS;
522    MPID_IOV r_cookie;
523    MPID_Request * const sreq = rreq->ch.lmt_req;
524    MPIDI_STATE_DECL(MPID_STATE_DO_SEND);
525
526    MPIDI_FUNC_ENTER(MPID_STATE_DO_SEND);
527
528    r_cookie = sreq->ch.lmt_tmp_cookie;
529
530    mpi_errno = ((MPIDI_CH3I_VC *)vc->channel_private)->lmt_start_send(vc, sreq, r_cookie);
531    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
532
533    /* free cookie buffer allocated in CTS handler */
534    MPIU_Free(sreq->ch.lmt_tmp_cookie.MPID_IOV_BUF);
535    sreq->ch.lmt_tmp_cookie.MPID_IOV_LEN = 0;
536
537    *complete = TRUE;
538
539 fn_exit:
540    MPIDI_FUNC_EXIT(MPID_STATE_DO_SEND);
541    return mpi_errno;
542 fn_fail:
543    goto fn_exit;
544}
545
546#undef FUNCNAME
547#define FUNCNAME do_cookie
548#undef FCNAME
549#define FCNAME MPIDI_QUOTE(FUNCNAME)
550static int do_cookie(MPIDI_VC_t *vc, MPID_Request *rreq, int *complete)
551{
552    int mpi_errno = MPI_SUCCESS;
553    MPID_IOV cookie;
554    MPID_Request *req = rreq->ch.lmt_req;
555    MPIDI_STATE_DECL(MPID_STATE_DO_COOKIE);
556
557    MPIDI_FUNC_ENTER(MPID_STATE_DO_COOKIE);
558
559    cookie = req->ch.lmt_tmp_cookie;
560
561    mpi_errno = ((MPIDI_CH3I_VC *)vc->channel_private)->lmt_handle_cookie(vc, req, cookie);
562    if (mpi_errno) MPIU_ERR_POP (mpi_errno);
563
564    /* free cookie buffer allocated in COOKIE handler */
565    MPIU_Free(req->ch.lmt_tmp_cookie.MPID_IOV_BUF);
566    req->ch.lmt_tmp_cookie.MPID_IOV_LEN = 0;
567
568    *complete = TRUE;
569
570 fn_exit:
571    MPIDI_FUNC_EXIT(MPID_STATE_DO_COOKIE);
572    return mpi_errno;
573 fn_fail:
574    goto fn_exit;
575}
Note: See TracBrowser for help on using the browser.