CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Main CFD Forum (
-   -   Effect of temp variables in subroutine (

CF April 18, 2008 01:54

Effect of temp variables in subroutine

I've quite a few subroutines for my CFD code. In most subroutines, I need them to accept input variables such as arrays. One e.g. is

subroutine area(xy,ab,cd,ans)

real(8), intent(in) :: xy(size_x,size_y),ab(size_x,size_y),cd(size_x,size _y)

real(8), intent(out) :: ans(size_x,size_y)


end subroutine area

Another way to do this is:

subroutine area


end subroutine area

where ans,ab,cd,xy are global variables.

If I do it by the 2nd method, will I save speed and memory? I've quite a few of the 1st type of subroutines and I wonder if I am wasting memory and slowing the code down. Of cos, for the 1st type, I could input different variables such as xy2,xy3 and it makes my code more compact.

Thank you.

Tom April 18, 2008 04:32

Re: Effect of temp variables in subroutine
It doesn't take up any extra memory since the arrays are not been reallocated/duplicated. Basically the first method simply passes the memory address of where the arrays are stored and then performs the calculation on that area of memory (just as if the arrays were global).

CF April 20, 2008 10:13

Re: Effect of temp variables in subroutine
Oic... thanks a lot for the clarification, Tom!

All times are GMT -4. The time now is 06:12.