|
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 |
#include "bsendutil.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* -- Begin Profiling Symbol Block for routine MPI_Bsend */
|
|
Packit Service |
c5cf8c |
#if defined(HAVE_PRAGMA_WEAK)
|
|
Packit Service |
c5cf8c |
#pragma weak MPI_Bsend = PMPI_Bsend
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
|
|
Packit Service |
c5cf8c |
#pragma _HP_SECONDARY_DEF PMPI_Bsend MPI_Bsend
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_CRI_DUP)
|
|
Packit Service |
c5cf8c |
#pragma _CRI duplicate MPI_Bsend as PMPI_Bsend
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_WEAK_ATTRIBUTE)
|
|
Packit Service |
c5cf8c |
int MPI_Bsend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag,
|
|
Packit Service |
c5cf8c |
MPI_Comm comm) __attribute__ ((weak, alias("PMPI_Bsend")));
|
|
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_Bsend
|
|
Packit Service |
c5cf8c |
#define MPI_Bsend PMPI_Bsend
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef FUNCNAME
|
|
Packit Service |
c5cf8c |
#define FUNCNAME MPI_Bsend
|
|
Packit Service |
c5cf8c |
#undef FCNAME
|
|
Packit Service |
c5cf8c |
#define FCNAME MPL_QUOTE(FUNCNAME)
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPI_Bsend - Basic send with user-provided buffering
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Input Parameters:
|
|
Packit Service |
c5cf8c |
+ buf - initial address of send buffer (choice)
|
|
Packit Service |
c5cf8c |
. count - number of elements in send buffer (nonnegative integer)
|
|
Packit Service |
c5cf8c |
. datatype - datatype of each send buffer element (handle)
|
|
Packit Service |
c5cf8c |
. dest - rank of destination (integer)
|
|
Packit Service |
c5cf8c |
. tag - message tag (integer)
|
|
Packit Service |
c5cf8c |
- comm - communicator (handle)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Notes:
|
|
Packit Service |
c5cf8c |
This send is provided as a convenience function; it allows the user to
|
|
Packit Service |
c5cf8c |
send messages without worring about where they are buffered (because the
|
|
Packit Service |
c5cf8c |
user `must` have provided buffer space with 'MPI_Buffer_attach').
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
In deciding how much buffer space to allocate, remember that the buffer space
|
|
Packit Service |
c5cf8c |
is not available for reuse by subsequent 'MPI_Bsend's unless you are certain
|
|
Packit Service |
c5cf8c |
that the message
|
|
Packit Service |
c5cf8c |
has been received (not just that it should have been received). For example,
|
|
Packit Service |
c5cf8c |
this code does not allocate enough buffer space
|
|
Packit Service |
c5cf8c |
.vb
|
|
Packit Service |
c5cf8c |
MPI_Buffer_attach(b, n*sizeof(double) + MPI_BSEND_OVERHEAD);
|
|
Packit Service |
c5cf8c |
for (i=0; i
|
|
Packit Service |
c5cf8c |
MPI_Bsend(buf, n, MPI_DOUBLE, ...);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
.ve
|
|
Packit Service |
c5cf8c |
because only enough buffer space is provided for a single send, and the
|
|
Packit Service |
c5cf8c |
loop may start a second 'MPI_Bsend' before the first is done making use of the
|
|
Packit Service |
c5cf8c |
buffer.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
In C, you can
|
|
Packit Service |
c5cf8c |
force the messages to be delivered by
|
|
Packit Service |
c5cf8c |
.vb
|
|
Packit Service |
c5cf8c |
MPI_Buffer_detach(&b, &n);
|
|
Packit Service |
c5cf8c |
MPI_Buffer_attach(b, n);
|
|
Packit Service |
c5cf8c |
.ve
|
|
Packit Service |
c5cf8c |
(The 'MPI_Buffer_detach' will not complete until all buffered messages are
|
|
Packit Service |
c5cf8c |
delivered.)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N ThreadSafe
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N Fortran
|
|
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_RANK
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_TAG
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.seealso: MPI_Buffer_attach, MPI_Ibsend, MPI_Bsend_init
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPI_Bsend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int mpi_errno = MPI_SUCCESS;
|
|
Packit Service |
c5cf8c |
MPIR_Comm *comm_ptr = NULL;
|
|
Packit Service |
c5cf8c |
MPIR_Request *request_ptr = NULL;
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_BSEND);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_INITIALIZED_ORDIE();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_PT2PT_ENTER_FRONT(MPID_STATE_MPI_BSEND);
|
|
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 MPI object handles to object pointers */
|
|
Packit Service |
c5cf8c |
MPIR_Comm_get_ptr(comm, comm_ptr);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate object pointers if error checking is enabled */
|
|
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_COUNT(count, mpi_errno);
|
|
Packit Service |
c5cf8c |
/* Validate comm_ptr */
|
|
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 |
/* If comm_ptr is not valid, it will be reset to null */
|
|
Packit Service |
c5cf8c |
if (comm_ptr) {
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_SEND_TAG(tag, mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_SEND_RANK(comm_ptr, dest, mpi_errno)
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* Validate datatype handle */
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_DATATYPE(datatype, "datatype", mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate datatype object */
|
|
Packit Service |
c5cf8c |
if (HANDLE_GET_KIND(datatype) != HANDLE_KIND_BUILTIN) {
|
|
Packit Service |
c5cf8c |
MPIR_Datatype *datatype_ptr = NULL;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_get_ptr(datatype, 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 buffer */
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_USERBUFFER(buf, count, datatype, 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 |
#ifdef MPID_HAS_TBSEND
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
mpi_errno = MPID_tBsend(buf, count, datatype, dest, tag, comm_ptr, 0);
|
|
Packit Service |
c5cf8c |
if (mpi_errno == MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* FIXME: Check for MPID_WOULD_BLOCK? */
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Bsend_isend(buf, count, datatype, dest, tag, comm_ptr, BSEND, &request_ptr);
|
|
Packit Service |
c5cf8c |
/* Note that we can ignore the request_ptr because it is handled internally
|
|
Packit Service |
c5cf8c |
* by the bsend util routines */
|
|
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(MPID_STATE_MPI_BSEND);
|
|
Packit Service |
c5cf8c |
MPID_THREAD_CS_EXIT(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_bsend", "**mpi_bsend %p %d %D %i %t %C", buf, count,
|
|
Packit Service |
c5cf8c |
datatype, dest, tag, comm);
|
|
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 |
}
|