Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

How to understand stack reserve size and commit size?

An_N_1
New Contributor I
5,321 Views

When stack overflow occuring, increasing stack reserve size is helpful while commit size isn't.

Would experts explain the difference bewteen reserve and commit size, and when to increase reserve size and when to increase commit size?

Thanks!

0 Kudos
12 Replies
jimdempseyatthecove
Honored Contributor III
5,321 Views
0 Kudos
An_N_1
New Contributor I
5,321 Views

Thanks, Jim.

I have read some docs like that. According to the docs, I think commit have higher priority than reserve, since commit memory will allocate physical memory at a time, and reserve memory just reserve size in virtual memory.

But set commit size to a larger number can not solve stack overflow which can be solved by setting reserve size. Why?

0 Kudos
jimdempseyatthecove
Honored Contributor III
5,321 Views

I do not think that you can commit (one or more times accumulatively) more than reserve. IOW reserve must be set appropriately, and commit (if used by the runtime system) affects the size of the block committed to the page file/RAM (limited to the extent of the reserve size).

reserve == Block out this amount of Virtual Memory Address range for use as stack (not necessarily taking any resources until first used)

Jim Dempsey

0 Kudos
Steve_Lionel
Honored Contributor III
5,321 Views

My usual recommendation is to set the option /heap-arrays (Fortran > Optimization > Heap Arrays > 0). This causes temporaries and automatic arrays to be allocated on the heap rather than the stack. 

0 Kudos
An_N_1
New Contributor I
5,321 Views

Thanks Steve, Your advise is very valuable!

And Thanks Jim! 

0 Kudos
kolber__Michael
New Contributor I
5,321 Views

I have a Fortran DLL and a C++ executable.  The article that Jim references says to only set stack and heap for exe.  Is this really the case?  How do I handle large arrays in the dll?

 

Michael

0 Kudos
Steve_Lionel
Honored Contributor III
5,321 Views

There is nothing you can do in the DLL to affect the stack size. My advice is to build the DLL with /heap-arrays enabled.

0 Kudos
kolber__Michael
New Contributor I
5,321 Views

I am using a set of procedures called fox to read in xml.  When I enable /heap-arrays the fox code crashes.  It gives me an unhandled break and the locations are not even consistent .

0 Kudos
jimdempseyatthecove
Honored Contributor III
5,321 Views

>>When I enable /heap-arrays the fox code crashes. 

Enable all compile time and run time diagnostics. The run time diagnostics may require a console window, or for Windows Program without console window, set the environment variable FORT0 to a file specification for stderr messages, and set environment variable FORT6 to that for stdout messages.

Jim Dempsey

0 Kudos
kolber__Michael
New Contributor I
5,321 Views

If you enable /heap-arrays > 0.  Do you have to set the size allocation for the heap anywhere else?

0 Kudos
jimdempseyatthecove
Honored Contributor III
5,321 Views
0 Kudos
Steve_Lionel
Honored Contributor III
5,321 Views

Do not set the value of /heap-arrays to anything but zero. Non-zero values are not useful. You are not setting the size of the heap. Theoretically, that value for /heap-arrays allows the compiler to keep small things on the stack and allocate large temps on the heap, but in practice the situations where it can do that are so restricted that it is pointless.

0 Kudos
Reply