Fortran代码从简单的解除分配行中崩溃

时间:2019-06-06 23:11:09

标签: fortran

我正在修改一个开源程序,它在执行非常简单的一行时在某些设置下崩溃。我不明白为什么这行会导致程序崩溃。这行是

IF (allocated(bec%k))  DEALLOCATE(bec%k)

此行在崩溃之前被执行了多次,但是在某些程序设置的某个点之后,它使程序崩溃。在执行此行时始终分配bec%k。编译器是gfortran。

导致错误的终端输出说:

free(): invalid next size (normal)
Program received signal SIGABRT: Process abort signal.
Backtrace for this error:
#0  0x7f428db872da in ???
#1  0x7f428db86503 in ???
#2  0x7f428cfe4f1f in ???
#3  0x7f428cfe4e97 in ???
#4  0x7f428cfe6800 in ???
#5  0x7f428d02f896 in ???
#6  0x7f428d036909 in ???
#7  0x7f428d03e0ac in ???
#8  0x56366a04e2b6 in __becmod_MOD_deallocate_bec_type
    at /home/john/Desktop/q-e-qe-6.3/Modules/becmod.f90:401
#9  0x563669e734f4 in update_hamiltonian_
    at /home/john/Desktop/ce-tddft-6.3-another-copy/src/update_ham.f90:61
#10  0x563669e7ab70 in molecule_optical_absorption_
    at /home/john/Desktop/ce-tddft-6.3-another-copy/src/molecule_optical_absorption.f90:538
#11  0x563669e6e2c4 in tddft_main
    at /home/john/Desktop/ce-tddft-6.3-another-copy/src/tddft_main.f90:118
#12  0x563669e6de6e in main
    at /home/john/Desktop/ce-tddft-6.3-another-copy/src/tddft_main.f90:19

我还在输出文件中收到以下错误消息:

mpirun noticed that process rank 0 with PID 0 on node JohnUbuntu exited on signal 6 (Aborted).

如果您有兴趣,这里是该行以及bec数据类型的一部分的子例程

!-----------------------------------------------------------------------
  SUBROUTINE deallocate_bec_type (bec)
    !-----------------------------------------------------------------------
    !
    USE mp, ONLY: mp_get_comm_null
    IMPLICIT NONE
    TYPE (bec_type) :: bec
    !
    bec%comm = mp_get_comm_null()
    bec%nbnd = 0
    !
    IF (allocated(bec%r))  DEALLOCATE(bec%r)
    IF (allocated(bec%nc)) DEALLOCATE(bec%nc)
    IF (allocated(bec%k))  DEALLOCATE(bec%k)
    !
    RETURN
    !
  END SUBROUTINE deallocate_bec_type


  TYPE bec_type
     REAL(DP),   ALLOCATABLE :: r(:,:)    ! appropriate for gammaonly
     COMPLEX(DP),ALLOCATABLE :: k(:,:)    ! appropriate for generic k
     COMPLEX(DP),ALLOCATABLE :: nc(:,:,:)   ! appropriate for noncolin
     INTEGER :: comm
     INTEGER :: nbnd
     INTEGER :: nproc
     INTEGER :: mype
     INTEGER :: nbnd_loc
     INTEGER :: ibnd_begin
  END TYPE bec_type

非常感谢有关引起该问题或执行该操作的建议。

0 个答案:

没有答案