Blame src/mpi/pt2pt/buffree.c

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_Buffer_detach */
Packit Service c5cf8c
#if defined(HAVE_PRAGMA_WEAK)
Packit Service c5cf8c
#pragma weak MPI_Buffer_detach = PMPI_Buffer_detach
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit Service c5cf8c
#pragma _HP_SECONDARY_DEF PMPI_Buffer_detach  MPI_Buffer_detach
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit Service c5cf8c
#pragma _CRI duplicate MPI_Buffer_detach as PMPI_Buffer_detach
Packit Service c5cf8c
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit Service c5cf8c
int MPI_Buffer_detach(void *buffer_addr, int *size)
Packit Service c5cf8c
    __attribute__ ((weak, alias("PMPI_Buffer_detach")));
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_Buffer_detach
Packit Service c5cf8c
#define MPI_Buffer_detach PMPI_Buffer_detach
Packit Service c5cf8c
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPI_Buffer_detach
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
/*@
Packit Service c5cf8c
  MPI_Buffer_detach - Removes an existing buffer (for use in MPI_Bsend etc)
Packit Service c5cf8c
Packit Service c5cf8c
Output Parameters:
Packit Service c5cf8c
+ buffer_addr - initial buffer address (choice)
Packit Service c5cf8c
- size - buffer size, in bytes (integer)
Packit Service c5cf8c
Packit Service c5cf8c
Notes:
Packit Service c5cf8c
    The reason that 'MPI_Buffer_detach' returns the address and size of the
Packit Service c5cf8c
buffer being detached is to allow nested libraries to replace and restore
Packit Service c5cf8c
the buffer.  For example, consider
Packit Service c5cf8c
Packit Service c5cf8c
.vb
Packit Service c5cf8c
    int size, mysize, idummy;
Packit Service c5cf8c
    void *ptr, *myptr, *dummy;
Packit Service c5cf8c
    MPI_Buffer_detach(&ptr, &size);
Packit Service c5cf8c
    MPI_Buffer_attach(myptr, mysize);
Packit Service c5cf8c
    ...
Packit Service c5cf8c
    ... library code ...
Packit Service c5cf8c
    ...
Packit Service c5cf8c
    MPI_Buffer_detach(&dummy, &idummy);
Packit Service c5cf8c
    MPI_Buffer_attach(ptr, size);
Packit Service c5cf8c
.ve
Packit Service c5cf8c
Packit Service c5cf8c
This is much like the action of the Unix signal routine and has the same
Packit Service c5cf8c
strengths (it is simple) and weaknesses (it only works for nested usages).
Packit Service c5cf8c
Packit Service c5cf8c
Note that for this approach to work, MPI_Buffer_detach must return MPI_SUCCESS
Packit Service c5cf8c
even when there is no buffer to detach.  In that case, it returns a size of
Packit Service c5cf8c
zero.  The MPI 1.1 standard for 'MPI_BUFFER_DETACH' contains the text
Packit Service c5cf8c
Packit Service c5cf8c
.vb
Packit Service c5cf8c
   The statements made in this section describe the behavior of MPI for
Packit Service c5cf8c
   buffered-mode sends. When no buffer is currently associated, MPI behaves
Packit Service c5cf8c
   as if a zero-sized buffer is associated with the process.
Packit Service c5cf8c
.ve
Packit Service c5cf8c
Packit Service c5cf8c
This could be read as applying only to the various Bsend routines.  This
Packit Service c5cf8c
implementation takes the position that this applies to 'MPI_BUFFER_DETACH'
Packit Service c5cf8c
as well.
Packit Service c5cf8c
Packit Service c5cf8c
.N NotThreadSafe
Packit Service c5cf8c
Because the buffer for buffered sends (e.g., 'MPI_Bsend') is shared by all
Packit Service c5cf8c
threads in a process, the user is responsible for ensuring that only
Packit Service c5cf8c
one thread at a time calls this routine or 'MPI_Buffer_attach'.
Packit Service c5cf8c
Packit Service c5cf8c
.N Fortran
Packit Service c5cf8c
Packit Service c5cf8c
    The Fortran binding for this routine is different.  Because Fortran
Packit Service c5cf8c
    does not have pointers, it is impossible to provide a way to use the
Packit Service c5cf8c
    output of this routine to exchange buffers.  In this case, only the
Packit Service c5cf8c
    size field is set.
Packit Service c5cf8c
Packit Service c5cf8c
Notes for C:
Packit Service c5cf8c
    Even though the 'bufferptr' argument is declared as 'void *', it is
Packit Service c5cf8c
    really the address of a void pointer.  See the rationale in the
Packit Service c5cf8c
    standard for more details.
Packit Service c5cf8c
Packit Service c5cf8c
.seealso: MPI_Buffer_attach
Packit Service c5cf8c
@*/
Packit Service c5cf8c
int MPI_Buffer_detach(void *buffer_addr, int *size)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_BUFFER_DETACH);
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_ENTER(MPID_STATE_MPI_BUFFER_DETACH);
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
            MPIR_ERRTEST_ARGNULL(size, "size", 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 = MPIR_Bsend_detach(buffer_addr, size);
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_EXIT(MPID_STATE_MPI_BUFFER_DETACH);
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_buffer_detach", "**mpi_buffer_detach %p %p", buffer_addr,
Packit Service c5cf8c
                                 size);
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif
Packit Service c5cf8c
    mpi_errno = MPIR_Err_return_comm(0, FCNAME, mpi_errno);
Packit Service c5cf8c
    goto fn_exit;
Packit Service c5cf8c
    /* --END ERROR HANDLING-- */
Packit Service c5cf8c
}