I encountered a strange problem when I made my CFD code using FORTRAN.
I have many subroutines in my code. In order to avoid defining arrays repeatedly in the subroutines, I made a file to define all the arrays used in the code, comn.f. In each subroutine, I only use INCLUDE to define the arrays like:
subroutine momentum include 'comn.f'
I found if I increase the number of arrays in comn.f but do not change any other things in the code, the CPU time increases significantly.
I wonder if the way I define array is expensive in CPU. I wonder if you would please give me explainations and suggestions.
Thanks you very much.
Re: cpu time
There are many possible expainations for this, and it is likely that you are experiencing more than one of the possible reasons. I assume you are referring to execution time of the simulation, and not compile time. If the issue is compiler time, then who cares (I don't).
Here are a few ideas: (1) The number of dimensions in your arrays. The best would be one dimensional arrays. There are a number of additional index calculations when using many array indicies. Of course a three dimensional array can be manipulated as a one-dimensional array. (2) paging due to address space being larger than physical memory. The more array space, the more likely you are paging between memory and disk (3) The order of accessing the array
Do l =
Do m =
A(m,l,k) = ...
is faster than
Do l =
Do m =
A(k,l,m) = ...
If you are paging, the difference in these two formulations is dramatic.
(4) size of the address space that is frequently accessed. The optimimum is to have the size of frequenlty accessed data be smaller than your cache, and certainly smaller than your physical memory. There are ingenious ways to layout arrays so as to accomplish this. The old fashion techniques for vector computers, and computers with multiple levels of memory are very applicable here, and can speed performance on today's cpus significantly.
|All times are GMT -4. The time now is 22:16.|