|
[Sponsors] |
Stack frame size, Origin 2000, fortran, a question. |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 20, 1999, 07:07 |
Stack frame size, Origin 2000, fortran, a question.
|
#1 |
Guest
Posts: n/a
|
Hi.
Compiling a fortran program using SGI fortran77 compiler on Origin 200 I got a warning message about a stack frame size. I know how to change the stack size limit, but how does one change the stack frame size limit? Or is it the same? And there is another question, more fundamental. To be precise, the program (in a way of experiment, you know) ---------------------------------- dimension a(4000,30000) call B(a,4000) stop end subroutine B(a,N) dimension a(N,*) return end gives $ f77 test.f "test.f": Warning: Stack frame size (480000032) larger than system limit (268435456) If a(,) is passed to the subroutine via a common block, not as a parameter, no warning is given. Therefore, there is a way around. ----------------------------------- However, I would like to understand. I thought that when an array is passed to a subroutine, only the address of a(1,1) is put in the stack. Why, then, the size of the array is counted in the stack size? And if by any chance, the entire array is put in the stack (why? multitasking+multiprocessoring+shared memory needs?) then can it be that common block will give better performance? I would be very grateful for a precise answer. Or any ideas, really. Sergei |
|
February 22, 1999, 10:01 |
Re: Stack frame size, Origin 2000, fortran, a question.
|
#2 |
Guest
Posts: n/a
|
In a subroutine, variables defined inside the subroutine is local to the subroutine. These variables exist only throughout the life time of the subroutine, that is the variables are created when the subroutine is called, and the variables are destroyed when the subroutine is returned. Therefore, all local variables inside the subroutine are local unless they are declared as global in the common block. The local variables are dynamically created. Therefore, you need a place to hold these dynamically created variables. The compiler does not know the actually size required for these variables until the program is actually executed at run time. This is not machine or compiler specific. (although there is always limit to the size of subroutine and local variables.)
|
|
February 22, 1999, 12:41 |
Re: Stack frame size, Origin 2000, fortran, a question.
|
#3 |
Guest
Posts: n/a
|
Thank you, John.
I am afraid, you did not answer my question. Stack is a region in the memory which works in the mode last in-first out. When a subroutine is called, say, with CALL A(B,C,D), the addresses of B,C,D are put into the stack and the control is passed to the subroutine. The subroutine extracts the addresses of B,C,D from the stack, since it knows how many formal parameters (=arguments) it has. If A is an array, A(i,j), then the address of A is the address of the first element of A, that is A(1,1). In this example, therefore, the size of the stack should be larger than the memory size needed for keeping three addresses, but that's enough! It has nothing to do with the size of the array itself. This is possible because, according to the fortran standard, the address of the array element is calculated always in the same way: Addr(a(i,j))=Addr(a(1,1))+(j-1)*N+i-1, where N is the leading dimension of A. Also, Addr(b(k))=Addr(b(1))+k-1. As a result, you can, if you wish, treat a two-D array as a one-D array, which is a common trick among programmers. This is how I understand it. Why, then, that compiler includes the size of the entire array into the required stack size? This was my main question. By the way, changing the stack size limit turned out to be sufficient to satisfy the requirement for stack frame size. Thanks again. Yours Sergei |
|
February 22, 1999, 13:20 |
Re: Stack frame size, Origin 2000, fortran, a question.
|
#4 |
Guest
Posts: n/a
|
When you declare a DIMENSION statement inside a subroutine, the memory to hold that array ( every element) will have to be dynamically allocated. ( on the other hand, if you use COMMON statement, the memory required to hold that array is pre-allocated for you). If you don't pre-allocate the memory for the array, when you use the subroutine, it needs the additional memory space ( in addition to the pre-allocated memory). Where do you get these additional memory space? You have to set aside additional memory space to be used as dynamic memory. Maybe some compiler experts can give us a better answer.
|
|
February 22, 1999, 15:24 |
Re: Stack frame size, Origin 2000, fortran, a question.
|
#5 |
Guest
Posts: n/a
|
Dear John,
>When you declare a DIMENSION statement inside a subroutine, >the memory to hold that array ( every element) will have to >be dynamically allocated. Not necessarily. In subroutine A(B) dimension B(100),C(100) ... memory for C can be dynamically allocated (it depends on the compiler and/or the compiler options you give), but the memory for B is allocated outside the subroutine. Anyway, this is irrelevant. I was asking about the stack size. >Maybe some compiler experts can give us a better answer. This is what I am hoping for. Thank you. Yours Sergei |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
A question about size function | Mike | FLUENT | 0 | January 5, 2009 08:09 |
Fortran question | Noureddine | Main CFD Forum | 12 | October 31, 2007 14:07 |
Question for Fortran experts | jojo | Main CFD Forum | 5 | September 27, 2006 09:30 |
Fortran Question | Vishwas | Main CFD Forum | 1 | April 12, 2006 18:56 |
Tiny size particle question. (DPM) | ggbaby | FLUENT | 2 | August 18, 2004 11:14 |