Blame src/mpi/rma/win_create_dynamic.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_Win_create_dynamic */
Packit 0848f5
#if defined(HAVE_PRAGMA_WEAK)
Packit 0848f5
#pragma weak MPI_Win_create_dynamic = PMPI_Win_create_dynamic
Packit 0848f5
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit 0848f5
#pragma _HP_SECONDARY_DEF PMPI_Win_create_dynamic  MPI_Win_create_dynamic
Packit 0848f5
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit 0848f5
#pragma _CRI duplicate MPI_Win_create_dynamic as PMPI_Win_create_dynamic
Packit 0848f5
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit 0848f5
int MPI_Win_create_dynamic(MPI_Info info, MPI_Comm comm, MPI_Win *win) __attribute__((weak,alias("PMPI_Win_create_dynamic")));
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_Win_create_dynamic
Packit 0848f5
#define MPI_Win_create_dynamic PMPI_Win_create_dynamic
Packit 0848f5
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
#undef FUNCNAME
Packit 0848f5
#define FUNCNAME MPI_Win_create_dynamic
Packit 0848f5
Packit 0848f5
/*@
Packit 0848f5
MPI_Win_create_dynamic - Create an MPI Window object for one-sided
Packit 0848f5
communication.  This window allows memory to be dynamically exposed and
Packit 0848f5
un-exposed for RMA operations.
Packit 0848f5
Packit 0848f5
Packit 0848f5
This is a collective call executed by all processes in the group of comm. It
Packit 0848f5
returns a window win without memory attached. Existing process memory can be
Packit 0848f5
attached as described below. This routine returns a window object that can be
Packit 0848f5
used by these processes to perform RMA operations on attached memory. Because
Packit 0848f5
this window has special properties, it will sometimes be referred to as a
Packit 0848f5
dynamic window.  The info argument can be used to specify hints similar to the
Packit 0848f5
info argument for 'MPI_Win_create'.
Packit 0848f5
Packit 0848f5
In the case of a window created with 'MPI_Win_create_dynamic', the target_disp
Packit 0848f5
for all RMA functions is the address at the target; i.e., the effective
Packit 0848f5
window_base is 'MPI_BOTTOM' and the disp_unit is one. For dynamic windows, the
Packit 0848f5
target_disp argument to RMA communication operations is not restricted to
Packit 0848f5
non-negative values. Users should use 'MPI_Get_address' at the target process to
Packit 0848f5
determine the address of a target memory location and communicate this address
Packit 0848f5
to the origin process.
Packit 0848f5
Packit 0848f5
Input Parameters:
Packit 0848f5
+ info - info argument (handle)
Packit 0848f5
- comm - communicator (handle)
Packit 0848f5
Packit 0848f5
Output Parameters:
Packit 0848f5
. win - window object returned by the call (handle)
Packit 0848f5
Packit 0848f5
Notes:
Packit 0848f5
Packit 0848f5
Users are cautioned that displacement arithmetic can overflow in variables of
Packit 0848f5
type 'MPI_Aint' and result in unexpected values on some platforms. This issue may
Packit 0848f5
be addressed in a future version of MPI.
Packit 0848f5
Packit 0848f5
Memory in this window may not be used as the target of one-sided accesses in
Packit 0848f5
this window until it is attached using the function 'MPI_Win_attach'. That is, in
Packit 0848f5
addition to using 'MPI_Win_create_dynamic' to create an MPI window, the user must
Packit 0848f5
use 'MPI_Win_attach' before any local memory may be the target of an MPI RMA
Packit 0848f5
operation. Only memory that is currently accessible may be attached.
Packit 0848f5
Packit 0848f5
Packit 0848f5
.N ThreadSafe
Packit 0848f5
.N Fortran
Packit 0848f5
Packit 0848f5
.N Errors
Packit 0848f5
.N MPI_SUCCESS
Packit 0848f5
.N MPI_ERR_ARG
Packit 0848f5
.N MPI_ERR_COMM
Packit 0848f5
.N MPI_ERR_INFO
Packit 0848f5
.N MPI_ERR_OTHER
Packit 0848f5
.N MPI_ERR_SIZE
Packit 0848f5
Packit 0848f5
.seealso: MPI_Win_attach MPI_Win_detach MPI_Win_allocate MPI_Win_allocate_shared MPI_Win_create MPI_Win_free
Packit 0848f5
@*/
Packit 0848f5
int MPI_Win_create_dynamic(MPI_Info info, MPI_Comm comm, MPI_Win *win)
Packit 0848f5
{
Packit 0848f5
    static const char FCNAME[] = "MPI_Win_create_dynamic";
Packit 0848f5
    int mpi_errno = MPI_SUCCESS;
Packit 0848f5
    MPID_Win *win_ptr = NULL;
Packit 0848f5
    MPID_Comm *comm_ptr = NULL;
Packit 0848f5
    MPID_Info *info_ptr = NULL;
Packit 0848f5
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_WIN_CREATE_DYNAMIC);
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_RMA_FUNC_ENTER(MPID_STATE_MPI_WIN_CREATE_DYNAMIC);
Packit 0848f5
Packit 0848f5
    /* Validate parameters, especially handles 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
            MPIR_ERRTEST_INFO_OR_NULL(info, mpi_errno);
Packit 0848f5
            MPIR_ERRTEST_ARGNULL(win, "win", 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
    MPID_Info_get_ptr( info, info_ptr );
Packit 0848f5
Packit 0848f5
    /* Validate parameters and objects (post conversion) */
Packit 0848f5
#   ifdef HAVE_ERROR_CHECKING
Packit 0848f5
    {
Packit 0848f5
        MPID_BEGIN_ERROR_CHECKS;
Packit 0848f5
        {
Packit 0848f5
            /* Validate pointers */
Packit 0848f5
            MPID_Comm_valid_ptr( comm_ptr, mpi_errno, FALSE );
Packit 0848f5
            if (mpi_errno != MPI_SUCCESS) goto fn_fail;
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_Win_create_dynamic(info_ptr, comm_ptr, &win_ptr);
Packit 0848f5
    if (mpi_errno != MPI_SUCCESS) goto fn_fail;
Packit 0848f5
Packit 0848f5
    /* Initialize a few fields that have specific defaults */
Packit 0848f5
    win_ptr->name[0]    = 0;
Packit 0848f5
    win_ptr->errhandler = 0;
Packit 0848f5
Packit 0848f5
    /* return the handle of the window object to the user */
Packit 0848f5
    MPID_OBJ_PUBLISH_HANDLE(*win, win_ptr->handle);
Packit 0848f5
Packit 0848f5
    /* ... end of body of routine ... */
Packit 0848f5
Packit 0848f5
  fn_exit:
Packit 0848f5
    MPID_MPI_RMA_FUNC_EXIT(MPID_STATE_MPI_WIN_CREATE_DYNAMIC);
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_win_create_dynamic",
Packit 0848f5
            "**mpi_win_create_dynamic %I %C %p", info, comm, win);
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
}