我需要使用MPI在Fortran中对3D数组进行FFT。我一直在看FFTW网站,我也尝试在线查找示例,但我只能找到这个代码:
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)
此代码计算二维数组的FFT变换。我的问题是:如何使用此代码计算3d数组的FFT变换?
答案 0 :(得分:1)
关于fftw_mpi_plan_dft_2d
,请查看:
http://www.fftw.org/doc/MPI-Plan-Creation.html
很明显,必须有fftw_mpi_plan_dft_3d
函数。 fftw_mpi_local_size_2d
当然也是如此。参数会略有变化,但文档会对此有所帮助。