Fortran 用gnu FFTW 3.3.8计算复输入一维FFT
我使用gnu FFTW 3.3.8来计算具有复杂输入的一维FFT,由于某些原因,事情无法按如下所述工作 当使用FFTW FFTW 3.3.8 from且N=22时,输入和输出都返回为零。在我看来,在这两个值之间,例如16Fortran 用gnu FFTW 3.3.8计算复输入一维FFT,fortran,gfortran,fftw,Fortran,Gfortran,Fftw,我使用gnu FFTW 3.3.8来计算具有复杂输入的一维FFT,由于某些原因,事情无法按如下所述工作 当使用FFTW FFTW 3.3.8 from且N=22时,输入和输出都返回为零。在我看来,在这两个值之间,例如16 program hello implicit none integer N parameter (N = 20) double complex, dimension (N) :: in double complex, dimension
program hello
implicit none
integer N
parameter (N = 20)
double complex, dimension (N) :: in
double complex, dimension (N) :: out
real pi, one
integer i
double precision xone
xone=1.0000000000
pi=4.0*atan(one)
! generate input
do i=1,N
in(i)=xone
end do
call calc_fft(N, in, out)
! print output
do i=1,N
write(*,*)real (in(i)), real (out(i))
end do
! output data into a file
open(1, file = 'dataM.dat', status='new')
do i = 1,N
write(1,*) in(i), out(i)
end do
close(1)
end program hello
subroutine calc_fft(N,in,out)
integer N
double complex, dimension (N) :: in
double complex, dimension (N) :: out
integer*8 plan
integer i
call dfftw_plan_dft_1d(plan,N,in,out,FFTW_FORWARD,FFTW_ESTIMATE)
call dfftw_execute_dft(plan, in, out)
call dfftw_destroy_plan(plan)
end subroutine
gfortran testfftw.f90-L/usr/lib64/-lfftw3
N=16的输入/输出
1.0000000000000000 16.000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
1.0000000000000000 0.0000000000000000
gfortran testfftw.f90 -L/usr/lib64/ -lfftw3
Input / Output for N=20
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000
我使用的是科学Linux 7.6版
uname -a :
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Tue Oct 30 14:13:26 CDT 2018 x86_64 x86_64 x86_64 GNU/Linux
gcc-gfortran-4.8.5
IntelR CoreTM i3-3240 CPU@3.40GHz
使用4gb内存
我也在另一个CPU上尝试过类似的效果一个大问题似乎是calc_fft没有隐式无,所以隐式类型适用于
subroutine calc_fft(N,in,out)
integer N
double complex, dimension (N) :: in
double complex, dimension (N) :: out
...
如果我们添加隐式none作为
这里,FFTW_FORWARD和FFTW_ESTIMATE是需要通过FFTW的头文件定义的一些参数,否则,这些参数将被视为默认实数变量,没有隐式none
并得到了预期的结果。include文件的位置可能因计算机/操作系统而异,而ScientificLinux7似乎在/usr/include中有它们。请参阅,如有必要,请将其作为yum-install-fftw-devel安装。另外,为了获得最佳性能,不同的FFTW包可能比从yum获得的更好,但情况不同…欢迎使用。请检查所有调用的正确性,尤其是数据类型是否正确。Valgrind抱怨内存未初始化,有时我的程序会崩溃。感谢您在编辑方面的帮助。令人费解的是,对于N=22,它停止给出正确的输出,同时也破坏了输入。如果我理解您建议使用输入的副本来运行执行部分?不,我认为这是一个红色的hering。我尝试了fftw_preserve_输入,但没有效果。此外,这次坠机表明问题出在其他地方。通常情况下,您首先只需准备一次计划,然后准备数据并可能多次运行FFT。但我认为这对这里没有帮助。你的例程中没有隐式的none,变量FFTW_*只是隐式的实数标量。但那不是问题所在。。。第一次使用-Wall-fcheck=编译也很好,以避免错误。
subroutine calc_fft(N,in,out)
implicit none !<--
integer N
double complex, dimension (N) :: in
double complex, dimension (N) :: out
...
testfftw.f90:37:67:
call dfftw_plan_dft_1d(plan,N,in,out,FFTW_FORWARD,FFTW_ESTIMATE)
1
Error: Symbol 'fftw_estimate' at (1) has no IMPLICIT type
testfftw.f90:37:53:
call dfftw_plan_dft_1d(plan,N,in,out,FFTW_FORWARD,FFTW_ESTIMATE)
1
Error: Symbol 'fftw_forward' at (1) has no IMPLICIT type
subroutine calc_fft(N, in, out)
implicit none
include 'fftw3.f' !<--
integer N
gfortran testfftw.f90 -L/usr/lib64 -I/usr/include -lfftw3