|
[Sponsors] |
September 26, 2006, 14:47 |
Question for Fortran experts
|
#1 |
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, |
|
September 26, 2006, 15:21 |
Re: Question for Fortran experts
|
#2 |
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. |
|
September 26, 2006, 16:27 |
Re: Question for Fortran experts
|
#3 |
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 |
|
September 26, 2006, 16:35 |
Re: Question for Fortran experts
|
#4 |
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. |
|
September 27, 2006, 08:09 |
Re: Question for Fortran experts
|
#5 |
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. |
|
September 27, 2006, 09:30 |
Re: Question for Fortran experts
|
#6 |
Guest
Posts: n/a
|
Well! You answered my question. Thanks a lot!
|
|
|
|
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 |