Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26745 Discussions

How to understand stack reserve size and commit size?

An_N_1
New Contributor I
2,500 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
Black Belt
2,500 Views
An_N_1
New Contributor I
2,500 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?

jimdempseyatthecove
Black Belt
2,500 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

Steve_Lionel
Black Belt Retired Employee
2,500 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. 

An_N_1
New Contributor I
2,500 Views

Thanks Steve, Your advise is very valuable!

And Thanks Jim! 

kolber__Michael
New Contributor I
2,500 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

Steve_Lionel
Black Belt Retired Employee
2,500 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.

kolber__Michael
New Contributor I
2,500 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 .

jimdempseyatthecove
Black Belt
2,500 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

kolber__Michael
New Contributor I
2,500 Views

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

jimdempseyatthecove
Black Belt
2,500 Views

To track errors, look at additional environment variables

https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-supported-environmen...

Jim Dempsey

Steve_Lionel
Black Belt Retired Employee
2,500 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.

Reply