Consider a 2D transform of the form L x M (column major setup), from a complex array src to a real array tgt. Or , in Fortranese,
complex(C_DOUBLE_COMPLEX), pointer :: src(:,:)
real(8), pointer :: tgt(:,:) .
Corresponding pointers are
type(C_PTR) :: csrc,ctgt .
I would allocate them in the following manner:
! The complex array first
alloc_local = fftw_mpi_local_size_2d(M,L/2+1,MPI_COMM_WORLD,local_M,local_offset1)
csrc = fftw_alloc_complex(alloc_local)
call c_f_pointer(csrc, src, [L/2,local_M])
! Now the real array
alloc_local = fftw_mpi_local_size_2d(2*(L/2+1),M, &
MPI_COMM_WORLD,local_L,local_offset2)
ctgt = fftw_alloc_real(alloc_local)
call c_f_pointer(ctgt, tgt, [M,local_L])
Now, the plan would be created as:
! Create c-->r transform with one transposition left out
plan = fftw_mpi_plan_dft_c2r_2d(M,L,src,tgt, MPI_COMM_WORLD, &
ior(FFTW_MEASURE,FFTW_MPI_TRANSPOSED_OUT))
Finally, the transform would be performed as:
call fftw_mpi_execute_dft_c2r(plan, src, tgt)
However, this prescription does not work. The last call causes a segmentation fault. At first, i thought this might have something to do with how I allocate src and tgt arrays, but playing with different amount of memory allocated to tgt did not give any result. So, I am either doing something really silly, or this is not possible to do at all.
EDIT : MINIMALISTIC COMPILEABLE EXAMPLE
program trashingfftw
use, intrinsic :: iso_c_binding
use MPI
implicit none
include 'fftw3-mpi.f03'
integer(C_INTPTR_T), parameter :: L = 256
integer(C_INTPTR_T), parameter :: M = 256
type(C_PTR) :: plan, ctgt, csrc
complex(C_DOUBLE_COMPLEX), pointer :: src(:,:)
real(8), pointer :: tgt(:,:)
integer(C_INTPTR_T) :: alloc_local, local_M, &
& local_L,local_offset1,local_offset2
integer :: ierr,id
call mpi_init(ierr)
call mpi_comm_rank(MPI_COMM_WORLD,id,ierr)
call fftw_mpi_init()
alloc_local = fftw_mpi_local_size_2d(M,L/2+1, MPI_COMM_WORLD, &
local_M, local_offset1)
csrc = fftw_alloc_complex(alloc_local)
call c_f_pointer(csrc, src, [L/2,local_M])
alloc_local = fftw_mpi_local_size_2d(2*(L/2+1),M, MPI_COMM_WORLD, &
& local_L, local_offset2)
ctgt = fftw_alloc_real(alloc_local)
call c_f_pointer(ctgt, tgt, [M,local_L])
plan = fftw_mpi_plan_dft_c2r_2d(M,L,src,tgt, MPI_COMM_WORLD, &
ior(FFTW_MEASURE, FFTW_MPI_TRANSPOSED_OUT))
call fftw_mpi_execute_dft_c2r(plan, src, tgt)
call mpi_finalize(ierr)
end program trashingfftw
See Question&Answers more detail:
os