int ADD_SUFFIX(MPID_nem_ofi_iprobe_impl)(struct MPIDI_VC *vc, int source, int tag, MPIR_Comm * comm, int context_offset, int *flag, MPI_Status * status, MPIR_Request ** rreq_ptr) { int ret, mpi_errno = MPI_SUCCESS; fi_addr_t remote_proc = 0; uint64_t match_bits, mask_bits; size_t len; MPIR_Request rreq_s, *rreq; BEGIN_FUNC(FCNAME); if (rreq_ptr) { MPIDI_CH3I_NM_OFI_RC(MPID_nem_ofi_create_req(&rreq, 1)); rreq->kind = MPIR_REQUEST_KIND__RECV; *rreq_ptr = rreq; rreq->comm = comm; rreq->dev.match.parts.rank = source; rreq->dev.match.parts.tag = tag; rreq->dev.match.parts.context_id = comm->context_id; MPIR_Comm_add_ref(comm); } else { rreq = &rreq_s; rreq->dev.OnDataAvail = NULL; } REQ_OFI(rreq)->pack_buffer = NULL; REQ_OFI(rreq)->event_callback = ADD_SUFFIX(peek_callback); REQ_OFI(rreq)->match_state = PEEK_INIT; OFI_ADDR_INIT(source, vc, remote_proc); #if API_SET == API_SET_1 match_bits = init_recvtag(&mask_bits, comm->context_id + context_offset, source, tag); #elif API_SET == API_SET_2 match_bits = init_recvtag_2(&mask_bits, comm->context_id + context_offset, tag); #endif /* ------------------------------------------------------------------------- */ /* fi_recvmsg with FI_PEEK: */ /* Initiate a search for a match in the hardware or software queue. */ /* The search can complete immediately with -ENOMSG. */ /* I successful, libfabric will enqueue a context entry into the completion */ /* queue to make the search nonblocking. This code will poll until the */ /* entry is enqueued. */ /* ------------------------------------------------------------------------- */ msg_tagged_t msg; uint64_t msgflags = FI_PEEK; msg.msg_iov = NULL; msg.desc = NULL; msg.iov_count = 0; msg.addr = remote_proc; msg.tag = match_bits; msg.ignore = mask_bits; msg.context = (void *) &(REQ_OFI(rreq)->ofi_context); msg.data = 0; if(*flag == CLAIM_PEEK) msgflags|=FI_CLAIM; ret = fi_trecvmsg(gl_data.endpoint,&msg,msgflags); if(ret == -ENOMSG) { if (rreq_ptr) { MPIR_Request_free(rreq); *rreq_ptr = NULL; *flag = 0; } MPID_nem_ofi_poll(MPID_NONBLOCKING_POLL); goto fn_exit; } MPIR_ERR_CHKANDJUMP4((ret < 0), mpi_errno, MPI_ERR_OTHER, "**ofi_peek", "**ofi_peek %s %d %s %s", __SHORT_FILE__, __LINE__, FCNAME, fi_strerror(-ret)); while (PEEK_INIT == REQ_OFI(rreq)->match_state) MPID_nem_ofi_poll(MPID_BLOCKING_POLL); if (PEEK_NOT_FOUND == REQ_OFI(rreq)->match_state) { if (rreq_ptr) { MPIR_Request_free(rreq); *rreq_ptr = NULL; *flag = 0; } MPID_nem_ofi_poll(MPID_NONBLOCKING_POLL); goto fn_exit; } if (status != MPI_STATUS_IGNORE) *status = rreq->status; MPIR_Request_add_ref(rreq); *flag = 1; END_FUNC_RC(FCNAME); }
int MPID_nem_ofi_poll(int in_blocking_poll) { int complete = 0, mpi_errno = MPI_SUCCESS; ssize_t ret; cq_tagged_entry_t wc; cq_err_entry_t error; MPIDI_VC_t *vc; MPID_Request *req; req_fn reqFn; BEGIN_FUNC(FCNAME); do { /* ----------------------------------------------------- */ /* Poll the completion queue */ /* The strategy here is */ /* ret>0 successfull poll, events returned */ /* ret==0 empty poll, no events/no error */ /* ret<0, error, but some error instances should not */ /* cause MPI to terminate */ /* ----------------------------------------------------- */ ret = fi_cq_read(gl_data.cq, /* Tagged completion queue */ (void *) &wc, /* OUT: Tagged completion entry */ 1); /* Number of entries to poll */ if (ret > 0) { if (NULL != wc.op_context) { req = context_to_req(wc.op_context); if (REQ_OFI(req)->event_callback) { MPIDI_CH3I_NM_OFI_RC(REQ_OFI(req)->event_callback(&wc, req)); continue; } reqFn = req->dev.OnDataAvail; if (reqFn) { if (REQ_OFI(req)->pack_buffer) { MPIU_Free(REQ_OFI(req)->pack_buffer); } vc = REQ_OFI(req)->vc; complete = 0; MPIDI_CH3I_NM_OFI_RC(reqFn(vc, req, &complete)); continue; } else { MPIU_Assert(0); } } else { MPIU_Assert(0); } } else if (ret == -FI_EAGAIN) ; else if (ret < 0) { if (ret == -FI_EAVAIL) { ret = fi_cq_readerr(gl_data.cq, (void *) &error, 0); if (error.err == FI_ETRUNC) { /* ----------------------------------------------------- */ /* This error message should only be delivered on send */ /* events. We want to ignore truncation errors */ /* on the sender side, but complete the request anyway */ /* Other kinds of requests, this is fatal. */ /* ----------------------------------------------------- */ req = context_to_req(error.op_context); if (req->kind == MPID_REQUEST_SEND) { mpi_errno = REQ_OFI(req)->event_callback(NULL, req); } else if (req->kind == MPID_REQUEST_RECV) { mpi_errno = REQ_OFI(req)->event_callback(&wc, req); req->status.MPI_ERROR = MPI_ERR_TRUNCATE; req->status.MPI_TAG = error.tag; } else { mpi_errno = MPI_ERR_OTHER; } } else if (error.err == FI_ECANCELED) { req = context_to_req(error.op_context); MPIR_STATUS_SET_CANCEL_BIT(req->status, TRUE); } else { mpi_errno = MPI_ERR_OTHER; } } else { MPIR_ERR_CHKANDJUMP4(1, mpi_errno, MPI_ERR_OTHER, "**ofi_poll", "**ofi_poll %s %d %s %s", __SHORT_FILE__, __LINE__, FCNAME, fi_strerror(-ret)); } } } while (in_blocking_poll && (ret > 0)); END_FUNC_RC(FCNAME); }