Unlimited OR Auto Stack Size for Windows

Unlimited OR Auto Stack Size for Windows

mohanmuthu's picture

Hi,

I use ifort11 to compile the windows application. Recently I figureout that, stacksize limitatation is causing some error and with /F option, I could overcome for the time being. But my objective is to set the unlimited stacksize or auto stacksize based on the operating system (my application will be used in 32- as well as 64- bit machines).

Can someone advise me on how to make unlimited or auto stack size for windows?

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Sergey Kostrov's picture

>>...my objective is to set the unlimited stacksize or auto stacksize based on the operating system (my application will be
>>used in 32- as well as 64- bit machines).
>>
>>Can someone advise me on how to make unlimited or auto stack size for windows?

There are No any linker options to set unlimited or auto stack size for Windows. Since the memory size is always limited the stack size is limited as well. The situation gets worse on 32-bit systems because it has a 2GB limitation for address space. In case of 64-bit systems up to a couple of TBs of memory could be allocated.

In case of 32-bit Windows applications the following Stack Commit and Stack Reserve values for the linker could be used:

Stack Commit = 1073741824
Stack Reserve = 1073741824

but a size of your application plust size of all DLLs mapped to the address space of your application will reduce amount of available memory for processing.

Steve Lionel (Intel)'s picture

Even on 64-bit Windows, the stack is limited to 2GB (along with static code and data). I recommend setting the option Optimization > Heap Arrays > 0 (/heap-arrays) if you have problems with running out of stack. Keep in mind that setting the stack reserve size very large may prevent the program from running at all.

Steve
mohanmuthu's picture

Thank you Sergey and Steve.

Setting more than 2GB limit worked on Win 7 x64 workstation, but not on Win XP x64 workstation. However, when I reduced to 1GB, it works everywhere.

@ Steve - Do you think, setting 2GB stack size will be the best or 1GB would be the optimal consider other processes?

Sergey Kostrov's picture

>>...Setting more than 2GB limit worked on Win 7 x64 workstation...

I'm interested to know what value did you use? Was it for Stack Commit and Stack Reserve, or just for one of these linker options?

jimdempseyatthecove's picture

>> or 1GB would be the optimal consider other processes?

The stack size comes out of your Virtual Machine address space (per thread). The system resources taken (pages in page file) do not occur until a location within the Virtual Address page is referenced. Unused stack space consumes no system resource (but does consume virtual address space from the application). On x32 application, loss of virtual address space for (unwarrentedly large) stack space (per thread) eats into available heap space. If you are programming multi-threaded, as x32 app, program for more heap usage than stack usage (e.g. enable heap arrays) to reduce stack requirements, and then determine worst case stack requirement and set stack size to worst case + nn%.

"Unlimited" stack size is a meaningless term. Truely unlimited stack size would be infinite. Impractical unlimited stack size would be all of virtual address space (no remaining memory for code nor heap). While you could have heap start at lower virtual address (above code) and creap up in virtual address as heap requirements grow, and stack creap down from top usable virtual address (below O/S  reserved space), this technique is only valid for single threaded application. On multi-threaded you have a issue of how to partition the gap between top of code and static data and beginning of first stack (each thread has its own stack as part of flat address space of application). For x64 application, you can specify multi-GB if you desire (unless you have 1000's of threads), but on x32 application you have to be careful as virtual address space is a (practical) limited resource. 

Jim Dempsey

www.quickthreadprogramming.com
Steve Lionel (Intel)'s picture

Do not try setting 2GB as a stack size. It will give you problems. Please use /heap-arrays to reduce the use of stack.

Steve

Login to leave a comment.