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

Effect of temp variables in subroutine

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   April 18, 2008, 01: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, 04: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, 10: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

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
additional variables' effect ariel CFX 9 April 2, 2008 00:41
Effect of wall temp. on convergence ben akih CFX 3 September 27, 2006 17:25
REAL GAS UDF brian FLUENT 6 September 11, 2006 08:23
user SUBROUTINE for additional variables Tuks CFX 0 November 8, 2005 03:09
input variables in subroutine..? mspark CD-adapco 1 April 6, 2004 17:52


All times are GMT -4. The time now is 04:39.