13.2.3. Window That Allocates Shared Memory

PreviousUpNext
Up: Initialization Next: Window of Dynamically Attached Memory Previous: Window That Allocates Memory

MPI_WIN_ALLOCATE_SHARED(size, disp_unit, info, comm, baseptr, win)
IN sizesize of local window in bytes (non-negative integer)
IN disp_unitlocal unit size for displacements, in bytes (positive integer)
IN infoinfo argument (handle)
IN commintra-communicator (handle)
OUT baseptraddress of local allocated window segment (choice)
OUT winwindow object (handle)
C binding
int MPI_Win_allocate_shared(MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, void *baseptr, MPI_Win *win)
int MPI_Win_allocate_shared_c(MPI_Aint size, MPI_Aint disp_unit, MPI_Info info, MPI_Comm comm, void *baseptr, MPI_Win *win)
Fortran 2008 binding
MPI_Win_allocate_shared(size, disp_unit, info, comm, baseptr, win, ierror)

USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR
INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(IN) :: size
INTEGER, INTENT(IN) :: disp_unit
TYPE(MPI_Info), INTENT(IN) :: info
TYPE(MPI_Comm), INTENT(IN) :: comm
TYPE(C_PTR), INTENT(OUT) :: baseptr
TYPE(MPI_Win), INTENT(OUT) :: win
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_Win_allocate_shared(size, disp_unit, info, comm, baseptr, win, ierror) !(_c)

USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR
INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(IN) :: size, disp_unit
TYPE(MPI_Info), INTENT(IN) :: info
TYPE(MPI_Comm), INTENT(IN) :: comm
TYPE(C_PTR), INTENT(OUT) :: baseptr
TYPE(MPI_Win), INTENT(OUT) :: win
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_WIN_ALLOCATE_SHARED(SIZE, DISP_UNIT, INFO, COMM, BASEPTR, WIN, IERROR)

INTEGER(KIND=MPI_ADDRESS_KIND) SIZE, BASEPTR
INTEGER DISP_UNIT, INFO, COMM, WIN, IERROR

This procedure is collective over the group of comm. On each MPI process, it allocates memory of at least size bytes that is shared among all MPI processes in comm, and returns a pointer to the locally allocated segment in baseptr that can be used for load/store accesses on the calling MPI process. The locally allocated memory can be the target of load/store accesses by remote MPI processes; the base pointers for other MPI processes can be queried using the function MPI_WIN_SHARED_QUERY. The call also returns a handle to a new window that can be used by all MPI processes in comm to perform RMA operations. The size argument may be different at each MPI process and size = 0 is valid. It is the user's responsibility to ensure that the communicator comm represents a group of MPI processes that are in the same shared memory domain, i.e., that they can create a shared memory segment that can be accessed by all processes in the group. The discussions of rationales for MPI_ALLOC_MEM and MPI_FREE_MEM in Section Memory Allocation also apply to MPI_WIN_ALLOCATE_SHARED; in particular, see the rationale in Section Memory Allocation for an explanation of the type used for baseptr. The allocated memory is contiguous across processes in rank order unless the info key alloc_shared_noncontig is specified. Contiguous across processes in rank order means that the first address in the memory segment of MPI process i is consecutive with the last address in the memory segment of MPI process i-1. This may enable the user to calculate remote address offsets with local information only.

If the Fortran compiler provides TYPE(C_PTR), then the following generic interface must be provided in the mpi module and should be provided in the (deprecated) mpif.h include file through overloading, i.e., with the same routine name as the routine with INTEGER(KIND=MPI_ADDRESS_KIND) BASEPTR, but with a different specific procedure name:


INTERFACE MPI_WIN_ALLOCATE_SHARED 
    SUBROUTINE MPI_WIN_ALLOCATE_SHARED(SIZE, DISP_UNIT, INFO, COMM, & 
            BASEPTR, WIN, IERROR) 
        IMPORT :: MPI_ADDRESS_KIND 
        INTEGER :: DISP_UNIT, INFO, COMM, WIN, IERROR 
        INTEGER(KIND=MPI_ADDRESS_KIND) :: SIZE, BASEPTR 
    END SUBROUTINE 
    SUBROUTINE MPI_WIN_ALLOCATE_SHARED_CPTR(SIZE, DISP_UNIT, INFO, COMM, & 
            BASEPTR, WIN, IERROR) 
        USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR 
        IMPORT :: MPI_ADDRESS_KIND 
        INTEGER :: DISP_UNIT, INFO, COMM, WIN, IERROR 
        INTEGER(KIND=MPI_ADDRESS_KIND) :: SIZE 
        TYPE(C_PTR) :: BASEPTR 
    END SUBROUTINE 
END INTERFACE 
The base procedure name of this overloaded function is MPI_WIN_ALLOCATE_SHARED_CPTR. The implied specific procedure names are described in Section Interface Specifications, Procedure Names, and the Profiling Interface.

The info argument can be used to specify hints similar to the info argument for MPI_WIN_CREATE, MPI_WIN_ALLOCATE, and MPI_ALLOC_MEM. The additional info key alloc_shared_noncontig allows the library to optimize the layout of the shared memory segments in memory.


Advice to users.

If the info key alloc_shared_noncontig is not set to true, the allocation strategy is to allocate contiguous memory across MPI process ranks. This may limit the performance on some architectures because it does not allow the implementation to modify the data layout (e.g., padding to reduce access latency). ( End of advice to users.)

Advice to implementors.

If the user sets the info key alloc_shared_noncontig to true, the implementation can allocate the memory requested by each MPI process in a location that is close to this MPI process. This can be achieved by padding or allocating memory in special memory segments. Both techniques may make the address space across consecutive ranks noncontiguous. ( End of advice to implementors.)
For contiguous shared memory allocations, the default alignment requirements outlined for MPI_ALLOC_MEM in Section Memory Allocation and the mpi_minimum_memory_alignment info key apply to the start of the contiguous memory that is returned in baseptr to the first MPI process with nonzero size argument. For noncontiguous memory allocations, the default alignment requirements and the mpi_minimum_memory_alignment info key apply to all MPI processes with nonzero size argument.


Advice to users.

If the info key alloc_shared_noncontig is not set to true (or ignored by the MPI implementation), the alignment of the memory returned in baseptr to all but the first MPI process with nonzero size argument depends on the value of the size argument provided by other MPI processes. It is thus the user's responsibility to control the alignment of contiguous memory allocated for these MPI processes by ensuring that each MPI process provides a size argument that is an integral multiple of the alignment required for the application. ( End of advice to users.)
The consistency of load/store accesses from/to the shared memory as observed by the user program depends on the architecture. For details on how to create a consistent view see the description of MPI_WIN_SHARED_QUERY.

MPI_WIN_SHARED_QUERY(win, rank, size, disp_unit, baseptr)
IN winshared memory window (handle)
IN rankrank in the group of window win or MPI_PROC_NULL (non-negative integer)
OUT sizesize of the window segment (non-negative integer)
OUT disp_unitlocal unit size for displacements, in bytes (positive integer)
OUT baseptraddress for load/store access to window segment (choice)
C binding
int MPI_Win_shared_query(MPI_Win win, int rank, MPI_Aint *size, int *disp_unit, void *baseptr)
int MPI_Win_shared_query_c(MPI_Win win, int rank, MPI_Aint *size, MPI_Aint *disp_unit, void *baseptr)
Fortran 2008 binding
MPI_Win_shared_query(win, rank, size, disp_unit, baseptr, ierror)

USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR
TYPE(MPI_Win), INTENT(IN) :: win
INTEGER, INTENT(IN) :: rank
INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(OUT) :: size
INTEGER, INTENT(OUT) :: disp_unit
TYPE(C_PTR), INTENT(OUT) :: baseptr
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_Win_shared_query(win, rank, size, disp_unit, baseptr, ierror) !(_c)

USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR
TYPE(MPI_Win), INTENT(IN) :: win
INTEGER, INTENT(IN) :: rank
INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(OUT) :: size, disp_unit
TYPE(C_PTR), INTENT(OUT) :: baseptr
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_WIN_SHARED_QUERY(WIN, RANK, SIZE, DISP_UNIT, BASEPTR, IERROR)

INTEGER WIN, RANK, DISP_UNIT, IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) SIZE, BASEPTR

This function queries the MPI process-local address for remote memory segments created with MPI_WIN_ALLOCATE_SHARED, MPI_WIN_ALLOCATE, and MPI_WIN_CREATE. This function can return different MPI process-local addresses for the same physical memory when called by different MPI processes. The returned memory can be used for load/store accesses subject to the constraints defined in Section Semantics and Correctness. When rank is MPI_PROC_NULL, the baseptr, disp_unit, and size returned are the base, displacement unit, and size of the memory segment belonging to the MPI process with the lowest rank in the shared memory domain that specified size > 0. If all MPI processes in the group attached to the window specified size = 0, then the call returns size = 0 and a baseptr as if MPI_ALLOC_MEM was called with size = 0.

Only MPI_WIN_ALLOCATE_SHARED is guaranteed to allocate shared memory. Implementations are permitted, where possible, to provide shared memory for windows created with MPI_WIN_CREATE and MPI_WIN_ALLOCATE. However, availability of shared memory is not guaranteed. When the remote memory segment corresponding to a particular process cannot be accessed directly, this call returns size = 0 and a baseptr as if MPI_ALLOC_MEM was called with size = 0.


Rationale.

MPI_WIN_SHARED_QUERY may only be called on windows created by a call to MPI_WIN_ALLOCATE_SHARED, MPI_WIN_ALLOCATE, or MPI_WIN_CREATE. The potential for multiple memory regions in windows created through MPI_WIN_CREATE_DYNAMIC means that these windows cannot be used as input for MPI_WIN_SHARED_QUERY. ( End of rationale.)

Advice to users.

For windows allocated using MPI_WIN_ALLOCATE or MPI_WIN_CREATE, the group of MPI processes for which the implementation may provide shared memory can be determined using MPI_COMM_SPLIT_TYPE described in Section Communicator Constructors. ( End of advice to users.)
The consistency of load/store accesses from/to the shared memory as observed by the user program depends on the architecture. A consistent view can be created in the unified memory model (see Section Memory Model) by utilizing the window synchronization functions (see Section Synchronization Calls) or explicitly completing outstanding store accesses (e.g., by calling MPI_WIN_FLUSH). MPI does not define the semantics for accessing shared window memory in the separate memory model.

If the Fortran compiler provides TYPE(C_PTR), then the following generic interface must be provided in the mpi module and should be provided in the (deprecated) mpif.h include file through overloading, i.e., with the same routine name as the routine with INTEGER(KIND=MPI_ADDRESS_KIND) BASEPTR, but with a different specific procedure name:


INTERFACE MPI_WIN_SHARED_QUERY 
    SUBROUTINE MPI_WIN_SHARED_QUERY(WIN, RANK, SIZE, DISP_UNIT, & 
            BASEPTR, IERROR) 
        IMPORT :: MPI_ADDRESS_KIND 
        INTEGER :: WIN, RANK, DISP_UNIT, IERROR 
        INTEGER(KIND=MPI_ADDRESS_KIND) :: SIZE, BASEPTR 
    END SUBROUTINE 
    SUBROUTINE MPI_WIN_SHARED_QUERY_CPTR(WIN, RANK, SIZE, DISP_UNIT, & 
            BASEPTR, IERROR) 
        USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR 
        IMPORT :: MPI_ADDRESS_KIND 
        INTEGER :: WIN, RANK, DISP_UNIT, IERROR 
        INTEGER(KIND=MPI_ADDRESS_KIND) :: SIZE 
        TYPE(C_PTR) :: BASEPTR 
    END SUBROUTINE 
END INTERFACE 
The base procedure name of this overloaded function is MPI_WIN_SHARED_QUERY_CPTR. The implied specific procedure names are described in Section Interface Specifications, Procedure Names, and the Profiling Interface.


PreviousUpNext
Up: Initialization Next: Window of Dynamically Attached Memory Previous: Window That Allocates Memory


Return to MPI-4.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-4.1 of November 2, 2023
HTML Generated on November 19, 2023