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

Fortran programming style

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 25, 2011, 21:33
Default Fortran programming style
  #1
Member
 
Shenren Xu
Join Date: Jan 2011
Location: London, U.K.
Posts: 67
Rep Power: 15
Shenren_CN is on a distinguished road
Hi,

I'm new to writing CFD code in Fortran. I saw two different styles in writing code in Fortran lately and have been wondering what's the pros and cons of both.

One of them uses global variables substantially, and when a subroutine is called, there's normally no parameters pass; the other uses local variables, and every time a subroutine is called, a long list of parameters are passed, which is giving me trouble in easily keeping track of the variables being passed and used.

Intuitively, I think the 1st approach is better, apparently more readable. I wonder what's your opinion on this, and any suggestion on which style I should adopt when I write my code.

Cheers,
SX
Shenren_CN is offline   Reply With Quote

Old   January 25, 2011, 21:38
Default
  #2
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 20
DoHander is on a distinguished road
If you want to be able to parallelize your code at a later time, you will avoid the use of global variables.

(personal opinion of course)

Do
DoHander is offline   Reply With Quote

Old   January 26, 2011, 05:24
Default
  #3
Member
 
Shenren Xu
Join Date: Jan 2011
Location: London, U.K.
Posts: 67
Rep Power: 15
Shenren_CN is on a distinguished road
Quote:
Originally Posted by DoHander View Post
If you want to be able to parallelize your code at a later time, you will avoid the use of global variables.

(personal opinion of course)

Do

Thanks DoHander,
Could you please elaborate a little bit on this? Since I don't know anything about parallelization yet, why would global variables cause trouble for doing that?

Regards,
SX
Shenren_CN is offline   Reply With Quote

Old   January 31, 2011, 09:53
Default
  #4
Senior Member
 
ztdep's Avatar
 
p ding
Join Date: Mar 2009
Posts: 427
Rep Power: 19
ztdep is on a distinguished road
Send a message via Yahoo to ztdep Send a message via Skype™ to ztdep
for large cfd procedure, do not use global variable heaviley.
feel free to use class, and subroutine to exchange infromation.
look like a black box to other people
ztdep is offline   Reply With Quote

Old   February 1, 2011, 10:08
Default
  #5
Senior Member
 
Rami Ben-Zvi
Join Date: Mar 2009
Posts: 155
Rep Power: 17
Rami is on a distinguished road
Hello Shenren Xu,

Another reason to avoid global variables is they make code debugging difficult, as when some variable changes, it is difficult to trace where it was changed.
Rami
Rami is offline   Reply With Quote

Old   February 3, 2011, 00:00
Default
  #6
Member
 
Mohammad Reza Hadian
Join Date: Mar 2009
Location: Yazd, Iran
Posts: 52
Rep Power: 17
hadian is on a distinguished road
though passing variables to a subroutine by its argument is more recommended by programmers ( and i like it more), but the code run faster when you use global variables. In C family languages the pointer targeting the first member of a array in passed to a function, but if FORTRAN other information is passed and this can slow down the code. Moreover, the memory of the system should be considered too. when you use local variables, you will use extra memory for those variables when the sub-program is running.
hadian is offline   Reply With Quote

Old   February 4, 2011, 07:57
Default
  #7
New Member
 
lpk
Join Date: Apr 2009
Posts: 2
Rep Power: 0
Mich is on a distinguished road
Arrays and variables which don't change in "main loop", it is possible to make global. For example, grid nodes.
Mich is offline   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
programming language for CFD, C, C++, FORTRAN,.... hadian Main CFD Forum 15 September 9, 2008 23:19
GUI programming with FORTRAN ztdep Main CFD Forum 1 August 30, 2007 14:22
A problem in FORTRAN programming Behafarid Main CFD Forum 6 August 16, 2006 13:16
Fortran programming and 64 bit machine Q Main CFD Forum 4 November 7, 2005 06:18
C++ fortran mixed programming: allocatable array vito Main CFD Forum 1 April 19, 2005 12:11


All times are GMT -4. The time now is 03:52.