-:    0:Source:/home/MPI/testing/mpich2/mpich2/src/mpid/ch3/src/mpid_irecv.c
        -:    0:Graph:mpid_irecv.gcno
        -:    0:Data:mpid_irecv.gcda
        -:    0:Runs:4382
        -:    0:Programs:1376
        -:    1:/* -*- Mode: C; c-basic-offset:4 ; -*- */
        -:    2:/*
        -:    3: *  (C) 2001 by Argonne National Laboratory.
        -:    4: *      See COPYRIGHT in top-level directory.
        -:    5: */
        -:    6:
        -:    7:#include "mpidimpl.h"
        -:    8:
        -:    9:#undef FUNCNAME
        -:   10:#define FUNCNAME MPID_Irecv
        -:   11:#undef FCNAME
        -:   12:#define FCNAME MPIDI_QUOTE(FUNCNAME)
        -:   13:int MPID_Irecv(void * buf, int count, MPI_Datatype datatype, int rank, int tag,
        -:   14:	       MPID_Comm * comm, int context_offset,
        -:   15:               MPID_Request ** request)
  8883231:   16:{
        -:   17:    MPID_Request * rreq;
        -:   18:    int found;
  8883231:   19:    int mpi_errno = MPI_SUCCESS;
        -:   20:    MPIDI_STATE_DECL(MPID_STATE_MPID_IRECV);
        -:   21:
        -:   22:    MPIDI_FUNC_ENTER(MPID_STATE_MPID_IRECV);
        -:   23:
        -:   24:    MPIU_DBG_MSG_FMT(CH3_OTHER,VERBOSE,(MPIU_DBG_FDEST,
        -:   25:			"rank=%d, tag=%d, context=%d", 
        -:   26:			rank, tag, comm->recvcontext_id + context_offset));
        -:   27:    
  8883231:   28:    if (rank == MPI_PROC_NULL)
        -:   29:    {
    16317:   30:	rreq = MPID_Request_create();
    16317:   31:	if (rreq != NULL)
        -:   32:	{
    16317:   33:	    MPIU_Object_set_ref(rreq, 1);
    16317:   34:	    rreq->cc = 0;
    16317:   35:	    rreq->kind = MPID_REQUEST_RECV;
    16317:   36:	    MPIR_Status_set_procnull(&rreq->status);
        -:   37:	}
        -:   38:	else
        -:   39:	{
    #####:   40:	    MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_NO_MEM, "**nomem");
        -:   41:	}
        -:   42:	goto fn_exit;
        -:   43:    }
        -:   44:
        -:   45:    MPIU_THREAD_CS_ENTER(MSGQUEUE,);
  8866914:   46:    rreq = MPIDI_CH3U_Recvq_FDU_or_AEP(rank, tag, 
        -:   47:				       comm->recvcontext_id + context_offset,
        -:   48:                                       comm, buf, count, datatype, &found);
  8866914:   49:    if (rreq == NULL)
        -:   50:    {
        -:   51:	MPIU_THREAD_CS_EXIT(MSGQUEUE,);
    #####:   52:	MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_NO_MEM, "**nomem");
        -:   53:    }
        -:   54:
  8866914:   55:    if (found)
        -:   56:    {
        -:   57:	MPIDI_VC_t * vc;
        -:   58:	
        -:   59:	/* Message was found in the unexepected queue */
        -:   60:	MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"request found in unexpected queue");
        -:   61:
        -:   62:	/* Release the message queue - we've removed this request from 
        -:   63:	   the queue already */
        -:   64:	MPIU_THREAD_CS_EXIT(MSGQUEUE,);
        -:   65:
  1274695:   66:	if (MPIDI_Request_get_msg_type(rreq) == MPIDI_REQUEST_EAGER_MSG)
        -:   67:	{
        -:   68:	    int recv_pending;
        -:   69:	    
        -:   70:	    /* This is an eager message */
        -:   71:	    MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"eager message in the request");
        -:   72:	    
        -:   73:	    /* If this is a eager synchronous message, then we need to send an 
        -:   74:	       acknowledgement back to the sender. */
  1243700:   75:	    if (MPIDI_Request_get_sync_send_flag(rreq))
        -:   76:	    {
    12081:   77:		MPIDI_Comm_get_vc_set_active(comm, rreq->dev.match.parts.rank, &vc);
    12081:   78:		mpi_errno = MPIDI_CH3_EagerSyncAck( vc, rreq );
    12081:   79:		if (mpi_errno) MPIU_ERR_POP(mpi_errno);
        -:   80:	    }
        -:   81:
        -:   82:            /* the request was found in the unexpected queue, so it has a
        -:   83:               recv_pending_count of at least 1 */
  1243700:   84:            MPIDI_Request_decr_pending(rreq);
  1243700:   85:            MPIDI_Request_check_pending(rreq, &recv_pending);
  1243700:   86:	    if (!recv_pending)
        -:   87:	    {
        -:   88:		/* All of the data has arrived, we need to copy the data and 
        -:   89:		   then free the buffer. */
        -:   90:		/* FIXME: if the user buffer is contiguous, just move the
        -:   91:		   data without using a separate routine call */
  1243607:   92:		if (rreq->dev.recv_data_sz > 0)
        -:   93:		{
   793806:   94:		    MPIDI_CH3U_Request_unpack_uebuf(rreq);
   793806:   95:		    MPIU_Free(rreq->dev.tmpbuf);
        -:   96:		}
        -:   97:
  1243607:   98:		mpi_errno = rreq->status.MPI_ERROR;
  1243607:   99:		goto fn_exit;
        -:  100:	    }
        -:  101:	    else
        -:  102:	    {
        -:  103:		/* The data is still being transfered across the net.  We'll 
        -:  104:		   leave it to the progress engine to handle once the
        -:  105:		   entire message has arrived. */
       93:  106:		if (HANDLE_GET_KIND(datatype) != HANDLE_KIND_BUILTIN)
        -:  107:		{
    #####:  108:		    MPID_Datatype_get_ptr(datatype, rreq->dev.datatype_ptr);
    #####:  109:		    MPID_Datatype_add_ref(rreq->dev.datatype_ptr);
        -:  110:		}
        -:  111:	    
        -:  112:	    }
        -:  113:	}
    30995:  114:	else if (MPIDI_Request_get_msg_type(rreq) == MPIDI_REQUEST_RNDV_MSG)
        -:  115:	{
      157:  116:	    MPIDI_Comm_get_vc_set_active(comm, rreq->dev.match.parts.rank, &vc);
        -:  117:	
      157:  118:	    mpi_errno = vc->rndvRecv_fn( vc, rreq );
      157:  119:	    if (mpi_errno) MPIU_ERR_POP( mpi_errno );
      157:  120:	    if (HANDLE_GET_KIND(datatype) != HANDLE_KIND_BUILTIN)
        -:  121:	    {
    #####:  122:		MPID_Datatype_get_ptr(datatype, rreq->dev.datatype_ptr);
    #####:  123:		MPID_Datatype_add_ref(rreq->dev.datatype_ptr);
        -:  124:	    }
        -:  125:	}
    30838:  126:	else if (MPIDI_Request_get_msg_type(rreq) == MPIDI_REQUEST_SELF_MSG)
        -:  127:	{
    30838:  128:	    mpi_errno = MPIDI_CH3_RecvFromSelf( rreq, buf, count, datatype );
    30838:  129:	    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
        -:  130:	}
        -:  131:	else
        -:  132:	{
        -:  133:	    /* --BEGIN ERROR HANDLING-- */
    #####:  134:	    MPID_Request_release(rreq);
    #####:  135:	    rreq = NULL;
    #####:  136:	    MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_INTERN, "**ch3|badmsgtype",
        -:  137:		      "**ch3|badmsgtype %d", MPIDI_Request_get_msg_type(rreq));
        -:  138:	    /* --END ERROR HANDLING-- */
        -:  139:	}
        -:  140:    }
        -:  141:    else
        -:  142:    {
        -:  143:	/* Message has yet to arrived.  The request has been placed on the 
        -:  144:	   list of posted receive requests and populated with
        -:  145:           information supplied in the arguments. */
        -:  146:	MPIU_DBG_MSG(CH3_OTHER,VERBOSE,"request allocated in posted queue");
        -:  147:	
  7592219:  148:	if (HANDLE_GET_KIND(datatype) != HANDLE_KIND_BUILTIN)
        -:  149:	{
    65902:  150:	    MPID_Datatype_get_ptr(datatype, rreq->dev.datatype_ptr);
    65902:  151:	    MPID_Datatype_add_ref(rreq->dev.datatype_ptr);
        -:  152:	}
        -:  153:
  7592219:  154:	rreq->dev.recv_pending_count = 1;
        -:  155:
        -:  156:	/* We must wait until here to exit the msgqueue critical section
        -:  157:	   on this request (we needed to set the recv_pending_count
        -:  158:	   and the datatype pointer) */
        -:  159:	MPIU_THREAD_CS_EXIT(MSGQUEUE,rreq);
        -:  160:    }
        -:  161:
  8883231:  162:  fn_exit:
  8883231:  163:    *request = rreq;
        -:  164:    MPIU_DBG_MSG_P(CH3_OTHER,VERBOSE,"request allocated, handle=0x%08x", 
        -:  165:		   rreq->handle);
        -:  166:
  8883231:  167: fn_fail:
        -:  168:    MPIDI_FUNC_EXIT(MPID_STATE_MPID_IRECV);
  8883231:  169:    return mpi_errno;
        -:  170:}