ptl_poll.c 7.11 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
    me.match_id = id_any;
    me.match_bits = 0;
    me.ignore_bits = ~((ptl_match_bits_t)0);
    me.min_free = PTL_MAX_EAGER;
    
108
    /* if there is no space to append the entry, process outstanding events and try again */
109
110
    ret = MPID_nem_ptl_me_append(MPIDI_nem_ptl_ni, MPIDI_nem_ptl_pt, &me, PTL_OVERFLOW_LIST, (void *)(size_t)i,
                                 &overflow_me_handle[i]);
111
    MPIU_ERR_CHKANDJUMP1(ret, mpi_errno, MPI_ERR_OTHER, "**ptlmeappend", "**ptlmeappend %s", MPID_nem_ptl_strerror(ret));
112
113
114
115
116
117
118
119
120

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


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

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

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

142
143
144
145
146
147
148
149
150
151
152
153
154
            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;
            }
155
        }
156
        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
157
158
159
        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));
160
        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
161

162
163
        switch (event.type) {
        case PTL_EVENT_PUT:
164
165
            if (event.ptl_list == PTL_OVERFLOW_LIST)
                break;
Antonio J. Pena's avatar
Antonio J. Pena committed
166
167
168
169
170
171
            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;
            }
172
        case PTL_EVENT_PUT_OVERFLOW:
173
        case PTL_EVENT_GET:
174
        case PTL_EVENT_SEND:
175
        case PTL_EVENT_REPLY:
176
        case PTL_EVENT_SEARCH: {
177
178
179
            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
180
181
182
183
            if (REQ_PTL(req)->event_handler) {
                mpi_errno = REQ_PTL(req)->event_handler(&event);
                if (mpi_errno) MPIU_ERR_POP(mpi_errno);
            }
184
            break;
185
186
187
188
189
190
191
192
        }
        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
193
        case PTL_EVENT_LINK:
194
195
            /* ignore */
            break;
196
        case PTL_EVENT_ACK:
197
        default:
198
            MPIU_Error_printf("Received unexpected event type: %d %s", event.type, MPID_nem_ptl_strevent(&event));
199
200
201
            MPIU_ERR_INTERNALANDJUMP(mpi_errno, "Unexpected event type");
        }
    }
202
203

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