将函数传递给参数ifort vs gfortran

时间:2018-03-09 17:06:12

标签: fortran

我遇到了一个问题,因为我试图用ifort运行我的fortran代码,ifort之前是用gfortran编译的。我的代码函数之一是使用其他函数作为参数,如下所示。使用gfortran / ifort编译代码不会产生任何错误。

module mod_rk4_2

implicit none 

contains 


!rk4 temporal scheme 
function rk4(f,dt,func) result(f_new)

double precision, dimension(:,:), intent(in) :: f
double precision, intent(in) :: dt 
double precision, dimension(size(f,1),size(f,2)) :: f_new
double precision, dimension(:,:), allocatable ::  k1, k2, k3, k4

interface 
    function func(f) result(res)
        double precision, dimension(:,:), intent(in) :: f
        double precision, dimension(size(f,1),size(f,2)) ::  res
    end function func
end interface 


allocate(k1(size(f,1),size(f,2)),k2(size(f,1),size(f,2)),k3(size(f,1),size(f,2)),k4(size(f,1),size(f,2)))

k1=func(f)
k2=func(f+dt*k1/2)
k3=func(f+dt*k2/2)
k4=func(f+dt*k3)


f_new=f+dt/6*(k1+2*k2+2*k3+k4)

deallocate(k1,k2,k3,k4)


end function rk4

end module mod_rk4_2

运行使用gfortran编译的代码很好,但是当使用ifort编译时,代码在前面提到的函数的第一次调用时崩溃,并出现堆栈溢出错误消息。有任何想法吗 ?

forrtl: severe (170): Program Exception - stack overflow
Image              PC                Routine            Line        Source
main               00007FF779CCAE38  Unknown               Unknown  Unknown
main               00007FF779C564E0  Unknown               Unknown  Unknown
main               00007FF779CCAC02  Unknown               Unknown  Unknown
main               00007FF779CCB04C  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FF9D8EC1FE4  Unknown               Unknown  Unknown
ntdll.dll          00007FF9D99BEFC1  Unknown               Unknown  Unknown

0 个答案:

没有答案