|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mpiimpl.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* -- Begin Profiling Symbol Block for routine MPI_Sendrecv */
|
|
Packit Service |
c5cf8c |
#if defined(HAVE_PRAGMA_WEAK)
|
|
Packit Service |
c5cf8c |
#pragma weak MPI_Sendrecv = PMPI_Sendrecv
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
|
|
Packit Service |
c5cf8c |
#pragma _HP_SECONDARY_DEF PMPI_Sendrecv MPI_Sendrecv
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_CRI_DUP)
|
|
Packit Service |
c5cf8c |
#pragma _CRI duplicate MPI_Sendrecv as PMPI_Sendrecv
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_WEAK_ATTRIBUTE)
|
|
Packit Service |
c5cf8c |
int MPI_Sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest,
|
|
Packit Service |
c5cf8c |
int sendtag, void *recvbuf, int recvcount, MPI_Datatype recvtype,
|
|
Packit Service |
c5cf8c |
int source, int recvtag, MPI_Comm comm, MPI_Status * status)
|
|
Packit Service |
c5cf8c |
__attribute__ ((weak, alias("PMPI_Sendrecv")));
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
/* -- End Profiling Symbol Block */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
|
|
Packit Service |
c5cf8c |
the MPI routines */
|
|
Packit Service |
c5cf8c |
#ifndef MPICH_MPI_FROM_PMPI
|
|
Packit Service |
c5cf8c |
#undef MPI_Sendrecv
|
|
Packit Service |
c5cf8c |
#define MPI_Sendrecv PMPI_Sendrecv
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef FUNCNAME
|
|
Packit Service |
c5cf8c |
#define FUNCNAME MPI_Sendrecv
|
|
Packit Service |
c5cf8c |
#undef FCNAME
|
|
Packit Service |
c5cf8c |
#define FCNAME MPL_QUOTE(FUNCNAME)
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPI_Sendrecv - Sends and receives a message
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Input Parameters:
|
|
Packit Service |
c5cf8c |
+ sendbuf - initial address of send buffer (choice)
|
|
Packit Service |
c5cf8c |
. sendcount - number of elements in send buffer (integer)
|
|
Packit Service |
c5cf8c |
. sendtype - type of elements in send buffer (handle)
|
|
Packit Service |
c5cf8c |
. dest - rank of destination (integer)
|
|
Packit Service |
c5cf8c |
. sendtag - send tag (integer)
|
|
Packit Service |
c5cf8c |
. recvcount - number of elements in receive buffer (integer)
|
|
Packit Service |
c5cf8c |
. recvtype - type of elements in receive buffer (handle)
|
|
Packit Service |
c5cf8c |
. source - rank of source (integer)
|
|
Packit Service |
c5cf8c |
. recvtag - receive tag (integer)
|
|
Packit Service |
c5cf8c |
- comm - communicator (handle)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Output Parameters:
|
|
Packit Service |
c5cf8c |
+ recvbuf - initial address of receive buffer (choice)
|
|
Packit Service |
c5cf8c |
- status - status object (Status). This refers to the receive operation.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N ThreadSafe
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N Fortran
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N FortranStatus
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N Errors
|
|
Packit Service |
c5cf8c |
.N MPI_SUCCESS
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_COMM
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_COUNT
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_TYPE
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_TAG
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_RANK
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPI_Sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
|
|
Packit Service |
c5cf8c |
int dest, int sendtag,
|
|
Packit Service |
c5cf8c |
void *recvbuf, int recvcount, MPI_Datatype recvtype,
|
|
Packit Service |
c5cf8c |
int source, int recvtag, MPI_Comm comm, MPI_Status * status)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int mpi_errno = MPI_SUCCESS;
|
|
Packit Service |
c5cf8c |
MPIR_Comm *comm_ptr = NULL;
|
|
Packit Service |
c5cf8c |
MPIR_Request *sreq = NULL;
|
|
Packit Service |
c5cf8c |
MPIR_Request *rreq = NULL;
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_SENDRECV);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_INITIALIZED_ORDIE();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPID_THREAD_CS_ENTER(VNI_GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_PT2PT_ENTER_BOTH(MPID_STATE_MPI_SENDRECV);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate handle parameters needing to be converted */
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_ERROR_CHECKING
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
MPID_BEGIN_ERROR_CHECKS;
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_COMM(comm, mpi_errno);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPID_END_ERROR_CHECKS;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif /* HAVE_ERROR_CHECKING */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Convert handles to MPI objects. */
|
|
Packit Service |
c5cf8c |
MPIR_Comm_get_ptr(comm, comm_ptr);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_ERROR_CHECKING
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
MPID_BEGIN_ERROR_CHECKS;
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
/* Validate communicator */
|
|
Packit Service |
c5cf8c |
MPIR_Comm_valid_ptr(comm_ptr, mpi_errno, FALSE);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate count */
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_COUNT(sendcount, mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_COUNT(recvcount, mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate status (status_ignore is not the same as null) */
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_ARGNULL(status, "status", mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate tags */
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_SEND_TAG(sendtag, mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_RECV_TAG(recvtag, mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate source and destination */
|
|
Packit Service |
c5cf8c |
if (comm_ptr) {
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_SEND_RANK(comm_ptr, dest, mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_RECV_RANK(comm_ptr, source, mpi_errno);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate datatype handles */
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_DATATYPE(sendtype, "datatype", mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_DATATYPE(recvtype, "datatype", mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate datatype objects */
|
|
Packit Service |
c5cf8c |
if (HANDLE_GET_KIND(sendtype) != HANDLE_KIND_BUILTIN) {
|
|
Packit Service |
c5cf8c |
MPIR_Datatype *datatype_ptr = NULL;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_get_ptr(sendtype, datatype_ptr);
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_valid_ptr(datatype_ptr, mpi_errno);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_committed_ptr(datatype_ptr, mpi_errno);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (HANDLE_GET_KIND(recvtype) != HANDLE_KIND_BUILTIN) {
|
|
Packit Service |
c5cf8c |
MPIR_Datatype *datatype_ptr = NULL;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_get_ptr(recvtype, datatype_ptr);
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_valid_ptr(datatype_ptr, mpi_errno);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_committed_ptr(datatype_ptr, mpi_errno);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate buffers */
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_USERBUFFER(sendbuf, sendcount, sendtype, mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_USERBUFFER(recvbuf, recvcount, recvtype, mpi_errno);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPID_END_ERROR_CHECKS;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif /* HAVE_ERROR_CHECKING */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* ... body of routine ... */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno =
|
|
Packit Service |
c5cf8c |
MPID_Irecv(recvbuf, recvcount, recvtype, source, recvtag, comm_ptr,
|
|
Packit Service |
c5cf8c |
MPIR_CONTEXT_INTRA_PT2PT, &rreq);
|
|
Packit Service |
c5cf8c |
if (mpi_errno != MPI_SUCCESS)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* FIXME - Performance for small messages might be better if MPID_Send() were used here instead of MPID_Isend() */
|
|
Packit Service |
c5cf8c |
mpi_errno =
|
|
Packit Service |
c5cf8c |
MPID_Isend(sendbuf, sendcount, sendtype, dest, sendtag, comm_ptr, MPIR_CONTEXT_INTRA_PT2PT,
|
|
Packit Service |
c5cf8c |
&sreq);
|
|
Packit Service |
c5cf8c |
if (mpi_errno != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
/* --BEGIN ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
if (mpi_errno == MPIX_ERR_NOREQ)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**nomem");
|
|
Packit Service |
c5cf8c |
/* FIXME: should we cancel the pending (possibly completed) receive request or wait for it to complete? */
|
|
Packit Service |
c5cf8c |
MPIR_Request_free(rreq);
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
/* --END ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (!MPIR_Request_is_complete(sreq) || !MPIR_Request_is_complete(rreq)) {
|
|
Packit Service |
c5cf8c |
MPID_Progress_state progress_state;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPID_Progress_start(&progress_state);
|
|
Packit Service |
c5cf8c |
while (!MPIR_Request_is_complete(sreq) || !MPIR_Request_is_complete(rreq)) {
|
|
Packit Service |
c5cf8c |
mpi_errno = MPID_Progress_wait(&progress_state);
|
|
Packit Service |
c5cf8c |
if (mpi_errno != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
/* --BEGIN ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
MPID_Progress_end(&progress_state);
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
/* --END ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (unlikely(MPIR_Request_is_anysrc_mismatched(rreq))) {
|
|
Packit Service |
c5cf8c |
/* --BEGIN ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Request_handle_proc_failed(rreq);
|
|
Packit Service |
c5cf8c |
if (!MPIR_Request_is_complete(sreq)) {
|
|
Packit Service |
c5cf8c |
MPID_Cancel_send(sreq);
|
|
Packit Service |
c5cf8c |
MPIR_STATUS_SET_CANCEL_BIT(sreq->status, FALSE);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
/* --END ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPID_Progress_end(&progress_state);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = rreq->status.MPI_ERROR;
|
|
Packit Service |
c5cf8c |
MPIR_Request_extract_status(rreq, status);
|
|
Packit Service |
c5cf8c |
MPIR_Request_free(rreq);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (mpi_errno == MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
mpi_errno = sreq->status.MPI_ERROR;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPIR_Request_free(sreq);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (mpi_errno != MPI_SUCCESS)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* ... end of body of routine ... */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
fn_exit:
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_PT2PT_EXIT_BOTH(MPID_STATE_MPI_SENDRECV);
|
|
Packit Service |
c5cf8c |
MPID_THREAD_CS_EXIT(VNI_GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
|
|
Packit Service |
c5cf8c |
return mpi_errno;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
fn_fail:
|
|
Packit Service |
c5cf8c |
/* --BEGIN ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_ERROR_CHECKING
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
mpi_errno =
|
|
Packit Service |
c5cf8c |
MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER,
|
|
Packit Service |
c5cf8c |
"**mpi_sendrecv",
|
|
Packit Service |
c5cf8c |
"**mpi_sendrecv %p %d %D %i %t %p %d %D %i %t %C %p", sendbuf,
|
|
Packit Service |
c5cf8c |
sendcount, sendtype, dest, sendtag, recvbuf, recvcount, recvtype,
|
|
Packit Service |
c5cf8c |
source, recvtag, comm, status);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Err_return_comm(comm_ptr, FCNAME, mpi_errno);
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
/* --END ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
}
|