diff options
author | eschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2011-10-27 22:21:49 +0000 |
---|---|---|
committer | eschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2011-10-27 22:21:49 +0000 |
commit | cd846335f5afd751f7cfea9855efc52b0331cc30 (patch) | |
tree | df1ec872291fcaeb0bdfa9c1cb4e2799138f5c48 | |
parent | 34457bea62fffbb9e73edfafe315d4434dd043cc (diff) |
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:
- 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
- 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.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4763 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r-- | lib/make/force-rebuild | 1 | ||||
-rw-r--r-- | lib/sbin/GridFuncStuff.pl | 32 | ||||
-rw-r--r-- | src/include/cctk.h | 21 |
3 files changed, 43 insertions, 11 deletions
diff --git a/lib/make/force-rebuild b/lib/make/force-rebuild index 9c0475b5..d4247101 100644 --- a/lib/make/force-rebuild +++ b/lib/make/force-rebuild @@ -35,3 +35,4 @@ 08 Apr 2008: Add IF clause to scheduler 23 Dec 2010: Rename cctki_Capabilities.h to cctk_Capabilities.h 20 Jan 2011: Generate prototypes for scheduled functions +27 Oct 2011: Optimize CCTK_ARGUMENTS for grid functions in Fortran diff --git a/lib/sbin/GridFuncStuff.pl b/lib/sbin/GridFuncStuff.pl index d12831ed..f564d954 100644 --- a/lib/sbin/GridFuncStuff.pl +++ b/lib/sbin/GridFuncStuff.pl @@ -381,19 +381,37 @@ sub GetThornArguments { # FIXME: quick hack to shorten argument names # $type .= "${sep}cctkv$dim$group"; - $type .= "${sep}X$dim$group"; - $sep = ','; - if($block eq 'PRIVATE') + if ($gtype ne 'GF') { -# FIXME: quick hack to shorten argument names -# $arguments{"cctkv$dim$group"} = "(STORAGESIZE($thorn\::$group, $dim))"; - $arguments{"X$dim$group"} = "(STORAGESIZE($thorn\::$group, $dim))"; + $type .= "${sep}X$dim$group"; } else { + my $dim1=$dim+1; + if ($dim<3) + { + $type .= "${sep}cctk_lsh$dim1"; + } + else + { + $type .= "${sep}cctk_lsh($dim1)"; + } + } + $sep = ','; + if ($gtype ne 'GF') + { + if($block eq 'PRIVATE') + { +# FIXME: quick hack to shorten argument names +# $arguments{"cctkv$dim$group"} = "(STORAGESIZE($thorn\::$group, $dim))"; + $arguments{"X$dim$group"} = "(STORAGESIZE($thorn\::$group, $dim))"; + } + else + { # FIXME: quick hack to shorten argument names # $arguments{"cctkv$dim$group"} = "(STORAGESIZE($imp\::$group, $dim))"; - $arguments{"X$dim$group"} = "(STORAGESIZE($imp\::$group, $dim))"; + $arguments{"X$dim$group"} = "(STORAGESIZE($imp\::$group, $dim))"; + } } } if(defined($vararraysize) && $compactgroup == 0) diff --git a/src/include/cctk.h b/src/include/cctk.h index a258dc4d..32bcac79 100644 --- a/src/include/cctk.h +++ b/src/include/cctk.h @@ -37,7 +37,8 @@ cctk_dim,cctk_gsh,cctk_lsh,cctk_lbnd,cctk_ubnd,cctk_lssh,cctk_from,cctk_to,\ cctk_bbox,cctk_delta_time,cctk_time,cctk_delta_space,cctk_origin_space,\ cctk_levfac,cctk_levoff,cctk_levoffdenom,cctk_timefac,cctk_convlevel,\ -cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH +cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH,\ +cctk_lsh1,cctk_lsh2,cctk_lsh3 #define _DECLARE_CCTK_ARGUMENTS _DECLARE_CCTK_FARGUMENTS #define _DECLARE_CCTK_FARGUMENTS &&\ @@ -62,7 +63,10 @@ cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH CCTK_DECLARE(INTEGER,cctk_convfac,)&&\ CCTK_DECLARE(INTEGER,cctk_nghostzones,(cctk_dim))&&\ CCTK_DECLARE(INTEGER,cctk_iteration,)&&\ - CCTK_DECLARE(CCTK_POINTER,cctkGH,)&& + CCTK_DECLARE(CCTK_POINTER,cctkGH,)&&\ + CCTK_DECLARE(INTEGER,cctk_lsh1,)&&\ + CCTK_DECLARE(INTEGER,cctk_lsh2,)&&\ + CCTK_DECLARE(INTEGER,cctk_lsh3,)&& #define CCTK_WARN(a,b) CCTK_Warn(a,__LINE__,__FORTRANFILE__,CCTK_THORNSTRING,b) @@ -164,6 +168,9 @@ cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH /* Include prototypes for scheduled functions */ #include "cctk_ScheduleFunctions.h" +/* Include prototypes for scheduled functions */ +#include "cctk_ScheduleFunctions.h" + /* Include definitions provided by capabilities */ #include "cctk_Capabilities.h" @@ -479,7 +486,10 @@ static inline int CCTK_VECTGFINDEX4D (const cGH *GH, &((xGH)->cctk_convfac),\ (xGH)->cctk_nghostzones,\ &((xGH)->cctk_iteration),\ - &(xGH) + &(xGH),\ + &(xGH)->cctk_lsh[0],\ + &(xGH)->cctk_lsh[1],\ + &(xGH)->cctk_lsh[2] #define _CCTK_C2F_PROTO int *,\ int *,\ int *,int *, int *, int *, int *,int *,int *,\ @@ -493,7 +503,10 @@ static inline int CCTK_VECTGFINDEX4D (const cGH *GH, int *,\ int *,\ int *,\ - cGH ** + cGH **,\ + int *,\ + int *,\ + int * #define CCTK_EQUALS(a,b) (CCTK_Equals((a),(b))) |