I need to make a FFT of a 3D array in Fortran using MPI. I've been looking at the FFTW website and I also tried to look for examples online but I could find only this code:
use, intrinsic :: iso_c_binding
include 'fftw3-mpi.f03'
integer(C_INTPTR_T), parameter :: L = ...
integer(C_INTPTR_T), parameter :: M = ...
type(C_PTR) :: plan, cdata
complex(C_DOUBLE_COMPLEX), pointer :: data(:,:)
integer(C_INTPTR_T) :: i, j, alloc_local, local_M, local_j_offset
! get local data size and allocate (note dimension reversal)
alloc_local = fftw_mpi_local_size_2d(M, L, MPI_COMM_WORLD, &
local_M, local_j_offset)
cdata = fftw_alloc_complex(alloc_local)
call c_f_pointer(cdata, data, [L,local_M])
! create MPI plan for in-place forward DFT (note dimension reversal)
plan = fftw_mpi_plan_dft_2d(M, L, data, data, MPI_COMM_WORLD, &
FFTW_FORWARD, FFTW_MEASURE)
! initialize data to some function my_function(i,j)
do j = 1, local_M
do i = 1, L
data(i, j) = my_function(i, j + local_j_offset)
end do
end do
! compute transform (as many times as desired)
call fftw_mpi_execute_dft(plan, data, data)
call fftw_destroy_plan(plan)
call fftw_free(cdata)
This code computes the FFT transform of a 2d array. My question is: how can I use this code to compute a FFT transform of a 3d array?
Regarding fftw_mpi_plan_dft_2d
have a look at:
http://www.fftw.org/doc/MPI-Plan-Creation.html
It is quite obvious that there must be a fftw_mpi_plan_dft_3d
function as well. The same of course for fftw_mpi_local_size_2d
. The arguments will change slightly but the documentation will help you on this.