- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Recently large data sets were causing stack overflows in a program of mine. To allow for larger temporary arrays (prevent stack overflows), I changed Fortran>Optimization>Heap Arrays from <blank> to 0 (see attached memsetting.jpg).
After this change my program was using up all available memory to the point where ALLOCATE would fail. Also i was able to see the memory used up in task manager.
.
I built a test program to verify what i was seeing:
PROGRAM mainprog
IMPLICIT NONE
REAL*8, ALLOCATABLE, DIMENSION(:) :: allocarray
ALLOCATE(allocarray(10))
CALL memsub(SIZE(allocarray),allocarray)
WRITE(*,*) 'allocarray',allocarray
DEALLOCATE(allocarray)
ENDPROGRAM mainprog
.
SUBROUTINE memsub(n,array)
IMPLICIT NONE
INTEGER, INTENT(in) :: n
REAL*8, INTENT(inout), DIMENSION(n) :: array
REAL*8, DIMENSION(n) :: localarray
INTEGER i
localarray = 1.D0
DO i = 1,n
array(i) = -DBLE(i)
ENDDO
array = array + localarray
ENDSUBROUTINE memsub
.
.
If i set "Heap Arrays" to blank, Inspector does not detect any problems.
.
If i set "Heap Arrays" to 0, Inspector detects a memory leak:
ID Problem Sources Modules Object Size State
P1 Memory leak memsub.f90 memtest.exe 80 New
.
If i set "Heap Arrays" to 0, and change my local variable "localarray" to allocatable (and deallocate it at the end of the subroutine), Inspector does not detect any problems.
.
The Inspector results agree with what i was seeing in my program as far as memory usage.
My conclustion is that explicitly declared temporary arrays (not sure if that is the correct term, for example: REAL*8, DIMENSION(n) :: localarray) do not get automatically freed when they are created on the heap like i assumed they were.
Is this common knowledge? I didn't pick this up from reading posts about stack vs heap.
I guess I will stop using "Heap Arrays = 0" and try increasing the stack size to hopefully cure my issues? I have no idea what the stack size should be. Is there a way to tell what the default stack size is?
thanks,
rob
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This problem was fixed in a 13.0 update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Which update?
Does 2013.5.198 have the fix?
thanks,
rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, it should. I would say it was fixed in update 2 or 3.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page