Silverfrost Forums

Welcome to our forums

Deallocate 64bit /checkmate

18 Apr 2020 12:00 (Edited: 18 Apr 2020 12:27) #25235

I recompiled some code from a few years back and ran into some problems with 64bit /checkmate.

The following cut down code reproduces the problem. This runs fine with Win32 /Checkmate Win32 /Debug Win32 /Release X64 /Debug X64 /Release

It fails with X64 /Checkmate

I have the latest debuggers, plato, and ftn on my machine.

Ken

module asymmetric_wave_mod
implicit none
private

public asymmetric_wave_cb

integer, parameter :: dp = kind(1.d0)
integer, parameter :: npoints_max = 1     !#####  This value was originally much larger.  Problem does not appear to be
                                          !       related to the dimension of the allocated arrays
real(kind=dp), allocatable :: idc_plot(:), iac_plot(:), iinst_plot(:), ienv1_plot(:), ienv2_plot(:), time_plot(:), &
                              iinstsq_plot(:), iinstsqtime_plot(:), irms_plot(:)
 
contains

  integer function asymmetric_wave_cb()
  include<windows.ins>
  integer, save :: iw
   allocate (idc_plot(npoints_max),   iac_plot(npoints_max),   iinst_plot(npoints_max), &
              ienv1_plot(npoints_max), ienv2_plot(npoints_max), time_plot(npoints_max),  &
              iinstsq_plot(npoints_max), iinstsqtime_plot(npoints_max), irms_plot(npoints_max) )
    idc_plot       = 1.d0 ;     iac_plot     = 2.d0
    iinst_plot     = 3.d0 ;     ienv1_plot   = 4.d0
    ienv2_plot   = 5.d0 ;     time_plot     = 6.d0
    iinstsq_plot  = 7.d0 ;     iinstsqtime_plot = 7.d0
    irms_plot     = 8.d0
    print*,'Contents of allocated arrays'
    print*,idc_plot,iac_plot, iinst_plot, ienv1_plot, ienv2_plot, time_plot, &
                              iinstsq_plot, iinstsqtime_plot, irms_plot
    
    iw = winio@('%ww[no_maxminbox,no_sysmenu]&')
    iw = winio@('%mn[Exit]&','exit')
    iw = winio@('Click on EXIT menu to generate error when compiled X64 /Checkmate&')
    
    iw = winio@(' ')

!   ##########  dellocate below runs into problems when compiled with /checkmate X64
    print*,'At line before deallocate'
    deallocate (idc_plot, iac_plot, iinst_plot, ienv1_plot, ienv2_plot, time_plot, iinstsq_plot, iinstsq_plot, &
                iinstsqtime_plot, irms_plot)
    print*, 'At line after deallocate'
    asymmetric_wave_cb = 1
  end function asymmetric_wave_cb

end module asymmetric_wave_mod

program main
use asymmetric_wave_mod, only : asymmetric_wave_cb
implicit none
integer, save :: iw
iw = winio@('%ww[no_maxminbox,no_sysmenu]&')
iw = winio@('%mn[Exit]&','exit')
iw = winio@('%fn[Tahoma]%bg[grey]&')
iw = winio@('Click on button below&')
iw = winio@('%bc[white]%2nl%28^bt[Asymmetric wave]&', asymmetric_wave_cb)
iw = winio@(' ')

end program main 
18 Apr 2020 12:24 #25236

With only a single allocated array, everything is OK.

module asymmetric_wave_mod
implicit none
private

public asymmetric_wave_cb

integer, parameter :: dp = kind(1.d0)
integer, parameter :: npoints_max = 1     !#####  This value was originally much larger.  Problem does not appear to be
                                          !       related to the dimension of the allocated arrays
real(kind=dp), allocatable :: idc_plot(:)
 
contains

  integer function asymmetric_wave_cb()
  include<windows.ins>
  integer, save :: iw
   allocate (idc_plot(npoints_max) )
    idc_plot         = 1.d0
    print*,'Contents of allocated arrays'
    print*,idc_plot
    
    iw = winio@('%ww[no_maxminbox,no_sysmenu]&')
    iw = winio@('%mn[Exit]&','exit')
    iw = winio@('Click on EXIT menu to generate error when compiled X64 /Checkmate&')
    
    iw = winio@(' ')

!   ##########  dellocate below runs into problems when compiled with /checkmate X64
    print*,'At line before deallocate'
    deallocate (idc_plot)
    print*, 'At line after deallocate'
    asymmetric_wave_cb = 1
  end function asymmetric_wave_cb

end module asymmetric_wave_mod

program main
use asymmetric_wave_mod, only : asymmetric_wave_cb
implicit none
integer, save :: iw
iw = winio@('%ww[no_maxminbox,no_sysmenu]&')
iw = winio@('%mn[Exit]&','exit')
iw = winio@('%fn[Tahoma]%bg[grey]&')
iw = winio@('Click on button below&')
iw = winio@('%bc[white]%2nl%28^bt[Asymmetric wave]&',                      asymmetric_wave_cb)
iw = winio@(' ')

end program main 
18 Apr 2020 12:40 #25237

The problem appears to be related to the number of allocated arrays, for example with just 5 allocated arrays, everything is also ok.

module asymmetric_wave_mod 
implicit none 
private 

public asymmetric_wave_cb 

integer, parameter :: dp = kind(1.d0) 
integer, parameter :: npoints_max = 1     !#####  This value was originally much larger.  Problem does not appear to be 
                                          !       related to the dimension of the allocated arrays 
real(kind=dp), allocatable :: idc_plot(:), iac_plot(:), iinst_plot(:), ienv1_plot(:), ienv2_plot(:) 
  
contains 

  integer function asymmetric_wave_cb() 
  include<windows.ins> 
  integer, save :: iw 
   allocate (idc_plot(npoints_max),   iac_plot(npoints_max),   iinst_plot(npoints_max), & 
              ienv1_plot(npoints_max), ienv2_plot(npoints_max)) 
    idc_plot       = 1.d0 ;     iac_plot     = 2.d0 
    iinst_plot     = 3.d0 ;     ienv1_plot   = 4.d0 
    ienv2_plot   = 5.d0
    
    print*,'Contents of allocated arrays' 
    print*,idc_plot,iac_plot, iinst_plot, ienv1_plot, ienv2_plot 
    
    iw = winio@('%ww[no_maxminbox,no_sysmenu]&') 
    iw = winio@('%mn[Exit]&','exit') 
    iw = winio@('Click on EXIT menu to generate error when compiled X64 /Checkmate&') 
    
    iw = winio@(' ') 

!   ##########  dellocate below runs into problems when compiled with /checkmate X64 
    print*,'At line before deallocate'
    deallocate ( idc_plot,iac_plot, iinst_plot, ienv1_plot, ienv2_plot )
    print*, 'At line after deallocate' 
    asymmetric_wave_cb = 1 
  end function asymmetric_wave_cb 

end module asymmetric_wave_mod 

program main 
use asymmetric_wave_mod, only : asymmetric_wave_cb 
implicit none 
integer, save :: iw 
iw = winio@('%ww[no_maxminbox,no_sysmenu]&') 
iw = winio@('%mn[Exit]&','exit') 
iw = winio@('%fn[Tahoma]%bg[grey]&') 
iw = winio@('Click on button below&') 
iw = winio@('%bc[white]%2nl%28^bt[Asymmetric wave]&', asymmetric_wave_cb) 
iw = winio@(' ') 

end program main 
19 Apr 2020 7:07 #25241

I have made a note of this.

19 Apr 2020 1:29 #25242

Ken,

Check your first post; you have 'iinstsq_plot, iinstsq_plot, &'

allocate 9 arrays, deallocate 10 arrays

I was modifying your program as: allocate (idc_plot(npoints_max), stat=stat) ; call report_alloc ( 'idc_plot', stat) deallocate (idc_plot, stat=stat) ; call report_dealloc ( 'idc_plot', stat)

and found the repeat. Is this your original problem ?

I must admit, I try to use stat=stat on allocate and deallocate for a single array

John

19 Apr 2020 2:45 #25243

John,

You are correct. Very well spotted, the benefit of a fresh pair of eyes! That error has been in the original code for sometime, and never caused any issues until recompiled with X64 /checkmate.

I did go through a phase where I was using stat=stat on allocate / deallocate, with separate sequential statements for each allocable array in turn but found that for the relatively small arrays I generally work with I was not running into memory management problems - so I perhaps I have got a bit lazy.

Thanks

Ken

20 Apr 2020 12:06 #25248

Ken,

I wouldn't describe my eyes as 'fresh' !

Interesting the use of stat=stat. It's easy to be lazy as it's been a long time since I got a non-zero response. Can't recall since moving to /64.

The bigger problem is I develop a program on my newer pc, then forget and run it on my older pc, which has only 8gb memory. If I have a few 'apps' open it can take a long time to recover from requesting more memory than installed.

John

Please login to reply.