关于deallocate
代码如下:subroutinereset(this)
! ====变量声明====
implicit none
class(t_npod_norm_info),intent(inout)::this
integer(kind=i4b) ::is
! ====执行代码====
this%ndim = 0
if ( this%l_init ) then
this%l_init = .false.
if ( allocated(this%rnorm) ) deallocate(this%rnorm, stat=is)
if ( allocated(this%rnorm_inv)) deallocate(this%rnorm_inv, stat=is)
if ( allocated(this%rwy) ) deallocate(this%rwy, stat=is)
if ( allocated(this%rx) ) deallocate(this%rx, stat=is)
write(*,*)'begin'
if ( allocated(this%rh) ) deallocate(this%rh, stat=is)
write(*,*)'end'
end if
end subroutine reset
该代码不是每次运行都出错,偶尔会出错,出错现象比较奇怪,程序直接终止,没有任何出错信息提示。(1)屏幕输出begin后终止,不会输出end(2)没有出现常规出错的提示框
我是用的是vs2012+IVF 2013
希望请教,这种情况如何差错。
用的什么操作系统?什么编译器?
是否用到了混编?第三方库? vvt 发表于 2019-1-28 17:44
用的什么操作系统?什么编译器?
是否用到了混编?第三方库?
操作系统是win 10, 编译器visual studio 2012+ ivf 2013
没有使用混编,纯Fortran,未使用第三方库。
奇怪的是,成功需终止,没有任何出错信息。 在 end subroutine前加 pause 试试。 本帖最后由 pasuka 于 2019-1-29 09:11 编辑
lz不能给出复现问题的最小代码,只能在此胡乱猜测喽
1、结构体嵌套包含指针或动态分配数组的结构体
2、数组越界
3、程序其它部分的动态数组或指针出错
4、升级IVF或者换GCC
pasuka 发表于 2019-1-29 09:05
lz不能给出复现问题的最小代码,只能在此胡乱猜测喽
1、结构体嵌套包含指针或动态分配数组的结构体
2、数组 ...
代码量比较大,大概小10万行,所以无法全部贴出来
下面是该模块的全部代码
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 文件名称 :m_npod_norm_info.f90
! 功 能 :存储法矩阵信息
! 调用模块 :
! use m_olibtype
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
module m_npod_norm_info
use m_olibtype
implicit none
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! rnorm 法矩阵
! rh 偏导数
! rwy 右函数
! rx 改进参数
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
type t_npod_norm_info
logical ::l_init = .false.
integer(kind=i4b) ::ndim = 0
real(kind=dp),allocatable ::rnorm(:,:), rnorm_inv(:,:)
real(kind=dp),allocatable ::rh(:), rwy(:), rx(:)
contains
procedure,pass ::init
procedure,pass ::reset
final ::clean
end type t_npod_norm_info
type(t_npod_norm_info),save ::snorm
private ::init, reset, clean
contains
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutineinit(this, ndim, is)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 功 能 :t_npod_norm_info结构体初始化
!
!
! 输 入 :
! this t(t_npod_norm_info) 结构体
! ndim I*i4b 初始化维数
!
! 输 出 :
! is I*i4b 返回状态
!
! 输入输出 :
!
! 其它接口 :
! 调用模块 :
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! ====变量声明====
implicit none
class(t_npod_norm_info),intent(inout) ::this
integer(kind=i4b),intent(in) ::ndim
integer(kind=i4b),intent(out) ::is
! ====执行代码====
this%ndim = ndim
if ( this%l_init ) then
deallocate(this%rnorm, this%rnorm_inv, this%rh, this%rwy, this%rx, stat=is)
end if
allocate( this%rnorm(ndim,ndim), this%rnorm_inv(ndim,ndim), &
this%rh(ndim), this%rwy(ndim), this%rx(ndim), stat=is)
this%l_init = .true.
end subroutine init
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutinereset(this)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 功 能 :t_npod_norm_info结构体重置
!
! 输 入 :
! this t(t_npod_norm_info) 结构体
!
! 输 出 :
!
! 输入输出 :
!
! 其它接口 :
! 调用模块 :
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! ====变量声明====
implicit none
class(t_npod_norm_info),intent(inout)::this
integer(kind=i4b) ::is
! ====执行代码====
this%ndim = 0
if ( this%l_init ) then
this%l_init = .false.
if ( allocated(this%rnorm) ) deallocate(this%rnorm, stat=is)
if ( allocated(this%rnorm_inv)) deallocate(this%rnorm_inv, stat=is)
if ( allocated(this%rwy) ) deallocate(this%rwy, stat=is)
if ( allocated(this%rx) ) deallocate(this%rx, stat=is)
if ( allocated(this%rh) ) deallocate(this%rh, stat=is)
end if
end subroutine reset
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutineclean(this)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 功 能 :t_npod_norm_info结构体释放
!
! 输 入 :
! this t(t_npod_norm_info) 结构体
!
! 输 出 :
!
! 输入输出 :
!
! 其它接口 :
! 调用模块 :
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! ====变量声明====
implicit none
type(t_npod_norm_info),intent(inout) ::this
integer(kind=i4b) ::is
! ====执行代码====
this%ndim = 0
if ( this%l_init ) then
this%l_init = .false.
if ( allocated(this%rnorm) ) deallocate(this%rnorm, stat=is)
if ( allocated(this%rnorm_inv)) deallocate(this%rnorm_inv, stat=is)
if ( allocated(this%rh) ) deallocate(this%rh, stat=is)
if ( allocated(this%rwy) ) deallocate(this%rwy, stat=is)
if ( allocated(this%rx) ) deallocate(this%rx, stat=is)
end if
end subroutine clean
end modulem_npod_norm_info
该问题出现的时间比较长了,每次定位都是在this%rh释放出错。主要奇怪的是出错,程序不给出任何信息,没有出现内存溢出,无法写入之类的提示,就像正常运行结束一样。 pasuka 发表于 2019-1-29 09:05
lz不能给出复现问题的最小代码,只能在此胡乱猜测喽
1、结构体嵌套包含指针或动态分配数组的结构体
2、数组 ...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 文件名称 :m_npod_norm_info.f90
! 功 能 :存储法矩阵信息
! 调用模块 :
! use m_olibtype
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
module m_npod_norm_info
use m_olibtype
implicit none
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! rnorm 法矩阵
! rh 偏导数
! rwy 右函数
! rx 改进参数
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
type t_npod_norm_info
logical ::l_init = .false.
integer(kind=i4b) ::ndim = 0
real(kind=dp),allocatable ::rnorm(:,:), rnorm_inv(:,:)
real(kind=dp),allocatable ::rh(:), rwy(:), rx(:)
contains
procedure,pass ::init
procedure,pass ::reset
final ::clean
end type t_npod_norm_info
type(t_npod_norm_info),save ::snorm
private ::init, reset, clean
contains
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutineinit(this, ndim, is)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 功 能 :t_npod_norm_info结构体初始化
!
!
! 输 入 :
! this t(t_npod_norm_info) 结构体
! ndim I*i4b 初始化维数
!
! 输 出 :
! is I*i4b 返回状态
!
! 输入输出 :
!
! 其它接口 :
! 调用模块 :
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! ====变量声明====
implicit none
class(t_npod_norm_info),intent(inout) ::this
integer(kind=i4b),intent(in) ::ndim
integer(kind=i4b),intent(out) ::is
! ====执行代码====
this%ndim = ndim
if ( this%l_init ) then
deallocate(this%rnorm, this%rnorm_inv, this%rh, this%rwy, this%rx, stat=is)
end if
allocate( this%rnorm(ndim,ndim), this%rnorm_inv(ndim,ndim), &
this%rh(ndim), this%rwy(ndim), this%rx(ndim), stat=is)
this%l_init = .true.
end subroutine init
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutinereset(this)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 功 能 :t_npod_norm_info结构体重置
!
! 输 入 :
! this t(t_npod_norm_info) 结构体
!
! 输 出 :
!
! 输入输出 :
!
! 其它接口 :
! 调用模块 :
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! ====变量声明====
implicit none
class(t_npod_norm_info),intent(inout)::this
integer(kind=i4b) ::is
! ====执行代码====
this%ndim = 0
if ( this%l_init ) then
this%l_init = .false.
if ( allocated(this%rnorm) ) deallocate(this%rnorm, stat=is)
if ( allocated(this%rnorm_inv)) deallocate(this%rnorm_inv, stat=is)
if ( allocated(this%rwy) ) deallocate(this%rwy, stat=is)
if ( allocated(this%rx) ) deallocate(this%rx, stat=is)
if ( allocated(this%rh) ) deallocate(this%rh, stat=is)
end if
end subroutine reset
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutineclean(this)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 功 能 :t_npod_norm_info结构体释放
!
! 输 入 :
! this t(t_npod_norm_info) 结构体
!
! 输 出 :
!
! 输入输出 :
!
! 其它接口 :
! 调用模块 :
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! ====变量声明====
implicit none
type(t_npod_norm_info),intent(inout) ::this
integer(kind=i4b) ::is
! ====执行代码====
this%ndim = 0
if ( this%l_init ) then
this%l_init = .false.
if ( allocated(this%rnorm) ) deallocate(this%rnorm, stat=is)
if ( allocated(this%rnorm_inv)) deallocate(this%rnorm_inv, stat=is)
if ( allocated(this%rh) ) deallocate(this%rh, stat=is)
if ( allocated(this%rwy) ) deallocate(this%rwy, stat=is)
if ( allocated(this%rx) ) deallocate(this%rx, stat=is)
end if
end subroutine clean
end modulem_npod_norm_info
lz问题解决了吗?我最近也碰到deallocate出错,检查了数组下标,没有越界,但程序总是运行到这里就停了,找不到原因 Miyaa 发表于 2022-10-20 14:09
lz问题解决了吗?我最近也碰到deallocate出错,检查了数组下标,没有越界,但程序总是运行到这里就停了,找 ...
请不要挖坟哟。同样表现出来的错误,不同的人遇到的原因可能不同。
请另行发帖求助,并给出必要信息。最好是有能重现问题的最小代码。
页:
[1]