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

stack overflow

normcler
Beginner
1,508 Views
IVF comrades:

I'm debugging an application that fails with severe error 170, a stack overflow. The documentation for this runtime error requests the user consult the Release Notes for instructions on increasing the stack size, but I can't find them there.

The program has been generated on an Athlon 2200+ computer running Windows 2K Pro and is being run on a dual processor Pentium III computer running W2K Server. The application is large. I'm using some openMP code, but based on the traceback I'm getting, the overflow does NOT occur in the parallel section. I don't use the IDE at all. All the development is done from the command line. I'm using the following switches to compile all the source code:

/c /Qauto /check:all /stand:f95 /warn:general,declarations,unused,usage /debug:full /Od /trace
back /libs:static /Qopenmp_report2 /Qopenmp /threads /object:

Here are my questions:

1) What is the default stack size? Where can I find this information, or how?

2) How do I increase the stack size when I compile the code and then link the program? Am I correct in assuming that the linker sets the stack size, and I need only relink the program with the appropriate switch?

3) Can I use the EDITBIN /STACK command line directive to directly increase the stack size of the executable?

Thanks to all

Norm
0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,508 Views
Hi, Norm...

The default stack size is 1MB. In the IDE, you can change this in Properties under Linker..System..Stack Reserve Size. You can use EDITBIN for this.

Since you're using OpenMP, be aware that threads have their own stacksize. There is a section of the ifort documentation which discusses this - see the index under stack..size for threads.

I'll look into the issue of the incorrect pointer in the error message description.
0 Kudos
pradeepnatekar
Beginner
1,508 Views

Hi Steve,

I am creating a DLL from CVF6.6 and calling it from C#. I already have some allocatable arrays as well as explicitly declared arrays. For e.g. array(x,25) etc. I decide the value of x from one input file. Now, if I add some more explicit arrays to code, it gives stak overflow. x is in order of 1000.

I want to increase the stack size limit. Do a EDITBIN is required in this case as I am creating DLL or I can specify in Project->Link settings?

We have CVF 6.6 as well as latest IVF version. I want to migrate my code to IVF once I resolve this issue. Should I do after migrating to IVF? Please let me know if IVF handles this in better way.

Also let me know if stack overflow is happening because of code similar to following.

The code is something like this:-

---------

double precision, allocatable :: H(:), alpha(:), TwTiTshell(:,:), yvalue(:,:)

allocate(H(x+1),alpha(x+1))

allocate(yvalue(x+1,25))

allocate (TwTiTshell(x,3))

call SolveModelODEs(25, x, alpha,yvalue, TwTiTshell)

---

subroutine SolveModelODEs(n, x, fill_angle, yval, TwTiTshell)

integer, intent(in) :: n, x

double precision, intent(in) :: fill_angle(x+1)
double precision, intent(out) :: yval(x+1, n), TwTiTshell(x,3)

---

Thanks,

Pradeep

0 Kudos
Steven_L_Intel1
Employee
1,508 Views
My guess is that you have a local array (not shown) in the subroutine whose bounds depend on n. This is an "automatic array" and, at present, is put on the stack. In the next IVF update, due next week, there is a new option /heap-arrays, which tells the compiler to use heap allocation for automatics and temporaries instead of the stack.

You must do the EDITBIN on the EXE, not the DLL. It is the EXE that determines the stack size.
0 Kudos
grg99
Beginner
1,508 Views
The allocate itself does not use up stack space, but if you pass the array to certain functions, the compiler must allocate a temporary array on the stack. This happens behind your back, which is convenient most of the time, but can be a pain if it causes a stack overflow.

You might consider turning on the "show temporary allocation" option on the compiler's run-time warnings option page. That will print out a line each time the code makes a temporary array on the stack.

Once you've found the places, you can factor out the array from the parameter list to avoid the stack overflow.


0 Kudos
pradeepnatekar
Beginner
1,508 Views

Thanks.I have some local arrays whosebounds depends on n. I have not shown those here. I have read Steve's article in DoctorFortran reg. stacks. I think I should use allocatable arrays instead of theselocal arrays in that subroutine. I am still passing the arrays to subroutine which will take up some space on stack. But looks like the error is because of those local arrays. I will check with 'show temporary allocation' also.

About my quetion related to EDITBIN, I have not understood whether specifying 'reserve' and 'commit' values for project to create dll will be Ok or not. Please post an example if possible.

0 Kudos
Steven_L_Intel1
Employee
1,508 Views
Using EDITBIN on the DLL for stack reserve does nothing. That information is not used. Only the EXE matters.

Using allocatable arrays for the local arrays is a good solution.
0 Kudos
Reply