1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 /* #include "mpidpre.h" */
7 #include "mpidi_ch3_impl.h"
8 #include "mpid_nem_impl.h"
9 #if defined (MPID_NEM_INLINE) && MPID_NEM_INLINE
10 #include "mpid_nem_inline.h"
11 #endif
12
MPIDI_CH3_iSend(MPIDI_VC_t * vc,MPIR_Request * sreq,void * hdr,intptr_t hdr_sz)13 int MPIDI_CH3_iSend (MPIDI_VC_t *vc, MPIR_Request *sreq, void * hdr, intptr_t hdr_sz)
14 {
15 int mpi_errno = MPI_SUCCESS;
16 int again = 0;
17 int in_cs = FALSE;
18 MPIR_FUNC_VERBOSE_STATE_DECL(MPID_STATE_MPIDI_CH3_ISEND);
19
20 MPIR_FUNC_VERBOSE_ENTER(MPID_STATE_MPIDI_CH3_ISEND);
21
22 if (vc->state == MPIDI_VC_STATE_MORIBUND) {
23 sreq->status.MPI_ERROR = MPI_SUCCESS;
24 MPIR_ERR_SET1(sreq->status.MPI_ERROR, MPIX_ERR_PROC_FAILED, "**comm_fail", "**comm_fail %d", vc->pg_rank);
25 MPID_Request_complete(sreq);
26 goto fn_fail;
27 }
28
29 if (vc->ch.iSendContig)
30 {
31 mpi_errno = vc->ch.iSendContig(vc, sreq, hdr, hdr_sz, NULL, 0);
32 if(mpi_errno != MPI_SUCCESS) { MPIR_ERR_POP(mpi_errno); }
33 goto fn_exit;
34 }
35
36 /* MPIR_Assert(vc->ch.is_local); */
37 MPIR_Assert(hdr_sz <= sizeof(MPIDI_CH3_Pkt_t));
38
39 /* This channel uses a fixed length header, the size of which
40 * is the maximum of all possible packet headers */
41 hdr_sz = sizeof(MPIDI_CH3_Pkt_t);
42 MPIDI_DBG_Print_packet((MPIDI_CH3_Pkt_t*)hdr);
43
44 MPID_THREAD_CS_ENTER(POBJ, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
45 in_cs = TRUE;
46
47 if (MPIDI_CH3I_Sendq_empty(MPIDI_CH3I_shm_sendq))
48 {
49 MPIR_Assert(hdr_sz <= INT_MAX);
50 MPL_DBG_MSG_D (MPIDI_CH3_DBG_CHANNEL, VERBOSE, "iSend %d", (int) hdr_sz);
51 mpi_errno = MPID_nem_mpich_send_header (hdr, (int)hdr_sz, vc, &again);
52 if (mpi_errno) MPIR_ERR_POP (mpi_errno);
53 if (again)
54 {
55 goto enqueue_it;
56 }
57 else
58 {
59 int (*reqFn)(MPIDI_VC_t *, MPIR_Request *, int *);
60
61 reqFn = sreq->dev.OnDataAvail;
62 if (!reqFn)
63 {
64 MPIR_Assert (MPIDI_Request_get_type (sreq) != MPIDI_REQUEST_TYPE_GET_RESP);
65 mpi_errno = MPID_Request_complete(sreq);
66 MPIR_ERR_CHECK(mpi_errno);
67 }
68 else
69 {
70 int complete = 0;
71 mpi_errno = reqFn (vc, sreq, &complete);
72 if (mpi_errno) MPIR_ERR_POP (mpi_errno);
73 }
74 }
75 }
76 else
77 {
78 goto enqueue_it;
79 }
80
81
82 fn_exit:
83 if (in_cs) {
84 MPID_THREAD_CS_EXIT(POBJ, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
85 }
86
87 MPIR_FUNC_VERBOSE_EXIT(MPID_STATE_MPIDI_CH3_ISEND);
88 return mpi_errno;
89 fn_fail:
90 goto fn_exit;
91
92 enqueue_it:
93 MPL_DBG_MSG(MPIDI_CH3_DBG_OTHER, TERSE, "enqueuing");
94
95 sreq->dev.pending_pkt = *(MPIDI_CH3_Pkt_t *) hdr;
96 sreq->dev.iov[0].iov_base = (char *) &sreq->dev.pending_pkt;
97 sreq->dev.iov[0].iov_len = hdr_sz;
98 sreq->dev.iov_count = 1;
99 sreq->dev.iov_offset = 0;
100 sreq->ch.noncontig = FALSE;
101 sreq->ch.vc = vc;
102
103 if (MPIDI_CH3I_Sendq_empty(MPIDI_CH3I_shm_sendq)) {
104 MPIDI_CH3I_Sendq_enqueue(&MPIDI_CH3I_shm_sendq, sreq);
105 } else {
106 /* this is not the first send on the queue, enqueue it then
107 check to see if we can send any now */
108 MPIDI_CH3I_Sendq_enqueue(&MPIDI_CH3I_shm_sendq, sreq);
109 mpi_errno = MPIDI_CH3I_Shm_send_progress();
110 MPIR_ERR_CHECK(mpi_errno);
111 }
112
113 goto fn_exit;
114 }
115
116