- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a program using an array of user defined type. The total size of the array is about 8MB.
The array does not have allocatable components.
This array is passed to a subroutine as an INOUT argument and I also made a version of the program where the array is global.
In both versions, calling the subroutine causes stack overflow.
When the array has a size of about 6MB there is no stack overflow.
I have set the Properties in Visual Studio to use heap arrays
and have used both ifort and ifx compilers, latest Windows versions.
Any suggestion to why such a small array causes stack overflow?
Thanks.
Sincerely,
Svein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The default stack size on Windows is, I think, 10MB. You can set a larger value in the linker property System > Stack Reserve Size. You can also set the compiler option Fortran > Optimization > Heap Arrays > 0 - this will use dynamic allocation instead of the stack for temporary values.
For further reading, see Doctor Fortran in "Don't Blow Your Stack!" - Doctor Fortran (stevelionel.com)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is maybe pointless to speculate on the many possible causes. You need to follow the code in the debugger and find the code line that causes the overflow. One could then more usefully home in on the actual cause based on what the code is doing at the time of overflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The default stack size on Windows is, I think, 10MB. You can set a larger value in the linker property System > Stack Reserve Size. You can also set the compiler option Fortran > Optimization > Heap Arrays > 0 - this will use dynamic allocation instead of the stack for temporary values.
For further reading, see Doctor Fortran in "Don't Blow Your Stack!" - Doctor Fortran (stevelionel.com)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
Thanks.
I used heap arrays first, but that did not help.
Setting the Stack Reserve Size helped.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Svein-Atle_Engeseth the Heap Arrays option that @Steve_Lionel suggest should correct your problem.
From your description, it looks like your subroutine is performing an array operation that is requiring a temporary. Example:
A = B + C
As opposed to
do i=1,N
A(i) = B(i) + C(i)
end do
Note, in the first case, the compiler might figure out that an array temporary was not necessary, but in other cases it may generate an array temporary. If this be the case, and if your array temporary is too large to fit on stack, then you will get the stack overflow.
Increasing the stack size is not necessarily a fix all solution.
Jim Dempsey

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