Again ... Stack overflow

Again ... Stack overflow

Hello everybody

I have a problem with my Fortran simple program.

I am working on Compaq Visual Fortran, using Frotran 77 codes.

The program structure must be in this form , a main and subroutine because it is a part of a big program related to finite element method.

I have to enter the numbers of NHELE & NVELE as you can see in first statment.

The numbers must be 10000 & 10000 !!!

When I run the program stops and shows me the following messege:

forrt1: server <170>: program Exception - stack overflow

So I changed the required number much smaller till I reach 507 & 507 !!! , And it runs OK !!
but when I change it in to 508 & 508 >>> It stops again !! with the same messege.

I think the problem is about the Subroutine (NIGTEE) , because when i rearrange the program without it, every thing works fine.

I increased the stack size to maximum by project>>settings>>link>>output>>reserve & commit
but it didn't work also !!

how can I solve this problem ??
I will appreciate any help

My program ::

PARAMETER(NHELE=508,NVELE=508)
PARAMETER(NHNODE=NHELE+1,NVNODE=NVELE+1)
PARAMETER(NTOTALELE=NHELE*NVELE)

DIMENSION MELE(NTOTALELE,4)

CALL NIGTEE(NHELE,NVELE,NHNODE,NVNODE,NTOTALELE,MELE)

OPEN(UNIT=7,FILE='MeshNO For Rectangular.TXT',STATUS='UNKNOWN')
WRITE(7,500) ((MELE(I,J),J=1,4),I=1,NTOTALELE)
500FORMAT(4I20)

STOP
END

SUBROUTINE NIGTEE(NHELE,NVELE,NHNODE,NVNODE,NTOTALELE,MELE)
DIMENSION NM(NVNODE,NHNODE),NODE(4)
DIMENSION MELE(NTOTALELE,4)

KK=0
DO 20 I=1,NVNODE
DO 20 J=1,NHNODE
KK=KK+1
NM(I,J)=KK
20CONTINUE
KK=0
DO 30 I=1,NVELE
DO 30 J=1,NHELE
NODE(1)=NM(I,J)
NODE(2)=NM(I,J+1)
NODE(3)=NM(I+1,J+1)
NODE(4)=NM(I+1,J)
KK=KK+1
DO 50 II=1,4
50MELE(KK,II)=NODE(II)

30CONTINUE
RETURN
END

Thanks in Advance all

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Automatic arrays aren't Fortran 77, although a few compilers had them as an extension before Fortran 90. I mention that only because you assert that you are using Fortran 77 (which might be an improvement over this).
Also, you can't be using Compaq Fortran on linux, so you might find more expertise on the Windows Fortran forum.
This subroutine looks horribly inefficient. You create this big automatic array each time you enter the subroutine, and you index through it backwards. Wouldn't it work better if you eliminated the NM array, if there is no more to it than you show here?

Quoting - tim18
Automatic arrays aren't Fortran 77, although a few compilers had them as an extension before Fortran 90. I mention that only because you assert that you are using Fortran 77 (which might be an improvement over this).
Also, you can't be using Compaq Fortran on linux, so you might find more expertise on the Windows Fortran forum.
This subroutine looks horribly inefficient. You create this big automatic array each time you enter the subroutine, and you index through it backwards. Wouldn't it work better if you eliminated the NM array, if there is no more to it than you show here?

@tim18 ... thank you
do you mean Automatic array=Dynamic array , The Fortran77 does supports the Dynamic array . I am Using Compaq Fortran with Windows XP !!
What do you mean about the Subroutine ?? it must be in this form as I said , The NM array must be calculated only once and it is only used inside the subroutine ; so it shouldn't effect the program .
So simply , I CANNOT eliminte the NM array. :)

No, Fortran 77 doesn't support automatic arrays, even if some compiler called it dynamic array, it was still a non-standard extension. But that's aside from the question, except for the temptation to mis-use it. As the array is local to the subroutine, there's no apparent reason you couldn't at least define it with the subscripts in efficient order, if you don't want to cut it down to single subscript or eliminate it.
You noticed the problem with your stack overflow; I doubt you would have mentioned it if it didn't affect your program.
Currently supported compilers have heap-array alternatives for single threading; I guess CVF didn't have that option.
It's generally considered more reliable to use allocatable rather than automatic arrays, particularly when the array is large enough to incur danger of allocation failure. Possibly that could help. As I said, if you're looking for CVF expertise, the other forum is a better choice.

Leave a Comment

Please sign in to add a comment. Not a member? Join today