root/mpich2/trunk/src/mpid/ch3/channels/nemesis/nemesis/include/mpid_nem_impl.h @ 4707

Revision 4707, 13.3 KB (checked in by buntinas, 5 months ago)

converted all uses of memcpy to the macro MPIU_Memcpy

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#ifndef MPID_NEM_IMPL_H
8#define MPID_NEM_IMPL_H
9
10#include "my_papi_defs.h"
11#include "mpidi_ch3_impl.h"
12#include "mpimem.h"
13#include "mpid_nem_net_module_defs.h"
14#include "mpid_nem_atomics.h"
15#include "mpid_nem_defs.h"
16#include "mpid_nem_fbox.h"
17#include "mpid_nem_nets.h"
18#include "mpid_nem_queue.h"
19#include "mpid_nem_generic_queue.h"
20#include "mpiu_os_wrappers.h"
21
22
23
24#define MPID_NEM__BYPASS_Q_MAX_VAL  ((MPID_NEM_MPICH2_DATA_LEN) - (sizeof(MPIDI_CH3_Pkt_t)))
25
26int MPIDI_CH3I_Seg_alloc(size_t len, void **ptr_p);
27int MPIDI_CH3I_Seg_commit(MPID_nem_seg_ptr_t memory, int num_local, int local_rank);
28int MPIDI_CH3I_Seg_destroy(void);
29int MPID_nem_check_alloc(int);
30int MPID_nem_mpich2_init (int ckpt_restart);
31int MPID_nem_mpich2_send_ckpt_marker (unsigned short wave, MPIDI_VC_t *vc, int *try_again);
32int MPID_nem_coll_barrier_init (void);
33int MPID_nem_send_iov(MPIDI_VC_t *vc, MPID_Request **sreq_ptr, MPID_IOV *iov, int n_iov);
34int MPID_nem_lmt_pkthandler_init(MPIDI_CH3_PktHandler_Fcn *pktArray[], int arraySize);
35int MPID_nem_register_initcomp_cb(int (* callback)(void));
36int MPID_nem_choose_netmod(void);
37
38#define MPID_nem_mpich2_release_fbox(cell) (MPID_nem_mem_region.mailboxes.in[(cell)->pkt.mpich2.source]->mpich2.flag.value = 0, \
39                                            MPI_SUCCESS)
40
41/* initialize shared-memory MPI_Barrier variables */
42int MPID_nem_barrier_vars_init (MPID_nem_barrier_vars_t *barrier_region);
43
44static inline int
45MPID_nem_islocked (MPID_nem_fbox_common_ptr_t pbox, int value, int count)
46{
47    while (pbox->flag.value != value && --count == 0);
48
49    return (pbox->flag.value != value);
50}
51
52/* Nemesis packets */
53
54typedef enum MPID_nem_pkt_type
55{
56    MPIDI_NEM_PKT_LMT_RTS = MPIDI_CH3_PKT_END_ALL+1,
57    MPIDI_NEM_PKT_LMT_CTS,
58    MPIDI_NEM_PKT_LMT_DONE,
59    MPIDI_NEM_PKT_LMT_COOKIE,
60    MPIDI_NEM_PKT_END   
61} MPID_nem_pkt_type_t;
62
63typedef struct MPID_nem_pkt_lmt_rts
64{
65    MPID_nem_pkt_type_t type;
66    MPIDI_Message_match match;
67    MPI_Request sender_req_id;
68    MPIDI_msg_sz_t data_sz;
69    MPIDI_msg_sz_t cookie_len;
70}
71MPID_nem_pkt_lmt_rts_t;
72
73typedef struct MPID_nem_pkt_lmt_cts
74{
75    MPID_nem_pkt_type_t type;
76    MPI_Request sender_req_id;
77    MPI_Request receiver_req_id;
78    MPIDI_msg_sz_t data_sz;
79    MPIDI_msg_sz_t cookie_len;
80}
81MPID_nem_pkt_lmt_cts_t;
82
83typedef struct MPID_nem_pkt_lmt_done
84{
85    MPID_nem_pkt_type_t type;
86    MPI_Request req_id;
87}
88MPID_nem_pkt_lmt_done_t;
89
90typedef struct MPID_nem_pkt_lmt_cookie
91{
92    MPID_nem_pkt_type_t type;
93    int from_sender;
94    MPI_Request sender_req_id;
95    MPI_Request receiver_req_id;
96    MPIDI_msg_sz_t cookie_len;
97}
98MPID_nem_pkt_lmt_cookie_t;
99
100typedef union MPIDI_CH3_nem_pkt
101{
102    MPID_nem_pkt_lmt_rts_t lmt_rts;
103    MPID_nem_pkt_lmt_cts_t lmt_cts;
104    MPID_nem_pkt_lmt_done_t lmt_done;
105    MPID_nem_pkt_lmt_cookie_t lmt_cookie;
106} MPIDI_CH3_nem_pkt_t;
107
108   
109
110/*  Macros for sending lmt messages from inside network modules.
111    These assume mpi_errno is declared and the fn_exit and fn_fail
112    labels are defined.
113*/
114
115#define MPID_nem_lmt_send_RTS(vc, rts_pkt, s_cookie_buf, s_cookie_len) do {                             \
116        MPID_Request *_rts_req;                                                                         \
117        MPID_IOV _iov[2];                                                                               \
118                                                                                                        \
119        MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending rndv RTS packet");                                      \
120        (rts_pkt)->cookie_len = (s_cookie_len);                                                         \
121                                                                                                        \
122        _iov[0].MPID_IOV_BUF = (MPID_IOV_BUF_CAST)(rts_pkt);                                            \
123        _iov[0].MPID_IOV_LEN = sizeof(*(rts_pkt));                                                      \
124        _iov[1].MPID_IOV_BUF = (MPID_IOV_BUF_CAST)(s_cookie_buf);                                       \
125        _iov[1].MPID_IOV_LEN = (s_cookie_len);                                                          \
126                                                                                                        \
127        MPIU_DBG_MSGPKT((vc), (rts_pkt)->match.parts.tag, (rts_pkt)->match.parts.context_id, (rts_pkt)->match.parts.rank, \
128                        (rts_pkt)->data_sz, "Rndv");                                                    \
129                                                                                                        \
130        mpi_errno = MPIDI_CH3_iStartMsgv((vc), _iov, ((s_cookie_len)) ? 2 : 1, &_rts_req);              \
131        /* --BEGIN ERROR HANDLING-- */                                                                  \
132        if (mpi_errno != MPI_SUCCESS)                                                                   \
133        {                                                                                               \
134            MPIU_Object_set_ref(_rts_req, 0);                                                           \
135            MPIDI_CH3_Request_destroy(_rts_req);                                                        \
136            MPIU_ERR_SETFATALANDJUMP(mpi_errno, MPI_ERR_OTHER, "**rtspkt");                             \
137        }                                                                                               \
138        /* --END ERROR HANDLING-- */                                                                    \
139        if (_rts_req != NULL)                                                                           \
140        {                                                                                               \
141            if (_rts_req->status.MPI_ERROR != MPI_SUCCESS)                                              \
142            {                                                                                           \
143                MPIU_Object_set_ref(_rts_req, 0);                                                       \
144                MPIDI_CH3_Request_destroy(_rts_req);                                                    \
145                mpi_errno = MPIR_Err_create_code(_rts_req->status.MPI_ERROR, MPIR_ERR_FATAL,            \
146                                                 FCNAME, __LINE__, MPI_ERR_OTHER, "**rtspkt", 0);       \
147                MPID_Request_release(_rts_req);                                                         \
148                goto fn_exit;                                                                           \
149            }                                                                                           \
150            MPID_Request_release(_rts_req);                                                             \
151        }                                                                                               \
152    } while (0)
153
154#define MPID_nem_lmt_send_CTS(vc, rreq, r_cookie_buf, r_cookie_len) do {                                \
155        MPIDI_CH3_Pkt_t _upkt;                                                                          \
156        MPID_nem_pkt_lmt_cts_t * const _cts_pkt = (MPID_nem_pkt_lmt_cts_t *)&_upkt;                     \
157        MPID_Request *_cts_req;                                                                         \
158        MPID_IOV _iov[2];                                                                               \
159                                                                                                        \
160        MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending rndv CTS packet");                                      \
161        MPIDI_Pkt_init(_cts_pkt, MPIDI_NEM_PKT_LMT_CTS);                                                \
162        _cts_pkt->sender_req_id = (rreq)->ch.lmt_req_id;                                                \
163        _cts_pkt->receiver_req_id = (rreq)->handle;                                                     \
164        _cts_pkt->cookie_len = (r_cookie_len);                                                          \
165        _cts_pkt->data_sz = (rreq)->ch.lmt_data_sz;                                                     \
166                                                                                                        \
167        _iov[0].MPID_IOV_BUF = (MPID_IOV_BUF_CAST)_cts_pkt;                                             \
168        _iov[0].MPID_IOV_LEN = sizeof(*_cts_pkt);                                                       \
169        _iov[1].MPID_IOV_BUF = (MPID_IOV_BUF_CAST)(r_cookie_buf);                                       \
170        _iov[1].MPID_IOV_LEN = (r_cookie_len);                                                          \
171                                                                                                        \
172        mpi_errno = MPIDI_CH3_iStartMsgv((vc), _iov, (r_cookie_len) ? 2 : 1, &_cts_req);                \
173        MPIU_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**ctspkt");                           \
174        if (_cts_req != NULL)                                                                           \
175        {                                                                                               \
176            MPIU_ERR_CHKANDJUMP(_cts_req->status.MPI_ERROR, mpi_errno, MPI_ERR_OTHER, "**ctspkt");      \
177            MPID_Request_release(_cts_req);                                                             \
178        }                                                                                               \
179    } while (0)   
180       
181#undef FUNCNAME
182#define FUNCNAME MPID_nem_lmt_send_COOKIE
183#undef FCNAME
184#define FCNAME MPIDI_QUOTE(FUNCNAME)
185static inline int MPID_nem_lmt_send_COOKIE(MPIDI_VC_t *vc, MPID_Request *req,
186                                           void *cookie_buf, MPI_Aint cookie_len)
187{
188    int mpi_errno = MPI_SUCCESS;
189    MPIDI_CH3_Pkt_t _upkt;
190    MPID_nem_pkt_lmt_cookie_t * const cookie_pkt = (MPID_nem_pkt_lmt_cookie_t *)&_upkt;
191    MPID_Request *cookie_req;
192    MPID_IOV iov[2];
193
194    MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending rndv COOKIE packet");
195    MPIDI_Pkt_init(cookie_pkt, MPIDI_NEM_PKT_LMT_COOKIE);
196    cookie_pkt->cookie_len = (cookie_len);
197
198    /* We need to send both handle IDs in case there was
199       no CTS message in this protocol. */
200    switch (MPIDI_Request_get_type(req)) {
201        case MPIDI_REQUEST_TYPE_RECV:
202            cookie_pkt->from_sender = FALSE;
203            cookie_pkt->sender_req_id = (req)->ch.lmt_req_id;
204            cookie_pkt->receiver_req_id = (req)->handle;
205            break;
206        case MPIDI_REQUEST_TYPE_SEND:
207            cookie_pkt->from_sender = TRUE;
208            cookie_pkt->sender_req_id = (req)->handle;
209            cookie_pkt->receiver_req_id = (req)->ch.lmt_req_id;
210            break;
211        default:
212            MPIU_ERR_SETANDJUMP1(mpi_errno, MPI_ERR_OTHER, "**intern", "**intern %s", "unexpected request type");
213            break;
214    }
215
216    iov[0].MPID_IOV_BUF = (MPID_IOV_BUF_CAST) cookie_pkt;
217    iov[0].MPID_IOV_LEN = sizeof(*cookie_pkt);
218    iov[1].MPID_IOV_BUF = cookie_buf;
219    iov[1].MPID_IOV_LEN = cookie_len;
220
221    mpi_errno = MPIDI_CH3_iStartMsgv(vc, iov, (cookie_len ? 2 : 1), &cookie_req);
222    MPIU_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**cookiepkt");
223    if (cookie_req != NULL)
224    {
225        MPIU_ERR_CHKANDJUMP(cookie_req->status.MPI_ERROR, mpi_errno, MPI_ERR_OTHER, "**cookiepkt");
226        MPID_Request_release(cookie_req);
227    }
228
229fn_fail:
230    return mpi_errno;
231}
232       
233#define MPID_nem_lmt_send_DONE(vc, rreq) do {                                                                   \
234        MPIDI_CH3_Pkt_t _upkt;                                                                                  \
235        MPID_nem_pkt_lmt_done_t * const _done_pkt = (MPID_nem_pkt_lmt_done_t *)&_upkt;                          \
236        MPID_Request *_done_req;                                                                                \
237                                                                                                                \
238        MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending rndv DONE packet");                                             \
239        MPIDI_Pkt_init(_done_pkt, MPIDI_NEM_PKT_LMT_DONE);                                                      \
240        _done_pkt->req_id = (rreq)->ch.lmt_req_id;                                                              \
241                                                                                                                \
242        mpi_errno = MPIDI_CH3_iStartMsg((vc), _done_pkt, sizeof(*_done_pkt), &_done_req);                        \
243        MPIU_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**donepkt");                                  \
244        if (_done_req != NULL)                                                                                  \
245        {                                                                                                       \
246            MPIU_ERR_CHKANDJUMP(_done_req->status.MPI_ERROR, mpi_errno, MPI_ERR_OTHER, "**donepkt");            \
247            MPID_Request_release(_done_req);                                                                    \
248        }                                                                                                       \
249    } while (0)   
250
251
252#endif /* MPID_NEM_IMPL_H */
Note: See TracBrowser for help on using the browser.