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

Effect of temp variables in subroutine

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 18, 2008, 02:54
Default Effect of temp variables in subroutine
  #1
CF
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.

  Reply With Quote

Old   April 18, 2008, 05:32
Default Re: Effect of temp variables in subroutine
  #2
Tom
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).
  Reply With Quote

Old   April 20, 2008, 11:13
Default Re: Effect of temp variables in subroutine
  #3
CF
Guest
 
Posts: n/a
Oic... thanks a lot for the clarification, Tom!
  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
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


All times are GMT -4. The time now is 18:28.