You can run the following program with options '/debug /lgo' and '/check /lgo' and see that each call with /check usually gets new memory, while the /debug does not.
They both end with insufficient memory, but at different values of npt, giving an error I am familiar with. (My other problem failed allocating an array of only 800 bytes.)
With /check, you can see that the memory is not being reused.
What I have seen from other tests is there are little bits of memory taken out in a number of places over the 2gb of available memory, which can stop ALLOCATE from getting a large single chunk of memory. The order of multiple ALLOCATE statements can be important in this case.
integer*4 npt
do npt = 1000, 10000, 1000
call allocate_some (npt)
end do
end
subroutine allocate_some (npt)
integer*4, allocatable, dimension(:) :: kt
real*8, allocatable, dimension(:) :: org_y, h_kt, s_kt
real*8, allocatable, dimension(:,:) :: a, b
!
integer*4 npt
!
! npt=size(matrix_so%x)
if (allocated(org_y)) deallocate(org_y)
if (allocated(kt)) deallocate(kt)
if (allocated(h_kt)) deallocate(h_kt)
if (allocated(S_kt)) deallocate(S_kt)
if (allocated(a)) deallocate(a)
if (allocated(b)) deallocate(b)
!
allocate (org_y(npt))
allocate (kt(npt))
allocate (h_kt(npt))
allocate (S_kt(npt))
allocate (a(npt,npt))
allocate (b(npt,npt))
!
write (*,*) ' '
write (*,*) ' Running for npt =',npt
call Report_allocate_8 (org_y, npt, 'org_y')
call Report_allocate_4 (kt, npt, 'kt')
call Report_allocate_8 (h_kt, npt, 'h_kt')
call Report_allocate_8 (S_kt, npt, 's_kt')
call Report_allocate_8 (a, npt*npt, 'a')
call Report_allocate_8 (b, npt*npt, 'b')
!
return
end
subroutine Report_allocate_8 (b, npt, array_name)
!
integer*4 npt, ii
real*8 b(npt)
character array_name*(*)
!
ii = loc (b)
write (*,1001) 'Allocate at', ii, npt*8, array_name
1001 format (a,b'zz,zzz,zzz,zz#',' of ',i0,' bytes for array ',a)
end
subroutine Report_allocate_4 (b, npt, array_name)
!
integer*4 npt, ii
integer*4 b(npt)
character array_name*(*)
!
ii = loc (b)
write (*,1001) 'Allocate at', ii, npt*4, array_name
1001 format (a,b'zz,zzz,zzz,zz#',' of ',i0,' bytes for array ',a)
end