- removed comment
Improve performance of Fortran index calculations
In Fortran, Cactus currently declares grid functions e.g. as (this is the expansion of DECLARE_CCTK_ARGUMENTS)
REAL*8 gxx (X0metric,X1metric,X2metric)
where X0metric etc. are integers passed into the routine. Each grid function group has its own, independent size. This has two disadvantages:
1. The compiler does not know that all grid functions have the same size (namely cctk_lsh), and thus has to perform array index calculations separately for each group 2. The argument list is longer than neded
The enclosed patch declares grid functions via cctk_lsh. Grid arrays are still declared independently.
This reduces the code size of e.g. GRHydro/GRHydro_Tmunu.F90 from 6836 to 6241 bytes on my system. I have not attempted to measure a performance difference.
Keyword:
Comments (6)
-
-
reporter - removed comment
I do not know how efficient Fortran compilers are when arrays sizes are defined via an array. I therefore introduced three local scalars cctk_lsh1 cctk_lsh2 cctk_lsh3 that are used to specify the first three dimensions. Since these are the "innermost" dimensions, they are most crucial for performance. These scalars are set via CCTK_FARGUMENTS as defined in cctk.h.
-
- removed comment
So, the "if ($dim<3)" could also be an "if ($dim<=3)"? (You define cctk_lsh3 as well)
-
reporter - removed comment
No, $dim1 = $dim+1, since this loop counts dimensions from 0, while Fortran counts from 1.
-
- removed comment
Right. Maybe we should use dim1 in the 'if' construct to avoid others thinking along the same wrong lines as me. You are right, the code is ok.
-
reporter - changed status to resolved
- removed comment
Applied.
- Log in to comment
Why is there the conditional in GridFuncStuff.pl (new line 394):
+ if ($dim<3) + { + $type .= "${sep}cctk_lsh$dim1"; + } + else + { + $type .= "${sep}cctk_lsh($dim1)"; + }