@@ -23,8 +23,8 @@ C Syntax
2323 int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr)
2424
2525
26- Fortran Syntax (see FORTRAN NOTES)
27- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+ Fortran Syntax
27+ ^^^^^^^^^^^^^^
2828
2929.. code-block :: fortran
3030
@@ -74,40 +74,31 @@ pointer object for this parameter. The provided argument should be a
7474pointer to a pointer of arbitrary type (e.g., ``void ** ``).
7575
7676
77- FORTRAN NOTES
77+ Fortran NOTES
7878-------------
7979
80- There is no portable FORTRAN 77 syntax for using :ref: `MPI_Alloc_mem `. There is
81- no portable Fortran syntax for using pointers returned from
82- :ref: `MPI_Alloc_mem `. However, :ref: `MPI_Alloc_mem ` can be used with Sun Fortran
83- compilers.
84-
85- From FORTRAN 77, you can use the following non-standard declarations for
86- the SIZE and BASEPTR arguments:
80+ The :ref: `MPI_Alloc_mem ` calls require the use of the ``iso_c_binding `` module
81+ for due to the use of ``TYPE(C_PTR) ``.
8782
8883.. code-block :: fortran
8984
90- INCLUDE "mpif.h"
91- INTEGER*MPI_ADDRESS_KIND SIZE, BASEPTR
92-
93-
94- From either FORTRAN 77 or Fortran 90, you can use "Cray pointers" for
95- the BASEPTR argument. Cray pointers are described further in the Fortran
96- User's Guide and are supported by many Fortran compilers. For example,
85+ use iso_c_binding
9786
98- .. code-block :: fortran
87+ type(c_ptr) :: alloc_ptr
88+ integer :: size, ierr
89+ double precision, pointer :: array(:,:)
9990
100- INCLUDE "mpif.h"
101- REAL*4 A(100,100)
102- POINTER (BASEPTR, A)
103- INTEGER*MPI_ADDRESS_KIND SIZE
91+ ! A 2D array of 100 elements
92+ size = 10 * 10
93+ call MPI_Alloc_Mem(size * 8, MPI_INFO_NULL, alloc_ptr, ierr)
10494
105- SIZE = 4 * 100 * 100
106- CALL MPI_ALLOC_MEM(SIZE,MPI_INFO_NULL,BASEPTR,IERR )
95+ ! Point to the array
96+ call c_f_pointer(alloc_ptr, array, [10, 10] )
10797
108- ! use A
98+ ! ... use the array ...
10999
110- CALL MPI_FREE_MEM(A, IERR)
100+ ! Free the memory, no need for the alloc_ptr
101+ call MPI_Free_mem(array, ierr)
111102
112103
113104 ERRORS
0 commit comments