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

Stack overflow problem

ghazooo
Beginner
1,008 Views

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
Ghazooo

0 Kudos
6 Replies
TimP
Honored Contributor III
1,008 Views
I don't know that your example makes it clear why there is a stack overflow. However, if this is part of a large finite element method, you certainly will need to give attention to organize your loops for cache locality. When your loops are nested backwards, problems worsen rapidly as you make the arrays bigger.
0 Kudos
herger
Beginner
1,008 Views
Quoting - ghazooo

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
Ghazooo



Hi.
I hope I can help.
Maybe the problem is in the precision You chose.
Your NM is an array with 507x507 elements and also MELE is a vector fo 507*507 elemnts: maybe You should declare them with higher precision.
Hope this helps, best regards

Herger
0 Kudos
Ron_Green
Moderator
1,008 Views
When passing arrays to a subroutine, and the array is contiguous, you can often avoid creating a temporary copy by using either an INTERFACE declaration in your main program OR you can make your subroutine a CONTAINed subroutine and avoid passing the arguments.

There are other methods as well, these are the most common. Let me know if you need more help, but first try creating an interface block in the main program for the subroutine nigtee.

ron
0 Kudos
ghazooo
Beginner
1,008 Views
Quoting - tim18
I don't know that your example makes it clear why there is a stack overflow. However, if this is part of a large finite element method, you certainly will need to give attention to organize your loops for cache locality. When your loops are nested backwards, problems worsen rapidly as you make the arrays bigger.

Hi ..
Don't worry about my loops .. It works fine :))
cosider my problem is only with this simple program.
Thanks
0 Kudos
ghazooo
Beginner
1,008 Views
Quoting - herger


Hi.
I hope I can help.
Maybe the problem is in the precision You chose.
Your NM is an array with 507x507 elements and also MELE is a vector fo 507*507 elemnts: maybe You should declare them with higher precision.
Hope this helps, best regards

Herger

Hi ..
I tryed that before but didn't solve the problem.
Thank you
0 Kudos
ghazooo
Beginner
1,008 Views
When passing arrays to a subroutine, and the array is contiguous, you can often avoid creating a temporary copy by using either an INTERFACE declaration in your main program OR you can make your subroutine a CONTAINed subroutine and avoid passing the arguments.

There are other methods as well, these are the most common. Let me know if you need more help, but first try creating an interface block in the main program for the subroutine nigtee.

ron

Hello Sir ;
Thank you for your answer ... I think I've diagnosed the problem as you did .
The problem is with th subroutine NIGTEE.
Honestly , I don't know how to create the INTERFACE structure !! and Iam working with Fortran 77.
I will be very happy if you help me with that ..
Than you very much
0 Kudos
Reply