Intel® Fortran Compiler - Increased stack usage of 8.0 or higher compilers causes segmentation fault

The Intel® Fortran Compilers 8.0 or higher allocate more temporaries on the stack than previous Intel Fortran compilers. Temporaries include automatic arrays and array sub-sections corresponding to actual arguments. If the program is not afforded adequate stack space at runtime relative to the total size of the temporaries, the program will terminate with a segmentation fault on Linux* and Mac OS* X or Signal 11 on Windows*.

 

On Linux*, the stack space can be increased using:
ulimit -s unlimited     for bash shell, or
limit stacksize unlimited     for csh shell.

On Mac OS* X Leopard:  simply use the -stack_size option to the linker
ifort -Wl,-stack_size,0x10000000  foo.f

or   ld -stack_size 0x10000000 -o foo foo.o
 

On Mac OS* X Tiger:  see the article, "How to increase the stack size on MAC OS X" by Eric Circlaeys, Consulting Engineer, Apple Computer Europe.

For example to increase to 256MB with either ld or ifort on Mac OS,

ld –stack_size 0x10000000 –o foo foo.o
or   ifort –Wl,-stack_size,0x10000000,-stack_addr,0xc0000000 foo.f

 

For Intel® Fortran Compilers 10.0 and above, all platforms:
The -heap-arrays compiler option directs the compiler to put the automatic arrays and arrays created for temporary computations on the heap instead of the stack. Note the 13.0 initial release of the compiler has a memory leak with the  -heap-arrays switch, so do not use it with this release. (Fixed in 13.0 Update 1 - Issue ID DPD200235943)

Notes:

Linux: The size of "unlimited" varies by Linux configuration, so you may need to specify a larger, specific number to ulimit (for example, 999999999). On Linux also note that many 32bit Linux distributions ship with a pthread static library (libpthread.a) that at runtime will fix the stacksize to 2093056 bytes regardless of the ulimit setting. To avoid this problem do not link with the -static option or the -fast option. Instead of -fast, use options: -ipo -O3 -no-prec-div -xP . This only affects the 32bit Linux distributions and does not apply to the 64bit Linux distributions.

Mac OS X: stack "unlimiting" of the shell environment on Mac OS X is not possible.  The OS sets a ceiling for the maximum stack size, typically 64K.  Use the linker options shown above to increase stacksize.

Windows: On Windows, the stack space to reserved for the program is set using the /Fn compiler option, where n is the number of bytes.  Additionally, the stack reserve size can be specified through the Visual Studio IDE which adds the Microsoft Linker option /STACK: to the linker command line.  To set this, go to Property Pages>Configuration Properties>Linker>System>Stack Reserve Size. There you can specify the stack size in bytes in either decimal or C-language notation. If not specified, the default stack size is 1MB.

 
For more complete information about compiler optimizations, see our Optimization Notice.