Blame src/mpi/pt2pt/rsend_init.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2001 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include "mpiimpl.h"
Packit 0848f5
Packit 0848f5
/* -- Begin Profiling Symbol Block for routine MPI_Rsend_init */
Packit 0848f5
#if defined(HAVE_PRAGMA_WEAK)
Packit 0848f5
#pragma weak MPI_Rsend_init = PMPI_Rsend_init
Packit 0848f5
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit 0848f5
#pragma _HP_SECONDARY_DEF PMPI_Rsend_init  MPI_Rsend_init
Packit 0848f5
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit 0848f5
#pragma _CRI duplicate MPI_Rsend_init as PMPI_Rsend_init
Packit 0848f5
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit 0848f5
int MPI_Rsend_init(const void *buf, int count, MPI_Datatype datatype, int dest, int tag,
Packit 0848f5
                   MPI_Comm comm, MPI_Request *request) __attribute__((weak,alias("PMPI_Rsend_init")));
Packit 0848f5
#endif
Packit 0848f5
/* -- End Profiling Symbol Block */
Packit 0848f5
Packit 0848f5
/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
Packit 0848f5
   the MPI routines */
Packit 0848f5
#ifndef MPICH_MPI_FROM_PMPI
Packit 0848f5
#undef MPI_Rsend_init
Packit 0848f5
#define MPI_Rsend_init PMPI_Rsend_init
Packit 0848f5
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
#undef FUNCNAME
Packit 0848f5
#define FUNCNAME MPI_Rsend_init
Packit 0848f5
Packit 0848f5
/*@
Packit 0848f5
    MPI_Rsend_init - Creates a persistent request for a ready send
Packit 0848f5
Packit 0848f5
Input Parameters:
Packit 0848f5
+ buf - initial address of send buffer (choice) 
Packit 0848f5
. count - number of elements sent (integer) 
Packit 0848f5
. datatype - type of each element (handle) 
Packit 0848f5
. dest - rank of destination (integer) 
Packit 0848f5
. tag - message tag (integer) 
Packit 0848f5
- comm - communicator (handle) 
Packit 0848f5
Packit 0848f5
Output Parameters:
Packit 0848f5
. request - communication request (handle) 
Packit 0848f5
Packit 0848f5
.N ThreadSafe
Packit 0848f5
Packit 0848f5
.N Fortran
Packit 0848f5
Packit 0848f5
.N Errors
Packit 0848f5
.N MPI_SUCCESS
Packit 0848f5
.N MPI_ERR_COUNT
Packit 0848f5
.N MPI_ERR_TYPE
Packit 0848f5
.N MPI_ERR_RANK
Packit 0848f5
.N MPI_ERR_TAG
Packit 0848f5
.N MPI_ERR_COMM
Packit 0848f5
.N MPI_ERR_EXHAUSTED
Packit 0848f5
Packit 0848f5
.seealso: MPI_Start, MPI_Request_free, MPI_Send_init
Packit 0848f5
@*/
Packit 0848f5
int MPI_Rsend_init(const void *buf, int count, MPI_Datatype datatype, int dest,
Packit 0848f5
		   int tag, MPI_Comm comm, MPI_Request *request)
Packit 0848f5
{
Packit 0848f5
    static const char FCNAME[] = "MPI_Rsend_init";
Packit 0848f5
    int mpi_errno = MPI_SUCCESS;
Packit 0848f5
    MPID_Comm *comm_ptr = NULL;
Packit 0848f5
    MPID_Request *request_ptr = NULL;
Packit 0848f5
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_RSEND_INIT);
Packit 0848f5
Packit 0848f5
    MPIR_ERRTEST_INITIALIZED_ORDIE();
Packit 0848f5
    
Packit 0848f5
    MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit 0848f5
    MPID_MPI_PT2PT_FUNC_ENTER(MPID_STATE_MPI_RSEND_INIT);
Packit 0848f5
    
Packit 0848f5
    /* Validate handle parameters needing to be converted */
Packit 0848f5
#   ifdef HAVE_ERROR_CHECKING
Packit 0848f5
    {
Packit 0848f5
        MPID_BEGIN_ERROR_CHECKS;
Packit 0848f5
        {
Packit 0848f5
	    MPIR_ERRTEST_COMM(comm, mpi_errno);
Packit 0848f5
	}
Packit 0848f5
        MPID_END_ERROR_CHECKS;
Packit 0848f5
    }
Packit 0848f5
#   endif /* HAVE_ERROR_CHECKING */
Packit 0848f5
    
Packit 0848f5
    /* Convert MPI object handles to object pointers */
Packit 0848f5
    MPID_Comm_get_ptr( comm, comm_ptr );
Packit 0848f5
Packit 0848f5
    /* Validate parameters if error checking is enabled */
Packit 0848f5
#   ifdef HAVE_ERROR_CHECKING
Packit 0848f5
    {
Packit 0848f5
        MPID_BEGIN_ERROR_CHECKS;
Packit 0848f5
        {
Packit 0848f5
            MPID_Comm_valid_ptr( comm_ptr, mpi_errno, FALSE );
Packit 0848f5
            if (mpi_errno) goto fn_fail;
Packit 0848f5
	    
Packit 0848f5
	    MPIR_ERRTEST_COUNT(count, mpi_errno);
Packit 0848f5
	    MPIR_ERRTEST_SEND_RANK(comm_ptr, dest, mpi_errno);
Packit 0848f5
	    MPIR_ERRTEST_SEND_TAG(tag, mpi_errno);
Packit 0848f5
	    MPIR_ERRTEST_ARGNULL(request,"request",mpi_errno);
Packit 0848f5
	    
Packit 0848f5
	    /* Validate datatype handle */
Packit 0848f5
	    MPIR_ERRTEST_DATATYPE(datatype, "datatype", mpi_errno);
Packit 0848f5
	    
Packit 0848f5
	    /* Validate datatype object */
Packit 0848f5
	    if (HANDLE_GET_KIND(datatype) != HANDLE_KIND_BUILTIN)
Packit 0848f5
	    {
Packit 0848f5
		MPID_Datatype *datatype_ptr = NULL;
Packit 0848f5
Packit 0848f5
		MPID_Datatype_get_ptr(datatype, datatype_ptr);
Packit 0848f5
		MPID_Datatype_valid_ptr(datatype_ptr, mpi_errno);
Packit 0848f5
		if (mpi_errno) goto fn_fail;
Packit 0848f5
		MPID_Datatype_committed_ptr(datatype_ptr, mpi_errno);
Packit 0848f5
		if (mpi_errno) goto fn_fail;
Packit 0848f5
	    }
Packit 0848f5
	    
Packit 0848f5
	    /* Validate buffer */
Packit 0848f5
	    MPIR_ERRTEST_USERBUFFER(buf,count,datatype,mpi_errno);
Packit 0848f5
        }
Packit 0848f5
        MPID_END_ERROR_CHECKS;
Packit 0848f5
    }
Packit 0848f5
#   endif /* HAVE_ERROR_CHECKING */
Packit 0848f5
Packit 0848f5
    /* ... body of routine ...  */
Packit 0848f5
    
Packit 0848f5
    mpi_errno = MPID_Rsend_init(buf, count, datatype, dest, tag, comm_ptr,
Packit 0848f5
				MPID_CONTEXT_INTRA_PT2PT, &request_ptr);
Packit 0848f5
    if (mpi_errno != MPI_SUCCESS) goto fn_fail;
Packit 0848f5
Packit 0848f5
    /* return the handle of the request to the user */
Packit 0848f5
    MPID_OBJ_PUBLISH_HANDLE(*request, request_ptr->handle);
Packit 0848f5
Packit 0848f5
    /* ... end of body of routine ... */
Packit 0848f5
    
Packit 0848f5
  fn_exit:
Packit 0848f5
    MPID_MPI_PT2PT_FUNC_EXIT(MPID_STATE_MPI_RSEND_INIT);
Packit 0848f5
    MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit 0848f5
    return mpi_errno;
Packit 0848f5
Packit 0848f5
  fn_fail:
Packit 0848f5
    /* --BEGIN ERROR HANDLING-- */
Packit 0848f5
#   ifdef HAVE_ERROR_CHECKING
Packit 0848f5
    {
Packit 0848f5
	mpi_errno = MPIR_Err_create_code(
Packit 0848f5
	    mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_rsend_init",
Packit 0848f5
	    "**mpi_rsend_init %p %d %D %i %t %C %p", buf, count, datatype, dest, tag, comm, request);
Packit 0848f5
    }
Packit 0848f5
#   endif
Packit 0848f5
    mpi_errno = MPIR_Err_return_comm( comm_ptr, FCNAME, mpi_errno );
Packit 0848f5
    goto fn_exit;
Packit 0848f5
    /* --END ERROR HANDLING-- */
Packit 0848f5
}