1
我的主代码存在一些问题,所以我试图找出问题所在。 因此,我有这样的小码:Fortran奇怪的分段错误
MODULE Param
IMPLICIT NONE
integer, parameter :: dr = SELECTED_REAL_KIND(15, 307)
integer :: D =3
integer :: Q=10
integer :: mmo=16
integer :: n=2
integer :: x=80
integer :: y=70
integer :: z=20
integer :: tMax=8
END MODULE Param
module m
contains
subroutine compute(f, r)
USE Param, ONLY: dr, mmo, x, y, z, n
IMPLICIT NONE
real (kind=dr), intent(in) :: f(x,y,z, 0:mmo, n)
real (kind=dr), intent(out) :: r(x, y, z, n)
real (kind=dr) :: fGlob(x,y,z, 0:mmo)
!-------------------------------------------------------------------------
print*, 'We are in compute subroutine'
r= 00.0
fGlob=sum(f,dim=5)
r=sum(f, dim=4)
print*, 'fGlob=', fGlob(1,1,1, 1)
print*, 'f=', f(1,1,1, 0,1)
print*, 'r=', r(1,1,1, 1)
end subroutine compute
end module m
PROGRAM test_prog
USE Param
USE m
Implicit None
integer :: tStep
real (kind=dr), dimension(:,:,:, :,:), allocatable :: f
real (kind=dr), dimension(:,:,:,:), allocatable :: r
!----------------------------------------------------------------------------
! Initialise the parameters.
print*, 'beginning of the test'
! Allocate
allocate(f(x,y,z, 0:mmo,n))
allocate(r(x,y,z, n))
f=1.0_dr
! ---------------------------------------------------------
! Iteration over time
! ---------------------------------------------------------
do tStep = 1, tMax
print *, tStep
call compute(f,r)
f=f+1
print *, 'tStep', tStep
enddo
print*, 'f=', f(1,1,1, 0,1)
print*, 'r=', r(1,1,1, 1)
! Deallacation
deallocate(f)
deallocate(r)
print*, 'End of the test program'
END PROGRAM test_prog
现在,我无法理解为什么当我ifort
编译,我有一个segmentation fault
,当我与gfortran
编译工作。而最糟糕的是,当我编译ifort
和gfortran
以及它们的fast
选项时,我再次遇到segmentation fault (core dumped)
错误。而更令人困惑的是,当我也试着用两种编译器编译traceback
选项时,一切正常。
我知道segmentation fault (core dumped)
错误通常意味着我尝试读取或写入错误的位置(矩阵索引等);但是在这个小代码中,我没有看到像这样的错误。
有没有人可以帮助我理解为什么会出现这些错误?
阅读此内容 - https://software.intel.com/zh-CN/articles/determining-root-cause-of-sigsegv-or-sigbus-errors - 并在检查完所有问题后回报它引发了。 –
有一个小的mcve很好。尽管如此,请尝试编译器提供的调试选项:-g -fcheck = all -Wall''-g -traceback -check -warn'。 –
我会继续调查您的链接中的内容。但我认为这个问题是堆栈溢出问题。我会向你证实这一点。无论如何,感谢这个有用的链接,我没有发现当我谷歌搜索。 –