Fortran Coder

查看: 13195|回复: 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
希望请教,这种情况如何差错。

分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

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,未使用第三方库。
奇怪的是,成功需终止,没有任何出错信息。

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
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-5-14 23:04

Powered by Tencent X3.4

© 2013-2024 Tencent

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