CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Stack frame size, Origin 2000, fortran, a question.

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 20, 1999, 06:07
Default Stack frame size, Origin 2000, fortran, a question.
  #1
Sergei Chernyshenko
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

  Reply With Quote

Old   February 22, 1999, 09:01
Default Re: Stack frame size, Origin 2000, fortran, a question.
  #2
John C. Chien
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.)
  Reply With Quote

Old   February 22, 1999, 11:41
Default Re: Stack frame size, Origin 2000, fortran, a question.
  #3
Sergei Chernyshenko
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
  Reply With Quote

Old   February 22, 1999, 12:20
Default Re: Stack frame size, Origin 2000, fortran, a question.
  #4
John C. Chien
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.
  Reply With Quote

Old   February 22, 1999, 14:24
Default Re: Stack frame size, Origin 2000, fortran, a question.
  #5
Sergei Chernyshenko
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
  Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A question about size function Mike FLUENT 0 January 5, 2009 07:09
Fortran question Noureddine Main CFD Forum 12 October 31, 2007 13:07
Question for Fortran experts jojo Main CFD Forum 5 September 27, 2006 08:30
Fortran Question Vishwas Main CFD Forum 1 April 12, 2006 17:56
Tiny size particle question. (DPM) ggbaby FLUENT 2 August 18, 2004 10:14


All times are GMT -4. The time now is 02:51.