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

Question for Fortran experts

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 26, 2006, 14:47
Default Question for Fortran experts
  #1
jojo
Guest
 
Posts: n/a
Hi everybody,

I have a question which, curiously, is not addressed in recent Fortran handbooks (maybe I have missed the single-line remark in the 1000-pages books I have read...):

What is best for optimization?

1) allocate dynamic arrays in a subroutine (i.e., arrays will be allocated/de-allocated each time the routine is called)

2) pass working arrays as arguments from the main program, as it used to be in former versions of Fortran.

I prefer solution 1) as it improves the readiness of the code but I am not sure it is the most efficient one from a computational point of view.

Cheers,
  Reply With Quote

Old   September 26, 2006, 15:21
Default Re: Question for Fortran experts
  #2
opaque
Guest
 
Posts: n/a
Dear jojo..

The answer is language independent..

Try allocating/freeing memory within a long loop and your program will crawl to a halt.. In particular, if the chunk sizes changes within the loop..

If your routine is called a few times.. Go for 1.. If your routine is called many times, you are better of going with 2..

Take a finite element assembly routine that is called for every element.. You could be talking about millions of calls.

Not a definite answer, but hope it helps,

Opaque.

  Reply With Quote

Old   September 26, 2006, 16:27
Default Re: Question for Fortran experts
  #3
Arek
Guest
 
Posts: n/a
Hi,

IMHO the better way is allocating arrays only once and passing them as an argument or using modules. It's probably true for any language. See "Matlab guide" by D. and N. Higham, chapter "Optimizing M-files". Of course it depends what is your primary goal speed or memory usage optimization. Regards Arek
  Reply With Quote

Old   September 26, 2006, 16:35
Default Re: Question for Fortran experts
  #4
Renato.
Guest
 
Posts: n/a
The best for optimization is usually the simplest form, option 2, static arrays in the main program being passed as arguments for subroutines, but, in my opinion, it's only useful for academic purposes nowadays since it's hard to keep a large program that is supposed to run several different cases with distinct memory requirements. In my case, I try to group the biggest and more used arrays in few modules (2 at most) and the memory allocation is done once whithin a "MemoryManagement" routine at the beginning of the program to diminish memory trash and fragmentation effects. Of course, whenever possible I reuse some of these arrays for other purposes to avoid new allocations.

Regards

Renato.

  Reply With Quote

Old   September 27, 2006, 08:09
Default Re: Question for Fortran experts
  #5
Mani
Guest
 
Posts: n/a
Let's repeat it one more time

Allocate your arrays in a subroutine only if the arrays are not huge and the subroutine is not the one limiting the performance of your program.

For efficiency, option 2 is preferred because allocating (searching for free memory) takes time. Now you still have two options: pass the array as argument, or use a module (common block in legacy Fortran). You can make your subroutine more generic by using arguments, and I am not sure that the access of memory through a module is any more efficient than that. If the array in question is used in other subroutines as well, and the subroutine is written to work exclusively on this global array, a module would be the convenient choice.
  Reply With Quote

Old   September 27, 2006, 09:30
Default Re: Question for Fortran experts
  #6
jojo
Guest
 
Posts: n/a
Well! You answered my question. Thanks a lot!

  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
question about uds tanven FLUENT 2 July 5, 2015 12:22
Unanswered question niklas OpenFOAM 2 July 31, 2013 17:03
A interesting question for multiphase experts!? Asghari FLUENT 0 April 4, 2007 08:51
CHANNEL FLOW: a question and a request Carlos Main CFD Forum 4 August 23, 2002 06:55
question K.L.Huang Siemens 1 March 29, 2000 05:57


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