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

stack overflow when a large array is passed to a function

soiu2000
Beginner
487 Views
I use Intel Visual Fortran 9.1 to compile a program on x64 xp. An array is passed to a function. When the array is small, everything is all right. But when the array is large, a stack overflow error occurs. As I know it is due to a temperary copy of the large array is being creating in the stack. But usually the address of the array should be passed to the function instead of the value of the array. Why this behavior exists? I try the compile option /noautomatic to prevent the compile from passing the array's values. But it is useless. How can I do to solve this error? Please help me.
0 Kudos
1 Reply
Steven_L_Intel1
Employee
487 Views

The compiler thinks you're passing a non-contiguous arrsy to a routine which expects a contiguous array. This often happens with pointer arrays or if you pass an array slice with a stride other than 1. Because of this, the compiler has to construct a contiguous copy of the array and pass that- the copy goes on the stack by default.

The best solution, if it works for your application, is to make the array contiguous. Second best is to have the routine accept the array as assumed-shape, with dimension (:), and provide an explicit interface visible to the caller. Third best is to set the Linker stack reserve size to a large enough value to permit the temp to be created. This is the /F switch to ifort or /link /stack:n switch at the end of the ifort line. Otherwise. use /heap-arrays which wull cause the compiler to allocate these temp copies on the heap.

/automatic tells the compiler to allocate all variables on the stack, which makes the proble, worse.

See the Newsletter articles in the sticky threads for more on these topics.

0 Kudos
Reply