[MPI3 Fortran] MPI_Alloc_mem in Fortran

N.M. Maclaren nmm1 at cam.ac.uk
Wed Oct 13 15:19:46 CDT 2010

MPI_Alloc_mem has two partially related purposes:

    1) To enable an application to control some aspects of MPI's memory
usage, especially for applications which play games with memory.
Providing an object as an argument (rather than just requesting
allocation) is a very 1970s approach, but is still occasionally useful.

    2) To provide a hook for windows that may be used for passive
one-sided communication, where such memory can fairly often be allocated
only by a system-dependent library call.

Even with wording forbidding the user to touch the buffer when in use,
Fortran semantics require the object to have the TARGET attribute.
That being so, one simple specification could be:

    SUBROUTINE MPI_Alloc_mem (size, info, baseptr, ierror)
    C_PTR, INTENT(IN), OPTIONAL :: baseptr

    If baseptr is absent or is C_NULL_PTR, the procedure allocates
    size bytes of space using an unspecified method (which could be
    ALLOCATE).  Otherwise, it must point to a block of memory of size
    at least size bytes, which must not be accessed or manipulated
    in any way by the program until after the call to MPI_Free_mem. 

    If a program needs to use a particular object or force the use of
    ALLOCATE, it can trivially use C_LOC to create a C pointer from
    the object (including a pointer variable allocated by ALLOCATE).

I haven't put the appropriate wording around that but, realistically, I
think that's all that is needed.  The TARGET requirement is already
imposed by C_LOC.  You may prefer rather less use of OPTIONAL :-)
Is there any important requirement that that doesn't meet?

Nick Maclaren.

More information about the mpiwg-fortran mailing list