In some systems, message-passing and remote-memory-access (RMA/) operations run faster when accessing specially allocated memory (e.g., memory that is shared by the other processes in the communicating group on an SMP). MPI-/ provides a mechanism for allocating and freeing such special memory. The use of such memory for message passing or RMA/ is not mandatory, and this memory can be used without restrictions as any other dynamically allocated memory. However, implementations may restrict the use of the MPI_WIN_LOCK and MPI_WIN_UNLOCK functions to windows allocated in such memory (see Section 6.4.3.)
MPI_ALLOC_MEM(size, info, baseptr)
int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr)
MPI_ALLOC_MEM(SIZE, INFO, BASEPTR, IERROR) INTEGER INFO, IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) SIZE, BASEPTR
int MPI::Alloc_mem(MPI::Aint size, const MPI::Info& info)
void*
The info argument can be used to provide directives that control the desired location of the allocated memory. Such a directive does not affect the semantics of the call. Valid info values are implementation-dependent; a null directive value of info = MPI_INFO_NULL is always valid.
The function MPI_ALLOC_MEM may return an error code of class MPI_ERR_NO_MEM to indicate it failed because memory is exhausted.
int MPI_Free_mem(void *base)
MPI_FREE_MEM(BASE, IERROR) <type> BASE(*)
INTEGER IERROR
int MPI::Free_mem(void *base)
void
The function MPI_FREE_MEM may return an error code of class MPI_ERR_BASE to indicate an invalid base argument.
A call to MPI_ALLOC_MEM can be used in shared memory systems to allocate memory in a shared memory segment.(End of advice to implementors.)
Example of use of MPI_ALLOC_MEM, in Fortran with pointer support. We assume 4-byte REALs, and assume that pointers are address-sized.
REAL A POINTER (P, A(100,100)) ! no memory is allocated CALL MPI_ALLOC_MEM(4*100*100, MPI_INFO_NULL, P, IERR) ! memory is allocated ... A(3,5) = 2.71; ... CALL MPI_FREE_MEM(A, IERR) ! memory is freed
Since standard Fortran does not support (C-like) pointers, this code is not Fortran 77 or Fortran 90 code. Some compilers (in particular, at the time of writing, g77 and Fortran compilers for Intel) do not support this code.
float (* f)[100][100] ; MPI_Alloc_mem(sizeof(float)*100*100, MPI_INFO_NULL, &f); ... (*f)[5][3] = 2.71; ... MPI_Free_mem(f);
MPI-Standard for MARMOT