运行FORTRAN代码时遇到一些问题。
当我尝试DEALLOCATE特定变量时会发生此错误。
我实际上并不了解如何找到解决问题的方法......
我的错误消息如下:
Error in `my_app.x': double free or corruption (!prev): 0x00000000042e5520 **
Program received signal SIGABRT: Process abort signal.
#8 0x6F692B in __My_mod_deallocate_VARIABLE at deallocate_VARIABLE.f:415 (discriminator 2)
为了解决我的问题,我使用了所有类型的GNU FORTRAN编译器选项:
-g -Wall -fbacktrace -finit-local-zero -ffpe-trap=invalid,zero,overflow -fbounds-check -fcheck=all
我实际上是在尝试打印不同的值:
当我分配我的变量时,首先是
INTEGER, ALLOCATABLE,DIMENSION(:) :: MY_VARIABLE
ALLOCATE(MY_VARIABLE (257))
MY_VARIABLE = 0
WRITE(7,*), 'IAM ALLOCATIONG MY VARIABLE'
IF (ALLOCATED (MY_VARIABLE)) WRITE(7,*), 'MY_VARIABLE_ALLOCATED ','OUI'
IF (.NOT.ALLOCATED(MY_VARIABLE)) WRITE(7,*),'MY_VARIABLE ','NON'
WRITE(7,*),'09 LOC(MY_VARIABLE )',LOC( MY_VARIABLE )
WRITE(7,*), '09 SHAPE (MY_VARIABLE)', SHAPE(MY_VARIABLE)
WRITE(7,*), '09 LBOUND (MY_VARIABLE)', LBOUND(MY_VARIABLE)
WRITE(7,*), '09 UBOUND (MY_VARIABLE)', UBOUND(MY_VARIABLE)
我有一些令人满意的结果:
IAM ALLOCATIONG MY VARIABLE
09 MY_VARIABLE_ALLOCATED OUI
09 LOC(MY_VARIABLE ) 76719840
09 SHAPE (MY_VARIABLE) 257
09 LBOUND (MY_VARIABLE) 1
09 UBOUND (MY_VARIABLE) 257
然后,一些例程正在运行,在执行结束之前,我想释放MY_VARIABLE。
在释放我的变量之前,我执行了另一项测试:
WRITE(7,*), 'IAM DEALLOCATIONG MY VARIABLE'
IF (ALLOCATED (MY_VARIABLE)) WRITE(7,*), 'MY_VARIABLE_ALLOCATED ','OUI'
IF (.NOT.ALLOCATED(MY_VARIABLE)) WRITE(7,*),'MY_VARIABLE ','NON'
WRITE(7,*),'09 LOC(MY_VARIABLE )',LOC( MY_VARIABLE )
WRITE(7,*), '09 SHAPE (MY_VARIABLE)', SHAPE(MY_VARIABLE)
WRITE(7,*), '09 LBOUND (MY_VARIABLE)', LBOUND(MY_VARIABLE)
WRITE(7,*), '09 UBOUND (MY_VARIABLE)', UBOUND(MY_VARIABLE)
结果又是:
IAM DEALLOCATIONG MY VARIABLE
09 MY_VARIABLE_ALLOCATED OUI
09 LOC(MY_VARIABLE ) 76719840
09 SHAPE (MY_VARIABLE) 257
09 LBOUND (MY_VARIABLE) 1
09 UBOUND (MY_VARIABLE) 257
然后,我使用FORTRAN DEALLOCATING语句:
DEALLOCATE( MY_VARIABLE )
我遗憾地遇到了跑步错误。
有没有人对如何解决这类错误有一些线索? 非常感谢。