Fortran Coder

查看: 13104|回复: 8

[求助] 关于deallocate

[复制链接]

4

帖子

1

主题

0

精华

入门

F 币
33 元
贡献
16 点
发表于 2019-1-28 17:25:36 | 显示全部楼层 |阅读模式
代码如下:
    subroutine  reset(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
希望请教,这种情况如何差错。

953

帖子

0

主题

0

精华

大师

F 币
180 元
贡献
73 点

规矩勋章元老勋章新人勋章水王勋章热心勋章

QQ
发表于 2019-1-28 17:44:10 | 显示全部楼层
用的什么操作系统?什么编译器?
是否用到了混编?第三方库?

4

帖子

1

主题

0

精华

入门

F 币
33 元
贡献
16 点
 楼主| 发表于 2019-1-28 20:16:59 | 显示全部楼层
vvt 发表于 2019-1-28 17:44
用的什么操作系统?什么编译器?
是否用到了混编?第三方库?

操作系统是win 10, 编译器visual studio 2012+ ivf 2013
没有使用混编,纯Fortran,未使用第三方库。
奇怪的是,成功需终止,没有任何出错信息。

790

帖子

2

主题

0

精华

大宗师

F 币
3765 元
贡献
2255 点
发表于 2019-1-28 22:38:26 | 显示全部楼层
在 end subroutine前加 pause 试试。

490

帖子

4

主题

0

精华

大宗师

F 币
3298 元
贡献
1948 点

水王勋章元老勋章热心勋章

发表于 2019-1-29 09:05:27 | 显示全部楼层
本帖最后由 pasuka 于 2019-1-29 09:11 编辑

lz不能给出复现问题的最小代码,只能在此胡乱猜测喽
1、结构体嵌套包含指针或动态分配数组的结构体
2、数组越界
3、程序其它部分的动态数组或指针出错
4、升级IVF或者换GCC


4

帖子

1

主题

0

精华

入门

F 币
33 元
贡献
16 点
 楼主| 发表于 2019-1-29 11:29:51 | 显示全部楼层
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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    subroutine  init(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



!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    subroutine  reset(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



!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    subroutine  clean(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 module  m_npod_norm_info

该问题出现的时间比较长了,每次定位都是在this%rh释放出错。主要奇怪的是出错,程序不给出任何信息,没有出现内存溢出,无法写入之类的提示,就像正常运行结束一样。

4

帖子

1

主题

0

精华

入门

F 币
33 元
贡献
16 点
 楼主| 发表于 2019-1-29 11:31:49 | 显示全部楼层
pasuka 发表于 2019-1-29 09:05
lz不能给出复现问题的最小代码,只能在此胡乱猜测喽
1、结构体嵌套包含指针或动态分配数组的结构体
2、数组 ...

[Fortran] 纯文本查看 复制代码
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!   文件名称 :  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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    subroutine  init(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



!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    subroutine  reset(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



!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    subroutine  clean(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 module  m_npod_norm_info

3

帖子

1

主题

0

精华

新人

F 币
26 元
贡献
12 点
发表于 2022-10-20 14:09:44 | 显示全部楼层
lz问题解决了吗?我最近也碰到deallocate出错,检查了数组下标,没有越界,但程序总是运行到这里就停了,找不到原因

235

帖子

0

主题

0

精华

版主

World Analyser

F 币
630 元
贡献
464 点

新人勋章美女勋章元老勋章热心勋章规矩勋章管理勋章

QQ
发表于 2022-10-20 15:11:16 | 显示全部楼层
Miyaa 发表于 2022-10-20 14:09
lz问题解决了吗?我最近也碰到deallocate出错,检查了数组下标,没有越界,但程序总是运行到这里就停了,找 ...

请不要挖坟哟。同样表现出来的错误,不同的人遇到的原因可能不同。
请另行发帖求助,并给出必要信息。最好是有能重现问题的最小代码。
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-3-29 18:02

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表