|
From: nure123 on 26 Jan 2008 02:32 Hi All, I have some old code that I need to use. The code compiles and links all right but while running breaks down which the debugger says is due to stack overflow but increasing the stack size to any amount does not weed out the problem. Following code snippets recreate the problem. The code snippet and the original program too run ok if the array dimension is set to (64, 2001) instead of (65, 2001). In original code the routine has several tens of arguments and the dimensions are defined through constants defined in a separate file. I suspect, it is less of a language problem and more of a compiler specific problem. I am using Absoft Pro Fortran compiler and have set the stack size to (-stack:9850000009, the maximum I have set so far ). Could anybody suggest me a way out of the problem.. In file1: PROGRAM MAIN DOUBLE PRECISION a(65,2001) CALL ROUTINE1(a) END PROGRAM In file2: SUBROUTINE ROUTINE1(a) DOUBLE PRECISION a(65,2001) CALL ROUTINE1(a) RETURN END SUBROUTINE Regards, Nure
From: Ravindra Vidhate on 26 Jan 2008 02:43 As the your code shows that it is a recursive function so there must exists a condition to break this recursiveness. Ravindra
From: nure123 on 26 Jan 2008 02:55 On Jan 26, 1:43 am, Ravindra Vidhate <ravividh...(a)gmail.com> wrote: > As the your code shows that it is a recursive function so there must > exists a condition to break this recursiveness. > > Ravindra Sorry, I pasted the wrong version. Problem exists with the following code too. file1: PROGRAM MAIN DOUBLE PRECISION a(65,2001) CALL ROUTINE1(a) END PROGRAM file2: SUBROUTINE ROUTINE1(a) DOUBLE PRECISION a(65,2001) RETURN END SUBROUTINE
From: Louis Krupp on 26 Jan 2008 05:17 nure123(a)gmail.com wrote: > On Jan 26, 1:43 am, Ravindra Vidhate <ravividh...(a)gmail.com> wrote: >> As the your code shows that it is a recursive function so there must >> exists a condition to break this recursiveness. >> >> Ravindra > > Sorry, I pasted the wrong version. Problem exists with the following > code too. > > file1: > PROGRAM MAIN > DOUBLE PRECISION a(65,2001) > CALL ROUTINE1(a) > END PROGRAM > > file2: > SUBROUTINE ROUTINE1(a) > DOUBLE PRECISION a(65,2001) > RETURN > END SUBROUTINE You might try adding "SAVE" to the array declaration in your main program: SAVE DOUBLE PRECISION a(65,2001) This might get the array off the stack at the expense of making your code file bigger. Dynamically allocating the array might be even better; see your Fortran manual for details. (Others here will know more about these options, but depending on what time zone you're in, this might be useful for now.) Louis
From: fj on 26 Jan 2008 06:43
On 26 jan, 08:55, nure...(a)gmail.com wrote: > On Jan 26, 1:43 am, Ravindra Vidhate <ravividh...(a)gmail.com> wrote: > > > As the your code shows that it is a recursive function so there must > > exists a condition to break this recursiveness. > > > Ravindra > > Sorry, I pasted the wrong version. Problem exists with the following > code too. > > file1: > PROGRAM MAIN > DOUBLE PRECISION a(65,2001) > CALL ROUTINE1(a) > END PROGRAM > > file2: > SUBROUTINE ROUTINE1(a) > DOUBLE PRECISION a(65,2001) > RETURN > END SUBROUTINE In this second version, there is nothing wrong. It should work with any stack size ... and any FORTRAN commpiler. Are you sure it does not work ? Of course, your first example was clearly wrong ... with any stack and any FORTRAN compiler. Full recursivity without stop test cannot work ! |