Deallocate语句导致崩溃

时间:2013-07-19 22:03:41

标签: windows gcc fortran90 gfortran

我正在处理崩溃的代码。我意识到编译后的程序在解除变量时会崩溃,但我不知道如何修复它。

当我运行代码时,Windows弹出窗口显示:

main.exe has stopped working. Windows can check for a solution to the problem.

,编译器显示消息Process returned -1073740940 (0xC0000374) execution time : 1.171 s

Bellow有一个代码示例:

Subroutine PoissonCode()
Use Mesh
Implicit none
Real(8), Allocatable :: u(:,:),v(:,:),p(:,:)
Character(50) :: Nome
Allocate(u(0:Imax,0:jmax),v(0:Imax,0:jmax),p(0:Imax,0:jmax),fx(0:Imax,0:jmax),fy(0:Imax,0:jmax))
Allocate(xd(0:Imax),yd(0:Jmax))

........Code Here...............

Deallocate(u,v,p,fx,fy,xd,yd)
Deallocate(xd,yd)

End Subroutine PoissonCode

我将完整的代码here用于进一步调查。 我还尝试在Windows 7 x64和Windows XP x86中使用不同版本的GFortran运行代码,但没有成功。

修改:

代码的正确结尾是:

...

Deallocate(u,v,p,fx,fy)
Deallocate(xd,yd)

End Subroutine PoissonCode

上线日期:

我使用不同的编译器(英特尔Visual Fortran)测试了代码,但仍未成功。

1 个答案:

答案 0 :(得分:1)

D'uhhhh(对我们所有人)

Deallocate(u,v,p,fx,fy,xd,yd)
Deallocate(xd,yd)

在第二行中,您的程序(尝试)释放已在第一行中释放的变量。我想有时阅读已发布的代码是值得的。

deallocate具有可选参数staterrmsg,可用于捕获此类错误,并提供替代程序崩溃的默认行为。