我的目标是并行化用Fortran编写的FFTW串行代码,该代码告诉我们材料中的有限应变分布。我只需并行化前向傅里叶变换和后向变换即可保持原样。 首先可以这样做吗?我尝试这样做,但是遇到了一些细分错误。我实际上可以粘贴整个代码,但是它只有1600行,但是我将在错误仍然存在的地方附加。
假定其他琐碎变量和必需标头的初始化。
complex ( C_DOUBLE_COMPLEX ) , dimension ( : , : , : ), pointer :: in_forward !> @var Array input in FFT
complex ( C_DOUBLE_COMPLEX ) , dimension ( : , : , : ), pointer :: out_forward !> @var Array output in FFT
complex ( C_DOUBLE_COMPLEX ) , dimension ( : , : , : ), allocatable :: in_backward !> @var Array input of FFT-1
complex ( C_DOUBLE_COMPLEX ) , dimension ( : , : , : ), allocatable :: out_backward !> @var Array output for FFT-1
ALLOCATE delta(3,3,npts1,npts2,local_npts3))
integer (kind = i4b ) :: plan_forward
integer (kind = i4b ) :: plan_backward
integer :: AllocateStatus
CALL MPI_INIT(ier)
CALL fftw_mpi_init
call MPI_COMM_SIZE(MPI_COMM_WORLD, size, IER)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, IER)
ur0=0
open(ur0,file='elfft.in',status='old')
read(ur0,'(a)') prosa
read(ur0,*),npts1,npts2,npts3
npts1_c = npts1
npts2_c = npts2
npts3_c = npts3
alloc_local = fftw_mpi_local_size_3d(npts3_c, npts2_c, npts1_c, MPI_COMM_WORLD, local_npts3_c, local_j_offset_c)
local_npts3 = local_npts3_c
local_j_offset = local_j_offset_c
cdata = fftw_alloc_complex(alloc_local)
CALL C_F_POINTER(cdata, in_forward, [npts1_c, npts2_c, local_npts3_c])
do vii=1,3
do vjj=1,3
in_forward(:,:,:) = CMPLX(delta(vii,vjj,:,:,:),0)
if (imicro == 1 .and. iter == 1 .and. vii == 1 .and. vjj == 1 ) then
plan = fftw_mpi_plan_dft_3d(local_npts3_c,npts2_c,npts1_c, in_forward , out_forward, MPI_COMM_WORLD, FFTW_FORWARD, FFTW_ESTIMATE)
print *, 'successful plan creation for forward'
endif
call fftw_mpi_execute_dft( plan,in_forward, out_forward )
.
.
call fftw_destroy_plan(plan)
call fftw_free(cdata)
编译并运行该程序后,出现此错误。 我仍然觉得我做的事情还不完整,希望有一个更好的理解。因此,如果有人可以向我建议任何示例源代码或参考资料,那就太好了。
Error in `./a.out': munmap_chunk(): invalid pointer successful plan creation for forward
successful plan creation for forward
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.