Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stack overflow

Status
Not open for further replies.

yorelchr

MIS
Apr 1, 2012
8
IT
Hello Everyone,

I've written a program that have a lot of loops and a recursive subroutine. When I run it, I always have the following error message:
forrt1 : severe (170): program exception - stack overflow.
How can I increase the memory?
I've already declared the arrays as Allocatable.
I'm using Compaq Visual Fortran Pro Edition 6.5
Thanks a lot for any help
Yorelchr
 
I am using the same compiler as you do and receive the stack overflow error occasionally. Everytime, I found a read statement to be the cause of the problem:

Code:
integer, allocatable, dimension (:,:) :: iValue
integer nX, nY
.
.
nX = 100
nY = 200
allocate (iValue (nX, nY), stat = irslt)
.
.
read (IO_DATA, *) iValue

leads to stack overflow. I tried to increase the stack - there is a function in the win32API to do this, but this was not successful.

But when I changed the read statement to
Code:
read (IO_DATA, *) ((iValue (i,j), i = 1, nX), j = 1, nY)

everything is fine.
So, my advise would be to track where your stack overflow occurs. If it happens in a read statement you may be successful in changing the code as above.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
I don't think that a stack overflow could be caused by an allocatable array, because such an array is allocated on the heap, not on the stack...

I suggest instead to look for the automatic arrays (local arrays which get their size at the entrance of a subroutine but which are not declared allocatable). These arrays are often allocated on the stack (but this depends on the compiler).

François Jacq
 
Question is, how deep is your recursion? To get a stack overflow on recursion can mean that there is insufficient stack or it can mean that the code is caught in a recursive loop.

Test is simple, just increment a count and print it whenever you enter the routine.

Decrease the count whenever you exit.

See what figure it gets up to. Is this what you're expecting?
 
sorry, I didn't react to your message before. I've made a terrible mistake: I wanted to do what xwb advised me and I don't know what I did but I "lost" the main program. When opening Compaq Visual Fortran it tells me that not all the files could be downloaded and asks me if I want to create a new one...is there a way to find it back???
 
Did you try copying it somewhere on the same disk? You may have moved it instead of copying it. Easiest way is to search for it either using explorer or from the cmd prompt,
Code:
cd dir /s filename
 
FJacq:
I thought the same, but maybe while reading a complete array - maybe not only allocatable ones - the data are written to the stack first and then saved to the proper place in the heap, once the reading is done. At least, I encountered a number of stack overflows during reading the array as a whole item. Might be a question when and how the format is applied. When I did loops for reading the arrays one element at a time, all was fine. Unfortunately, this takes a while longer.

yorelchr:
- Look for the file in question in the directory that you use for your programming, maybe only the link got corrupted
- search your drive for your program file with the search function
- check your waste bin (is this what the container for deleted files is called ?) for your file

If all is negative: retype your prog and promise yourself you will do backups on a regular basis. You would not be the first one to learn it that way.....

Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
ok, I could found a "not too old" version of my main...
First, thank you very much for your replies !!!
so I've put a count, when the program stops, its value is 1020163
all the arrays are allocatable and I think I really should increase the "stock".
I don't think there's a problem in my program since it ran successfully on many cases, but the case I'm studying on is really more big than the previous ones.
I've read about editbin (installed on my pc) but when I try to run it, it fails, mayybe I don't do the right things : I open a terminal and type "editbin /STACK:4000000 DFDEV.exe" but it tells me that it can't find DFDEV.exe even if I type the line from the directory containing the .exe...

PS: to gummibaer: where's the win32API?
any idea?
thanks a lot
 
oups, sorry, didn't see your last replies.
I had to take a previous version of my main.exe...I'm so in a hurry that I'm starting to do big mistakes...and from now, I will do backups more regularly !!!
thank you really for your help !!
 
gummibaer :
When reading a file, data are not put temporarily on the stack but within a buffer. There is also a limit on the number of file buffers open simultaneously but the error message in case of problem would be different.

As xwb indicated, the main origin of a stack overflow is a recursive program where the recursion depth is not controlled correctly.

I missed that the OP mentioned that he was using a recursive subroutine ...

François Jacq
 
PS: to gummibaer: where's the win32API?
any idea?

This was part of my installation.

But I found a better clue than a windows routine. Check in the fortran docs on linker options.

/STACK
Syntax:

/STACK:reserve[,commit]
Sets the size of the stack in bytes.

The reserve argument specifies the total stack allocation in virtual memory. The default stack size is 1MB. The linker rounds up the specified value to the nearest 4 bytes.

The optional commit argument is subject to interpretation by the operating system. In Windows NT 4 and Windows 2000, it specifies the amount of physical memory to allocate at a time. Committed virtual memory causes space to be reserved in the paging file. A higher commit value saves time when the application needs more stack space but increases the memory requirements and possibly startup time.

Specify the reserve and commit values in decimal or C-language notation. (Use the digits 1-9 for decimal values, precede octal values with zero (0), and precede hexadecimal values with zero and x (0x or 0X).

An alternate way to set the stack is with the STACKSIZE statement in a .DEF file. STACKSIZE overrides Stack Allocations (/STACK) if you specify both. You can change the stack after the executable file is built by using the EDITBIN.EXE tool. For more information, see Editing Files with EDITBIN.

To set these options in the visual development environment, type values in the Reserve and Commit boxes in the Output category of the Link tab in the Project Settings dialog box.

... but I for myself failed to make good use of this for my application.

Ahem, and more than a million recourses is quite a lot. Consider how much memory is newly allocated on each course and how much memory would be used in total then ?

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Thanks Froncois,

I was not aware of this, as I do not have nay experiance in recoursive programs.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
to gummibaer: yes, it's quite a lot more than a million, but I really coudn't find any other way and until now I never had any problem with that.
I tried to do the command with the Stack, but all I could find on internet in the kind of message you put in your post, but I'm completely unable to understand !!!!

An alternate way to set the stack is with the STACKSIZE statement in a .DEF file. STACKSIZE overrides Stack Allocations (/STACK) if you specify both. You can change the stack after the executable file is built by using the EDITBIN.EXE tool. For more information, see Editing Files with EDITBIN.

To set these options in the visual development environment, type values in the Reserve and Commit boxes in the Output category of the Link tab in the Project Settings dialog box.


I'd like to try the last option, but I don't understand what I should write in this box.
 
Do you use the visual environment ?
If yes, then

- open the project tag in the main menu
- there select the settings... option

This opens the Project Settings Dialog. In the right half of this dialog select the linker tag.

Then there is a drop down menu named 'category:' Open this and select the Output option.

In the window that opens then you find the Reserve and commit boxes where you should enter your values.

But - cross my heart - I do not know what to enter there.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Hi norbert,

thank you, I've found the tabs. I tried with numbers like 0x4 and 0x4 but nothing changed...
 
That's about the same what I achieved trying to solve my kind of stack overflow by increasing the stack. Sorry.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
thank you thank you thank you and thank you !!!!!! it worked...I've put the value : 4000000 and 4000000. And the program ran perfectly !!
Really big thanks to all of you for your help and advices !!!
 
Norbert,
I always reply before checking if there's new post...but I was so happy that I wanted to share it !!
When you put 4000000, it directly translates it into 0x3d0900
Maybe I could put a smaller number, but for tonight, I just let this :)
thanks again
 
You are welcome.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top