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

More on stack overflow

JohnNichols
Valued Contributor III
406 Views
Dear Steve:

I had another program blow up with stack overflow, after it gave me an outof bounds error. I read your Dr Fortran Blog on the Stack overflow issue, but I still have a question.

The routines do Fast Fourier transforms, so I have very large arrays, the array size is set by a variable FFTsize that is passed in the arguments to the subroutines, along with the file number details. When I call the main analysis program the stackoverflows if I set the FFTSize above 4092, it has to multiples of 2, so 8184 is the next size.

What is the best method to establish the arrays so I do not get a stack overflow? My guess is I have 10 arrays with 32678 elements and eight varialbe arrays of FFtSize. This is in Windows 7 32 bit.

Thanks

John
0 Kudos
6 Replies
JohnNichols
Valued Contributor III
406 Views
Steve:

Sorry about the double post, I thought I had lost the first one.

JMN
0 Kudos
mecej4
Honored Contributor III
406 Views
You can allocate the stack required using the /F option to the compiler or the /stack: option to the linker. If the arrays that you described above are of type double precision, you need about 4 MB of stack.

If, on the other hand, as your bounds overflow suggests, you have mismatched subprogram arguments, an incorrect integer argument could be used as the size of a local variable, and any reasonable allocation of stack would not help to remove the problem. In this case, you should investigate and remove the bounds error first.
0 Kudos
Steven_L_Intel1
Employee
406 Views
The simplest solution is to set the project property Optimization > Heap Arrays to 0. This will allocate local automatic arrays and array temps on the heap rather than the stack.

An approach that doesn't require a special setting is to change the local arrays to ALLOCATABLE and to allocate them to the desired size. For example, instead of:

REAL A(FFTsize)

you'd have:

REAL A(:)
...
ALLOCATE (A(FFTsize))

These will get automatically deallocated on routine exit.
0 Kudos
JohnNichols
Valued Contributor III
406 Views
Steve:

Thank you for the responses.

CAn you tel me what format the numbers are required in the stack size allocation. The old Microsoft Fortran manual says hexadecimal, I could not find an answer in the Intel manuals, they said what to do but no example.

Regards

JMN
0 Kudos
JohnNichols
Valued Contributor III
406 Views
Steve:

Worked it out at last, 4000000 worked a treat.

JMN
0 Kudos
Steven_L_Intel1
Employee
406 Views
If you are using the linker property to set the stack reserve size, the value there is decimal. This may work for you now, but if the problem size increases it may fail again. This is why I generally recommend using heap allocation.
0 Kudos
Reply