Using MPI_Shared memory with multidimensional arrays

Hi,

I am trying use shared mpi mem (per Node) for allocating a N-Dimensional array. Following a simple example* I can get a C pointer (1d) to the shared memory location. My question is how can I best “map” or “wrap” the N-Dim Fortran array (used later on) to this C-pointer without using additional memory or tmp variables. Can you share an example? (or adapt the one on the link)

*https://stackoverflow.com/questions/24797298/mpi-fortran-code-how-to-share-data-on-node-via-openmp (the title of the thread is missleading)

Thanks!,
Sebastian

This seems to be the answer:

call C_F_POINTER (C_LOC(rank1_array), rank3_array, [3,2,4])

I had to figure this out last week (Kernels/transpose-get-mpi.F90 at a1a6df2c7d0a1a3909f59b82961dd6c13dac9cf2 · ParRes/Kernels · GitHub).

I’m adding the answer here since StackOverflow might disappear.

  integer(kind=INT32) ::  order, block_order
  type(MPI_Win) :: WA                               ! MPI window for A (original matrix)
  type(c_ptr) :: XA                                 ! MPI baseptr / C pointer for A
  real(kind=REAL64), pointer     ::  A(:,:)         ! Fortran pointer to A
  integer(kind=MPI_ADDRESS_KIND) :: wsize
  integer(kind=INT32) :: dsize
!...
  dsize = storage_size(one)/8
  ! MPI_Win_allocate(size, disp_unit, info, comm, baseptr, win, ierror)
  wsize = block_order * order * dsize
  call MPI_Win_allocate(size=wsize, disp_unit=dsize, &
                        info=MPI_INFO_NULL, comm=MPI_COMM_WORLD, baseptr=XA, win=WA)
  call MPI_Win_lock_all(0,WA)

  call c_f_pointer(XA,A,[block_order,order])
2 Likes