I’m a newbie to CUDA Fortran.I have searched the forum for this error “Segmentation fault (core dumped)” and read some replies but it didn’t solve the problem.If anyone can provide me with hints or solutions to the problem,it would be grateful.
The source code is:
module precision
! Precision control
integer, parameter, public :: Single = kind(0.0) ! Single precision
integer, parameter, public :: Double = kind(0.0d0) ! Double precision
integer, parameter, public :: fp_kind = Double
!integer, parameter, public :: fp_kind = Single
module cufft
integer, public :: CUFFT_FORWARD = -1
integer, public :: CUFFT_R2C = Z'2a' ! Real to Complex (interleaved)
integer, public :: CUFFT_D2Z = Z'6a' ! Double to Double-Complex
interface cufftPlan1d
subroutine cufftPlan1d(plan, nx, type, batch) bind(C,name='cufftPlan1d')
use iso_c_binding
integer(c_int):: plan
integer(c_int),value:: nx, batch,type
end subroutine cufftPlan1d
end interface cufftPlan1d
interface cufftDestroy
subroutine cufftDestroy(plan) bind(C,name='cufftDestroy')
use iso_c_binding
integer(c_int),value:: plan
end subroutine cufftDestroy
end interface cufftDestroy
interface cufftExecD2Z
subroutine cufftExecD2Z(plan, idata, odata, direction) &
bind(C,name='cufftExecD2Z')
use iso_c_binding
use precision
integer(c_int),value:: direction
integer(c_int),value:: plan
complex(fp_kind),device:: idata(*),odata(*)
end subroutine cufftExecD2Z
end interface cufftExecD2Z
end module cufft
program fft_test
use precision
use cufft
complex(fp_kind) ,allocatable:: a(:),b(:)
complex(fp_kind),device,allocatable:: a_d(:),b_d(:)
integer:: n
integer:: plan
integer :: x
n=2048
a=1
! allocate arrays on the host
allocate (a(n),b(n))
! allocate arrays on the device
allocate (a_d(n))
allocate (b_d(n))
DO x=1,1024
a(x)=a(x)+a(x)*6+1
!copy arrays to device
a_d=a
! Print initial array
print *, "Array A:"
print *, a(x)
! Initialize the plan
call cufftPlan1D(plan,n,CUFFT_D2Z,1)
! Execute FFTs
call cufftExecD2Z(plan,a_d,b_d,CUFFT_FORWARD)
! Copying results back to host
b=b_d
! Printing initial array
print *, "Array B"
print *, b(x)
!releasing memory on the host
deallocate (a,b)
!releasing memory on the device
deallocate (a_d,b_d)
! Destroying the plan
call cufftDestroy(plan)
end DO
end program fft_test