ptl_poll.c 7 KB
Newer Older
1
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2
3
4
5
6
/*
 *  (C) 2012 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

7
#include "ptl_impl.h"
8
#include "rptl.h"
9

10
#define OVERFLOW_LENGTH (1024*1024)
11
#define NUM_OVERFLOW_ME 8
12
13
14
15
16
17

static ptl_handle_me_t overflow_me_handle[NUM_OVERFLOW_ME];
static void *overflow_buf[NUM_OVERFLOW_ME];

static int append_overflow(int i);

18
#undef FUNCNAME
19
#define FUNCNAME MPID_nem_ptl_poll_init
20
21
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
22
int MPID_nem_ptl_poll_init(void)
23
24
25
{
    int mpi_errno = MPI_SUCCESS;
    int i;
26
    MPIU_CHKPMEM_DECL(NUM_OVERFLOW_ME);
27
    MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_POLL_INIT);
28

29
    MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_POLL_INIT);
30

31
32
33
34
35
36
37
    /* create overflow buffers */
    for (i = 0; i < NUM_OVERFLOW_ME; ++i) {
        MPIU_CHKPMEM_MALLOC(overflow_buf[i], void *, OVERFLOW_LENGTH, mpi_errno, "overflow buffer");
        mpi_errno = append_overflow(i);
        if (mpi_errno) MPIU_ERR_POP(mpi_errno);
    }
    
38
 fn_exit:
39
40
    MPIU_CHKPMEM_COMMIT();
 fn_exit2:
41
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_PTL_POLL_INIT);
42
43
    return mpi_errno;
 fn_fail:
44
45
    MPIU_CHKPMEM_REAP();
    goto fn_exit2;
46
47
48
49
50
}



#undef FUNCNAME
51
#define FUNCNAME MPID_nem_ptl_poll_finalize
52
53
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
54
int MPID_nem_ptl_poll_finalize(void)
55
56
57
58
{
    int mpi_errno = MPI_SUCCESS;
    int i;
    int ret;
59
    MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_POLL_FINALIZE);
60

61
    MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_POLL_FINALIZE);
62
    
63
    for (i = 0; i < NUM_OVERFLOW_ME; ++i) {
64
65
        if (overflow_me_handle[i] != PTL_INVALID_HANDLE) {
            ret = PtlMEUnlink(overflow_me_handle[i]);
66
            MPIU_ERR_CHKANDJUMP1(ret, mpi_errno, MPI_ERR_OTHER, "**ptlmeunlink", "**ptlmeunlink %s", MPID_nem_ptl_strerror(ret));
67
        }
68
69
        MPIU_Free(overflow_buf[i]);
    }
70
    
71
 fn_exit:
72
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_PTL_POLL_FINALIZE);
73
74
75
76
77
    return mpi_errno;
 fn_fail:
    goto fn_exit;
}

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#undef FUNCNAME
#define FUNCNAME append_overflow
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
static int append_overflow(int i)
{
    int mpi_errno = MPI_SUCCESS;
    int ret;
    ptl_me_t me;
    ptl_process_t id_any;
    MPIDI_STATE_DECL(MPID_STATE_APPEND_OVERFLOW);

    MPIDI_FUNC_ENTER(MPID_STATE_APPEND_OVERFLOW);

    MPIU_Assert(i >= 0 && i < NUM_OVERFLOW_ME);
    
    id_any.phys.pid = PTL_PID_ANY;
    id_any.phys.nid = PTL_NID_ANY;

    me.start = overflow_buf[i];
    me.length = OVERFLOW_LENGTH;
    me.ct_handle = PTL_CT_NONE;
    me.uid = PTL_UID_ANY;
    me.options = ( PTL_ME_OP_PUT | PTL_ME_MANAGE_LOCAL | PTL_ME_NO_TRUNCATE | PTL_ME_MAY_ALIGN |
102
                   PTL_ME_IS_ACCESSIBLE | PTL_ME_EVENT_LINK_DISABLE );
103
104
105
106
107
108
109
    me.match_id = id_any;
    me.match_bits = 0;
    me.ignore_bits = ~((ptl_match_bits_t)0);
    me.min_free = PTL_MAX_EAGER;
    
    ret = PtlMEAppend(MPIDI_nem_ptl_ni, MPIDI_nem_ptl_pt, &me, PTL_OVERFLOW_LIST, (void *)(size_t)i,
                      &overflow_me_handle[i]);
110
    MPIU_ERR_CHKANDJUMP1(ret, mpi_errno, MPI_ERR_OTHER, "**ptlmeappend", "**ptlmeappend %s", MPID_nem_ptl_strerror(ret));
111
112
113
114
115
116
117
118
119

 fn_exit:
    MPIDI_FUNC_EXIT(MPID_STATE_APPEND_OVERFLOW);
    return mpi_errno;
 fn_fail:
    goto fn_exit;
}


120
#undef FUNCNAME
121
#define FUNCNAME MPID_nem_ptl_poll
122
123
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
124
int MPID_nem_ptl_poll(int is_blocking_poll)
125
126
127
128
{
    int mpi_errno = MPI_SUCCESS;
    ptl_event_t event;
    int ret;
129
    MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_POLL);
130

131
    /* MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_POLL); */
132
133

    while (1) {
134
135
        /* check EQs for events */
        ret = MPID_nem_ptl_rptl_eqget(MPIDI_nem_ptl_eq, &event);
136
        MPIU_ERR_CHKANDJUMP(ret == PTL_EQ_DROPPED, mpi_errno, MPI_ERR_OTHER, "**eqdropped");
137
        if (ret == PTL_EQ_EMPTY) {
138
            ret = MPID_nem_ptl_rptl_eqget(MPIDI_nem_ptl_get_eq, &event);
139
140
            MPIU_ERR_CHKANDJUMP(ret == PTL_EQ_DROPPED, mpi_errno, MPI_ERR_OTHER, "**eqdropped");

141
142
143
144
145
146
147
148
149
150
151
152
153
            if (ret == PTL_EQ_EMPTY) {
                ret = MPID_nem_ptl_rptl_eqget(MPIDI_nem_ptl_control_eq, &event);
                MPIU_ERR_CHKANDJUMP(ret == PTL_EQ_DROPPED, mpi_errno, MPI_ERR_OTHER, "**eqdropped");

                if (ret == PTL_EQ_EMPTY) {
                    ret = MPID_nem_ptl_rptl_eqget(MPIDI_nem_ptl_origin_eq, &event);
                    MPIU_ERR_CHKANDJUMP(ret == PTL_EQ_DROPPED, mpi_errno, MPI_ERR_OTHER, "**eqdropped");
                }

                /* all EQs are empty */
                if (ret == PTL_EQ_EMPTY)
                    break;
            }
154
        }
155
        MPIU_ERR_CHKANDJUMP1(ret, mpi_errno, MPI_ERR_OTHER, "**ptleqget", "**ptleqget %s", MPID_nem_ptl_strerror(ret));
Antonio J. Pena's avatar
Antonio J. Pena committed
156
157
158
        MPIU_DBG_MSG_FMT(CH3_CHANNEL, VERBOSE, (MPIU_DBG_FDEST, "Received event %s pt_idx=%d ni_fail=%s list=%s user_ptr=%p hdr_data=%#lx mlength=%lu rlength=%lu",
                                                MPID_nem_ptl_strevent(&event), event.pt_index, MPID_nem_ptl_strnifail(event.ni_fail_type),
                                                MPID_nem_ptl_strlist(event.ptl_list), event.user_ptr, event.hdr_data, event.mlength, event.rlength));
159
        MPIU_ERR_CHKANDJUMP2(event.ni_fail_type != PTL_NI_OK && event.ni_fail_type != PTL_NI_NO_MATCH, mpi_errno, MPI_ERR_OTHER, "**ptlni_fail", "**ptlni_fail %s %s", MPID_nem_ptl_strevent(&event), MPID_nem_ptl_strnifail(event.ni_fail_type));
Antonio J. Pena's avatar
Antonio J. Pena committed
160

161
162
        switch (event.type) {
        case PTL_EVENT_PUT:
163
164
            if (event.ptl_list == PTL_OVERFLOW_LIST)
                break;
Antonio J. Pena's avatar
Antonio J. Pena committed
165
166
167
168
169
170
            if (event.pt_index == MPIDI_nem_ptl_control_pt) {
                mpi_errno = MPID_nem_ptl_nm_ctl_event_handler(&event);
                if (mpi_errno)
                    MPIU_ERR_POP(mpi_errno);
                break;
            }
171
        case PTL_EVENT_PUT_OVERFLOW:
172
        case PTL_EVENT_GET:
173
        case PTL_EVENT_SEND:
174
        case PTL_EVENT_REPLY:
175
        case PTL_EVENT_SEARCH: {
176
177
178
            MPID_Request * const req = event.user_ptr;
            MPIU_DBG_MSG_P(CH3_CHANNEL, VERBOSE, "req = %p", req);
            MPIU_DBG_MSG_P(CH3_CHANNEL, VERBOSE, "REQ_PTL(req)->event_handler = %p", REQ_PTL(req)->event_handler);
Antonio J. Pena's avatar
Antonio J. Pena committed
179
180
181
182
            if (REQ_PTL(req)->event_handler) {
                mpi_errno = REQ_PTL(req)->event_handler(&event);
                if (mpi_errno) MPIU_ERR_POP(mpi_errno);
            }
183
            break;
184
185
186
187
188
189
190
191
        }
        case PTL_EVENT_AUTO_FREE:
            mpi_errno = append_overflow((size_t)event.user_ptr);
            if (mpi_errno) MPIU_ERR_POP(mpi_errno);
            break;
        case PTL_EVENT_AUTO_UNLINK:
            overflow_me_handle[(size_t)event.user_ptr] = PTL_INVALID_HANDLE;
            break;
Antonio J. Pena's avatar
Antonio J. Pena committed
192
        case PTL_EVENT_LINK:
193
194
            /* ignore */
            break;
195
        case PTL_EVENT_ACK:
196
        default:
197
            MPIU_Error_printf("Received unexpected event type: %d %s", event.type, MPID_nem_ptl_strevent(&event));
198
199
200
            MPIU_ERR_INTERNALANDJUMP(mpi_errno, "Unexpected event type");
        }
    }
201
202

 fn_exit:
203
    /* MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_PTL_POLL); */
204
205
206
207
    return mpi_errno;
 fn_fail:
    goto fn_exit;
}