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

Revision 4888, 13.8 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#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/* MPID_PKT_DECL_CAST(pkt_u_var, s_pkt_type, s_pkt_p_var)
110   To avoid strict aliasing warnings when doing something like:
111       pkt_t upkt;
112       rts_pkt_t * const rts_pkt = (rts_pkt_t *)&upkt;
113   this macro does the same but through a union.
114
115   pkt_u_var -- variable name of the packet union
116   s_pkt_type -- type of the sub-packet
117   s_pkt_p_var -- variable name of the sub-packet pointer
118 */
119#define MPID_PKT_DECL_CAST(pkt_u_var, s_pkt_type, s_pkt_p_var)  \
120    union                                                       \
121    {                                                           \
122        MPIDI_CH3_Pkt_t p;                                      \
123        s_pkt_type s;                                           \
124    } pkt_u_var;                                                \
125    s_pkt_type * const s_pkt_p_var = &pkt_u_var.s
126
127   
128
129/*  Macros for sending lmt messages from inside network modules.
130    These assume mpi_errno is declared and the fn_exit and fn_fail
131    labels are defined.
132*/
133
134#define MPID_nem_lmt_send_RTS(vc, rts_pkt, s_cookie_buf, s_cookie_len) do {                             \
135        MPID_Request *_rts_req;                                                                         \
136        MPID_IOV _iov[2];                                                                               \
137                                                                                                        \
138        MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending rndv RTS packet");                                      \
139        (rts_pkt)->cookie_len = (s_cookie_len);                                                         \
140                                                                                                        \
141        _iov[0].MPID_IOV_BUF = (MPID_IOV_BUF_CAST)(rts_pkt);                                            \
142        _iov[0].MPID_IOV_LEN = sizeof(*(rts_pkt));                                                      \
143        _iov[1].MPID_IOV_BUF = (MPID_IOV_BUF_CAST)(s_cookie_buf);                                       \
144        _iov[1].MPID_IOV_LEN = (s_cookie_len);                                                          \
145                                                                                                        \
146        MPIU_DBG_MSGPKT((vc), (rts_pkt)->match.parts.tag, (rts_pkt)->match.parts.context_id, (rts_pkt)->match.parts.rank, \
147                        (rts_pkt)->data_sz, "Rndv");                                                    \
148                                                                                                        \
149        mpi_errno = MPIDI_CH3_iStartMsgv((vc), _iov, ((s_cookie_len)) ? 2 : 1, &_rts_req);              \
150        /* --BEGIN ERROR HANDLING-- */                                                                  \
151        if (mpi_errno != MPI_SUCCESS)                                                                   \
152        {                                                                                               \
153            MPIU_Object_set_ref(_rts_req, 0);                                                           \
154            MPIDI_CH3_Request_destroy(_rts_req);                                                        \
155            MPIU_ERR_SETFATALANDJUMP(mpi_errno, MPI_ERR_OTHER, "**rtspkt");                             \
156        }                                                                                               \
157        /* --END ERROR HANDLING-- */                                                                    \
158        if (_rts_req != NULL)                                                                           \
159        {                                                                                               \
160            if (_rts_req->status.MPI_ERROR != MPI_SUCCESS)                                              \
161            {                                                                                           \
162                MPIU_Object_set_ref(_rts_req, 0);                                                       \
163                MPIDI_CH3_Request_destroy(_rts_req);                                                    \
164                mpi_errno = MPIR_Err_create_code(_rts_req->status.MPI_ERROR, MPIR_ERR_FATAL,            \
165                                                 FCNAME, __LINE__, MPI_ERR_OTHER, "**rtspkt", 0);       \
166                MPID_Request_release(_rts_req);                                                         \
167                goto fn_exit;                                                                           \
168            }                                                                                           \
169            MPID_Request_release(_rts_req);                                                             \
170        }                                                                                               \
171    } while (0)
172
173#define MPID_nem_lmt_send_CTS(vc, rreq, r_cookie_buf, r_cookie_len) do {                                \
174        MPID_PKT_DECL_CAST(_upkt, MPID_nem_pkt_lmt_cts_t, _cts_pkt);                                    \
175        MPID_Request *_cts_req;                                                                         \
176        MPID_IOV _iov[2];                                                                               \
177                                                                                                        \
178        MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending rndv CTS packet");                                      \
179        MPIDI_Pkt_init(_cts_pkt, MPIDI_NEM_PKT_LMT_CTS);                                                \
180        _cts_pkt->sender_req_id = (rreq)->ch.lmt_req_id;                                                \
181        _cts_pkt->receiver_req_id = (rreq)->handle;                                                     \
182        _cts_pkt->cookie_len = (r_cookie_len);                                                          \
183        _cts_pkt->data_sz = (rreq)->ch.lmt_data_sz;                                                     \
184                                                                                                        \
185        _iov[0].MPID_IOV_BUF = (MPID_IOV_BUF_CAST)_cts_pkt;                                             \
186        _iov[0].MPID_IOV_LEN = sizeof(*_cts_pkt);                                                       \
187        _iov[1].MPID_IOV_BUF = (MPID_IOV_BUF_CAST)(r_cookie_buf);                                       \
188        _iov[1].MPID_IOV_LEN = (r_cookie_len);                                                          \
189                                                                                                        \
190        mpi_errno = MPIDI_CH3_iStartMsgv((vc), _iov, (r_cookie_len) ? 2 : 1, &_cts_req);                \
191        MPIU_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**ctspkt");                           \
192        if (_cts_req != NULL)                                                                           \
193        {                                                                                               \
194            MPIU_ERR_CHKANDJUMP(_cts_req->status.MPI_ERROR, mpi_errno, MPI_ERR_OTHER, "**ctspkt");      \
195            MPID_Request_release(_cts_req);                                                             \
196        }                                                                                               \
197    } while (0)   
198       
199#undef FUNCNAME
200#define FUNCNAME MPID_nem_lmt_send_COOKIE
201#undef FCNAME
202#define FCNAME MPIDI_QUOTE(FUNCNAME)
203static inline int MPID_nem_lmt_send_COOKIE(MPIDI_VC_t *vc, MPID_Request *req,
204                                           void *cookie_buf, MPI_Aint cookie_len)
205{
206    int mpi_errno = MPI_SUCCESS;
207    MPID_PKT_DECL_CAST(_upkt, MPID_nem_pkt_lmt_cookie_t, cookie_pkt);
208    MPID_Request *cookie_req;
209    MPID_IOV iov[2];
210
211    MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending rndv COOKIE packet");
212    MPIDI_Pkt_init(cookie_pkt, MPIDI_NEM_PKT_LMT_COOKIE);
213    cookie_pkt->cookie_len = (cookie_len);
214
215    /* We need to send both handle IDs in case there was
216       no CTS message in this protocol. */
217    switch (MPIDI_Request_get_type(req)) {
218        case MPIDI_REQUEST_TYPE_RECV:
219            cookie_pkt->from_sender = FALSE;
220            cookie_pkt->sender_req_id = (req)->ch.lmt_req_id;
221            cookie_pkt->receiver_req_id = (req)->handle;
222            break;
223        case MPIDI_REQUEST_TYPE_SEND:
224            cookie_pkt->from_sender = TRUE;
225            cookie_pkt->sender_req_id = (req)->handle;
226            cookie_pkt->receiver_req_id = (req)->ch.lmt_req_id;
227            break;
228        default:
229            MPIU_ERR_SETANDJUMP1(mpi_errno, MPI_ERR_OTHER, "**intern", "**intern %s", "unexpected request type");
230            break;
231    }
232
233    iov[0].MPID_IOV_BUF = (MPID_IOV_BUF_CAST) cookie_pkt;
234    iov[0].MPID_IOV_LEN = sizeof(*cookie_pkt);
235    iov[1].MPID_IOV_BUF = cookie_buf;
236    iov[1].MPID_IOV_LEN = cookie_len;
237
238    mpi_errno = MPIDI_CH3_iStartMsgv(vc, iov, (cookie_len ? 2 : 1), &cookie_req);
239    MPIU_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**cookiepkt");
240    if (cookie_req != NULL)
241    {
242        MPIU_ERR_CHKANDJUMP(cookie_req->status.MPI_ERROR, mpi_errno, MPI_ERR_OTHER, "**cookiepkt");
243        MPID_Request_release(cookie_req);
244    }
245
246fn_fail:
247    return mpi_errno;
248}
249       
250#define MPID_nem_lmt_send_DONE(vc, rreq) do {                                                                   \
251        MPID_PKT_DECL_CAST(_upkt, MPID_nem_pkt_lmt_done_t, _done_pkt);                                          \
252        MPID_Request *_done_req;                                                                                \
253                                                                                                                \
254        MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending rndv DONE packet");                                             \
255        MPIDI_Pkt_init(_done_pkt, MPIDI_NEM_PKT_LMT_DONE);                                                      \
256        _done_pkt->req_id = (rreq)->ch.lmt_req_id;                                                              \
257                                                                                                                \
258        mpi_errno = MPIDI_CH3_iStartMsg((vc), _done_pkt, sizeof(*_done_pkt), &_done_req);                       \
259        MPIU_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**donepkt");                                  \
260        if (_done_req != NULL)                                                                                  \
261        {                                                                                                       \
262            MPIU_ERR_CHKANDJUMP(_done_req->status.MPI_ERROR, mpi_errno, MPI_ERR_OTHER, "**donepkt");            \
263            MPID_Request_release(_done_req);                                                                    \
264        }                                                                                                       \
265    } while (0)   
266
267
268#endif /* MPID_NEM_IMPL_H */
Note: See TracBrowser for help on using the browser.