-:    0:Source:/home/MPI/testing/mpich2/mpich2/src/mpid/ch3/src/ch3u_eagersync.c
        -:    0:Graph:ch3u_eagersync.gcno
        -:    0:Data:ch3u_eagersync.gcda
        -:    0:Runs:4382
        -:    0:Programs:1376
        -:    1:
        -:    2:/* -*- Mode: C; c-basic-offset:4 ; -*- */
        -:    3:/*
        -:    4: *  (C) 2001 by Argonne National Laboratory.
        -:    5: *      See COPYRIGHT in top-level directory.
        -:    6: */
        -:    7:
        -:    8:#include "mpidimpl.h"
        -:    9:
        -:   10:/*
        -:   11: * Send a synchronous eager message.  This is an optimization that you
        -:   12: * may want to use for programs that make extensive use of MPI_Ssend and
        -:   13: * MPI_Issend for short messages.
        -:   14: */
        -:   15:
        -:   16:#undef FUNCNAME
        -:   17:#define FUNCNAME MPIDI_EagerSyncNoncontigSend
        -:   18:#undef FCNAME
        -:   19:#define FCNAME MPIDI_QUOTE(FUNCNAME)
        -:   20:/* MPIDI_CH3_EagerSyncNoncontigSend - Eagerly send noncontiguous data in
        -:   21:   synchronous mode.
        -:   22:
        -:   23:   Some implementations may choose to use Rendezvous sends (see ch3u_rndv.c)
        -:   24:   for all Synchronous sends (MPI_Issend and MPI_Ssend).  An eager 
        -:   25:   synchronous send eliminates one of the handshake messages, but 
        -:   26:   most application codes should not be using synchronous sends in
        -:   27:   performance-critical operations.
        -:   28:*/
        -:   29:int MPIDI_CH3_EagerSyncNoncontigSend( MPID_Request **sreq_p, 
        -:   30:				      const void * buf, int count, 
        -:   31:				      MPI_Datatype datatype, MPIDI_msg_sz_t data_sz, 
        -:   32:				      int dt_contig, MPI_Aint dt_true_lb,
        -:   33:				      int rank, 
        -:   34:				      int tag, MPID_Comm * comm, 
        -:   35:				      int context_offset )
    96891:   36:{
    96891:   37:    int mpi_errno = MPI_SUCCESS;
        -:   38:    MPIDI_CH3_Pkt_t upkt;
    96891:   39:    MPIDI_CH3_Pkt_eager_sync_send_t * const es_pkt = &upkt.eager_sync_send;
        -:   40:    MPIDI_VC_t * vc;
    96891:   41:    MPID_Request *sreq = *sreq_p;
        -:   42:    
    96891:   43:    sreq->cc = 2;
    96891:   44:    sreq->dev.OnDataAvail = 0;
    96891:   45:    sreq->dev.OnFinal = 0;
        -:   46:
    96891:   47:    MPIDI_Pkt_init(es_pkt, MPIDI_CH3_PKT_EAGER_SYNC_SEND);
    96891:   48:    es_pkt->match.parts.rank = comm->rank;
    96891:   49:    es_pkt->match.parts.tag = tag;
    96891:   50:    es_pkt->match.parts.context_id = comm->context_id + context_offset;
    96891:   51:    es_pkt->sender_req_id = sreq->handle;
    96891:   52:    es_pkt->data_sz = data_sz;
        -:   53:
    96891:   54:    MPIDI_Comm_get_vc_set_active(comm, rank, &vc);
        -:   55:    
        -:   56:    MPIDI_VC_FAI_send_seqnum(vc, seqnum);
        -:   57:    MPIDI_Pkt_set_seqnum(es_pkt, seqnum);
        -:   58:    MPIDI_Request_set_seqnum(sreq, seqnum);
        -:   59:    
        -:   60:    MPIU_DBG_MSGPKT(vc,tag,es_pkt->match.parts.context_id,rank,data_sz,"EagerSync");
        -:   61:
    96891:   62:    if (dt_contig)
        -:   63:    {
        -:   64:        MPID_IOV iov[2];
        -:   65:	MPIU_DBG_MSG_FMT(CH3_OTHER,VERBOSE,(MPIU_DBG_FDEST,
        -:   66:                                            "sending contiguous sync eager message, data_sz=" MPIDI_MSG_SZ_FMT, 
        -:   67:					    data_sz));
        -:   68:	
    85189:   69:        iov[0].MPID_IOV_BUF = (MPID_IOV_BUF_CAST)es_pkt;
    85189:   70:        iov[0].MPID_IOV_LEN = sizeof(*es_pkt);
    85189:   71:	iov[1].MPID_IOV_BUF = (MPID_IOV_BUF_CAST) ((char *)buf + dt_true_lb);
    85189:   72:	iov[1].MPID_IOV_LEN = data_sz;	
        -:   73:	
        -:   74:	MPIU_THREAD_CS_ENTER(CH3COMM,vc);
    85189:   75:	mpi_errno = MPIU_CALL(MPIDI_CH3,iSendv(vc, sreq, iov, 2));
        -:   76:	MPIU_THREAD_CS_EXIT(CH3COMM,vc);
        -:   77:	/* --BEGIN ERROR HANDLING-- */
    85189:   78:	if (mpi_errno != MPI_SUCCESS)
        -:   79:	{
    #####:   80:	    MPIU_Object_set_ref(sreq, 0);
    #####:   81:	    MPIDI_CH3_Request_destroy(sreq);
    #####:   82:	    *sreq_p = NULL;
    #####:   83:	    mpi_errno = MPIR_Err_create_code(mpi_errno, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**ch3|eagermsg", 0);
    #####:   84:	    goto fn_fail;
        -:   85:	}
        -:   86:	/* --END ERROR HANDLING-- */
        -:   87:    }
        -:   88:    else
        -:   89:    {
        -:   90:	MPIU_DBG_MSG_D(CH3_OTHER,VERBOSE,
        -:   91:		       "sending non-contiguous sync eager message, data_sz=" MPIDI_MSG_SZ_FMT, 
        -:   92:		       data_sz);
        -:   93:	
    11702:   94:	sreq->dev.segment_ptr = MPID_Segment_alloc( );
    11702:   95:        MPIU_ERR_CHKANDJUMP1((sreq->dev.segment_ptr == NULL), mpi_errno, MPI_ERR_OTHER, "**nomem", "**nomem %s", "MPID_Segment_alloc");
        -:   96:
    11702:   97:	MPID_Segment_init(buf, count, datatype, sreq->dev.segment_ptr, 0);
    11702:   98:	sreq->dev.segment_first = 0;
    11702:   99:	sreq->dev.segment_size = data_sz;
        -:  100:	
        -:  101:	MPIU_THREAD_CS_ENTER(CH3COMM,vc);
    11702:  102:        mpi_errno = vc->sendNoncontig_fn(vc, sreq, es_pkt, sizeof(MPIDI_CH3_Pkt_eager_sync_send_t));
        -:  103:	MPIU_THREAD_CS_EXIT(CH3COMM,vc);
    11702:  104:        if (mpi_errno) MPIU_ERR_POP(mpi_errno);
        -:  105:    }
        -:  106:
    96891:  107: fn_exit:
    96891:  108:    return mpi_errno;
    #####:  109: fn_fail:
    #####:  110:    *sreq_p = NULL;
    #####:  111:    goto fn_exit;
        -:  112:}
        -:  113:
        -:  114:/* Send a zero-sized message with eager synchronous.  This is a temporary
        -:  115:   routine, as we may want to replace this with a counterpart to the
        -:  116:   Eager Short message */
        -:  117:int MPIDI_CH3_EagerSyncZero(MPID_Request **sreq_p, int rank, int tag, 
        -:  118:			    MPID_Comm * comm, int context_offset )
   363688:  119:{
   363688:  120:    int mpi_errno = MPI_SUCCESS;
        -:  121:    MPIDI_CH3_Pkt_t upkt;
   363688:  122:    MPIDI_CH3_Pkt_eager_sync_send_t * const es_pkt = &upkt.eager_sync_send;
        -:  123:    MPIDI_VC_t * vc;
   363688:  124:    MPID_Request *sreq = *sreq_p;
        -:  125:    
        -:  126:    MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending zero length message");
        -:  127:    
   363688:  128:    sreq->cc = 2;
   363688:  129:    MPIDI_Request_set_msg_type(sreq, MPIDI_REQUEST_EAGER_MSG);
   363688:  130:    sreq->dev.OnDataAvail = 0;
        -:  131:    
   363688:  132:    MPIDI_Pkt_init(es_pkt, MPIDI_CH3_PKT_EAGER_SYNC_SEND);
   363688:  133:    es_pkt->match.parts.rank = comm->rank;
   363688:  134:    es_pkt->match.parts.tag = tag;
   363688:  135:    es_pkt->match.parts.context_id = comm->context_id + context_offset;
   363688:  136:    es_pkt->sender_req_id = sreq->handle;
   363688:  137:    es_pkt->data_sz = 0;
        -:  138:    
   363688:  139:    MPIDI_Comm_get_vc_set_active(comm, rank, &vc);
        -:  140:    MPIDI_VC_FAI_send_seqnum(vc, seqnum);
        -:  141:    MPIDI_Pkt_set_seqnum(es_pkt, seqnum);
        -:  142:    MPIDI_Request_set_seqnum(sreq, seqnum);
        -:  143:    
        -:  144:    MPIU_DBG_MSGPKT(vc,tag,es_pkt->match.parts.context_id,rank,(MPIDI_msg_sz_t)0,"EagerSync0");
        -:  145:    MPIU_THREAD_CS_ENTER(CH3COMM,vc);
   363688:  146:    mpi_errno = MPIU_CALL(MPIDI_CH3,iSend(vc, sreq, es_pkt, sizeof(*es_pkt)));
        -:  147:    MPIU_THREAD_CS_EXIT(CH3COMM,vc);
        -:  148:    /* --BEGIN ERROR HANDLING-- */
   363688:  149:    if (mpi_errno != MPI_SUCCESS)
        -:  150:    {
    #####:  151:	MPIU_Object_set_ref(sreq, 0);
    #####:  152:	MPIDI_CH3_Request_destroy(sreq);
    #####:  153:	*sreq_p = NULL;
    #####:  154:	mpi_errno = MPIR_Err_create_code(mpi_errno, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**ch3|eagermsg", 0);
    #####:  155:	goto fn_exit;
        -:  156:    }
        -:  157:    /* --END ERROR HANDLING-- */
        -:  158:
   363688:  159: fn_exit:
   363688:  160:    return mpi_errno;
        -:  161:}
        -:  162:
        -:  163:/* 
        -:  164: * These routines are called when a receive matches an eager sync send 
        -:  165: */
        -:  166:int MPIDI_CH3_EagerSyncAck( MPIDI_VC_t *vc, MPID_Request *rreq )
    15484:  167:{
    15484:  168:    int mpi_errno = MPI_SUCCESS;
        -:  169:    MPIDI_CH3_Pkt_t upkt;
    15484:  170:    MPIDI_CH3_Pkt_eager_sync_ack_t * const esa_pkt = &upkt.eager_sync_ack;
        -:  171:    MPID_Request * esa_req;
        -:  172:    
        -:  173:    MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending eager sync ack");
    15484:  174:    MPIDI_Pkt_init(esa_pkt, MPIDI_CH3_PKT_EAGER_SYNC_ACK);
    15484:  175:    esa_pkt->sender_req_id = rreq->dev.sender_req_id;
        -:  176:    MPIU_THREAD_CS_ENTER(CH3COMM,vc);
    15484:  177:    mpi_errno = MPIU_CALL(MPIDI_CH3,iStartMsg(vc, esa_pkt, sizeof(*esa_pkt), 
        -:  178:					      &esa_req));
        -:  179:    MPIU_THREAD_CS_EXIT(CH3COMM,vc);
    15484:  180:    if (mpi_errno != MPI_SUCCESS) {
    #####:  181:	MPIU_ERR_POP(mpi_errno);
        -:  182:    }
    15484:  183:    if (esa_req != NULL)
        -:  184:    {
    #####:  185:	MPID_Request_release(esa_req);
        -:  186:    }
    15484:  187: fn_fail:
    15484:  188:    return mpi_errno;
        -:  189:}
        -:  190:
        -:  191:/* 
        -:  192: * Here are the routines that are called by the progress engine to handle
        -:  193: * the various rendezvous message requests (cancel of sends is in 
        -:  194: * mpid_cancel_send.c).
        -:  195: */    
        -:  196:
        -:  197:#define set_request_info(rreq_, pkt_, msg_type_)		\
        -:  198:{								\
        -:  199:    (rreq_)->status.MPI_SOURCE = (pkt_)->match.parts.rank;	\
        -:  200:    (rreq_)->status.MPI_TAG = (pkt_)->match.parts.tag;		\
        -:  201:    (rreq_)->status.count = (pkt_)->data_sz;			\
        -:  202:    (rreq_)->dev.sender_req_id = (pkt_)->sender_req_id;		\
        -:  203:    (rreq_)->dev.recv_data_sz = (pkt_)->data_sz;		\
        -:  204:    MPIDI_Request_set_seqnum((rreq_), (pkt_)->seqnum);		\
        -:  205:    MPIDI_Request_set_msg_type((rreq_), (msg_type_));		\
        -:  206:}
        -:  207:
        -:  208:#undef FUNCNAME
        -:  209:#define FUNCNAME MPIDI_CH3_PktHandler_EagerSyncSend
        -:  210:#undef FCNAME
        -:  211:#define FCNAME MPIDI_QUOTE(FUNCNAME)
        -:  212:int MPIDI_CH3_PktHandler_EagerSyncSend( MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt,
        -:  213:					MPIDI_msg_sz_t *buflen, MPID_Request **rreqp )
   460579:  214:{
   460579:  215:    MPIDI_CH3_Pkt_eager_send_t * es_pkt = &pkt->eager_send;
        -:  216:    MPID_Request * rreq;
        -:  217:    int found;
        -:  218:    int complete;
        -:  219:    char *data_buf;
        -:  220:    MPIDI_msg_sz_t data_len;
   460579:  221:    int mpi_errno = MPI_SUCCESS;
        -:  222:    
        -:  223:    MPIU_DBG_MSG_FMT(CH3_OTHER,VERBOSE,(MPIU_DBG_FDEST,
        -:  224:     "received eager sync send pkt, sreq=0x%08x, rank=%d, tag=%d, context=%d",
        -:  225:	      es_pkt->sender_req_id, es_pkt->match.parts.rank, 
        -:  226:	      es_pkt->match.parts.tag, 
        -:  227:              es_pkt->match.parts.context_id));
        -:  228:    MPIU_DBG_MSGPKT(vc,es_pkt->match.parts.tag,es_pkt->match.parts.context_id,
        -:  229:		    es_pkt->match.parts.rank,es_pkt->data_sz,
        -:  230:		    "ReceivedEagerSync");
        -:  231:	    
   460579:  232:    rreq = MPIDI_CH3U_Recvq_FDP_or_AEU(&es_pkt->match, &found);
   460579:  233:    MPIU_ERR_CHKANDJUMP1(!rreq, mpi_errno,MPI_ERR_OTHER, "**nomemreq", "**nomemuereq %d", MPIDI_CH3U_Recvq_count_unexp());
        -:  234:    
   460579:  235:    set_request_info(rreq, es_pkt, MPIDI_REQUEST_EAGER_MSG);
        -:  236:
   460579:  237:    data_len = ((*buflen - sizeof(MPIDI_CH3_Pkt_t) >= rreq->dev.recv_data_sz)
        -:  238:                ? rreq->dev.recv_data_sz : *buflen - sizeof(MPIDI_CH3_Pkt_t));
   460579:  239:    data_buf = (char *)pkt + sizeof(MPIDI_CH3_Pkt_t);
        -:  240:    
   460579:  241:    if (found)
        -:  242:    {
        -:  243:	MPIDI_CH3_Pkt_t upkt;
   444981:  244:	MPIDI_CH3_Pkt_eager_sync_ack_t * const esa_pkt = &upkt.eager_sync_ack;
        -:  245:	MPID_Request * esa_req;
        -:  246:
   444981:  247:	if (rreq->dev.recv_data_sz == 0) {
   362259:  248:            *buflen = sizeof(MPIDI_CH3_Pkt_t);
   362259:  249:	    MPIDI_CH3U_Request_complete(rreq);
   362259:  250:	    *rreqp = NULL;
        -:  251:	}
        -:  252:	else {
    82722:  253:	    mpi_errno = MPIDI_CH3U_Receive_data_found( rreq, data_buf,
        -:  254:                                                       &data_len, &complete );
    82722:  255:	    if (mpi_errno != MPI_SUCCESS) {
    #####:  256:		MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_OTHER, "**ch3|postrecv",
        -:  257:		    "**ch3|postrecv %s", "MPIDI_CH3_PKT_EAGER_SYNC_SEND");
        -:  258:	    }
        -:  259:
    82722:  260:            *buflen = sizeof(MPIDI_CH3_Pkt_t) + data_len;
        -:  261:
    82722:  262:            if (complete) 
        -:  263:            {
    #####:  264:                MPIDI_CH3U_Request_complete(rreq);
    #####:  265:                *rreqp = NULL;
        -:  266:            }
        -:  267:            else
        -:  268:            {
    82722:  269:                *rreqp = rreq;
        -:  270:            }
        -:  271:	}
        -:  272:	MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"sending eager sync ack");
        -:  273:	
   444981:  274:	MPIDI_Pkt_init(esa_pkt, MPIDI_CH3_PKT_EAGER_SYNC_ACK);
   444981:  275:	esa_pkt->sender_req_id = rreq->dev.sender_req_id;
        -:  276:	/* Because this is a packet handler, it is already within a CH3 CS */
        -:  277:	/* MPIU_THREAD_CS_ENTER(CH3COMM,vc); */
   444981:  278:	mpi_errno = MPIU_CALL(MPIDI_CH3,iStartMsg(vc, esa_pkt, 
        -:  279:						  sizeof(*esa_pkt), &esa_req));
        -:  280:	/* MPIU_THREAD_CS_EXIT(CH3COMM,vc); */
   444981:  281:	if (mpi_errno != MPI_SUCCESS) {
    #####:  282:	    MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,
        -:  283:				"**ch3|syncack");
        -:  284:	}
   444981:  285:	if (esa_req != NULL) {
        2:  286:	    MPID_Request_release(esa_req);
        -:  287:	}
        -:  288:    }
        -:  289:    else
        -:  290:    {
    15598:  291:	if (rreq->dev.recv_data_sz == 0) {
     1429:  292:            *buflen = sizeof(MPIDI_CH3_Pkt_t);
     1429:  293:	    MPIDI_CH3U_Request_complete(rreq);
     1429:  294:	    *rreqp = NULL;
        -:  295:	}
        -:  296:	else {
    14169:  297:	    mpi_errno = MPIDI_CH3U_Receive_data_unexpected( rreq, data_buf,
        -:  298:                                                            &data_len, &complete );
    14169:  299:	    if (mpi_errno != MPI_SUCCESS) {
    #####:  300:		MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_OTHER, "**ch3|postrecv",
        -:  301:		    "**ch3|postrecv %s", "MPIDI_CH3_PKT_EAGER_SYNC_SEND");
        -:  302:	    }
        -:  303:
    14169:  304:            *buflen = sizeof(MPIDI_CH3_Pkt_t) + data_len;
        -:  305:
    14169:  306:            if (complete) 
        -:  307:            {
    #####:  308:                MPIDI_CH3U_Request_complete(rreq);
    #####:  309:                *rreqp = NULL;
        -:  310:            }
        -:  311:            else
        -:  312:            {
    14169:  313:                *rreqp = rreq;
        -:  314:            }
        -:  315:	}
    15598:  316:	MPIDI_Request_set_sync_send_flag(rreq, TRUE);
        -:  317:    }
   460579:  318: fn_fail:
   460579:  319:    return mpi_errno;
        -:  320:}
        -:  321:
        -:  322:#undef FUNCNAME
        -:  323:#define FUNCNAME MPIDI_CH3_PktHandler_EagerSyncAck
        -:  324:#undef FCNAME
        -:  325:#define FCNAME MPIDI_QUOTE(FUNCNAME)
        -:  326:int MPIDI_CH3_PktHandler_EagerSyncAck( MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt,
        -:  327:				       MPIDI_msg_sz_t *buflen, MPID_Request **rreqp )
   460465:  328:{
   460465:  329:    MPIDI_CH3_Pkt_eager_sync_ack_t * esa_pkt = &pkt->eager_sync_ack;
        -:  330:    MPID_Request * sreq;
        -:  331:    
        -:  332:    MPIU_DBG_MSG_P(CH3_OTHER,VERBOSE,
        -:  333:	   "received eager sync ack pkt, sreq=0x%08x", esa_pkt->sender_req_id);
        -:  334:	    
   460465:  335:    MPID_Request_get_ptr(esa_pkt->sender_req_id, sreq);
        -:  336:    /* decrement CC (but don't mark data transfer as complete since the 
        -:  337:       transfer could still be in progress) */
        -:  338:
        -:  339:    /* FIXME: This sometimes segfaults */
   460465:  340:    MPIDI_CH3U_Request_complete(sreq);  
        -:  341:    
   460465:  342:    *buflen = sizeof(MPIDI_CH3_Pkt_t);
   460465:  343:    *rreqp = NULL;
   460465:  344:    return MPI_SUCCESS;
        -:  345:}
        -:  346:
        -:  347:#ifdef MPICH_DBG_OUTPUT
        -:  348:int MPIDI_CH3_PktPrint_EagerSyncSend( FILE *fp, MPIDI_CH3_Pkt_t *pkt )
        -:  349:{
        -:  350:    MPIU_DBG_PRINTF((" type ......... EAGER_SYNC_SEND\n"));
        -:  351:    MPIU_DBG_PRINTF((" sender_reqid . 0x%08X\n", pkt->eager_sync_send.sender_req_id));
        -:  352:    MPIU_DBG_PRINTF((" context_id ... %d\n", pkt->eager_sync_send.match.parts.context_id));
        -:  353:    MPIU_DBG_PRINTF((" tag .......... %d\n", pkt->eager_sync_send.match.parts.tag));
        -:  354:    MPIU_DBG_PRINTF((" rank ......... %d\n", pkt->eager_sync_send.match.parts.rank));
        -:  355:    MPIU_DBG_PRINTF((" data_sz ...... %d\n", pkt->eager_sync_send.data_sz));
        -:  356:#ifdef MPID_USE_SEQUENCE_NUMBERS
        -:  357:    MPIU_DBG_PRINTF((" seqnum ....... %d\n", pkt->eager_sync_send.seqnum));
        -:  358:#endif
        -:  359:    return MPI_SUCCESS;
        -:  360:}
        -:  361:
        -:  362:int MPIDI_CH3_PktPrint_EagerSyncAck( FILE *fp, MPIDI_CH3_Pkt_t *pkt )
        -:  363:{
        -:  364:    MPIU_DBG_PRINTF((" type ......... EAGER_SYNC_ACK\n"));
        -:  365:    MPIU_DBG_PRINTF((" sender_reqid . 0x%08X\n", pkt->eager_sync_ack.sender_req_id));
        -:  366:    return MPI_SUCCESS;
        -:  367:}
        -:  368:#endif