|
[Sponsors] |
April 18, 2008, 02:54 |
Effect of temp variables in subroutine
|
#1 |
Guest
Posts: n/a
|
Hi,
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) ans=ab*cd+xy end subroutine area Another way to do this is: subroutine area ans=ab*cd+xy 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. |
|
April 18, 2008, 05:32 |
Re: Effect of temp variables in subroutine
|
#2 |
Guest
Posts: n/a
|
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).
|
|
April 20, 2008, 11:13 |
Re: Effect of temp variables in subroutine
|
#3 |
Guest
Posts: n/a
|
Oic... thanks a lot for the clarification, Tom!
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
additional variables' effect | ariel | CFX | 9 | April 2, 2008 01:41 |
Effect of wall temp. on convergence | ben akih | CFX | 3 | September 27, 2006 18:25 |
REAL GAS UDF | brian | FLUENT | 6 | September 11, 2006 09:23 |
user SUBROUTINE for additional variables | Tuks | CFX | 0 | November 8, 2005 03:09 |
input variables in subroutine..? | mspark | Siemens | 1 | April 6, 2004 18:52 |