summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoreschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2013-03-25 20:28:40 +0000
committereschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2013-03-25 20:28:40 +0000
commit069e8f1d570cc373c843673be0acf7bc4dd10b6e (patch)
treee210e253ec96aeb6f3b708560ca1a32b339e8128 /lib
parentf74e867aab6e3a36824f5c33ed1d75bac90ef06f (diff)
Allow setting parameter values at build time
Allow setting parameter values at build time, enabling additional compiler optimisations. I measured that e.g. ML_BSSN runs 5% to 10% faster if its parameters are chosen at build time. This introduces macros CCTK_PARAMETER${thorn}${parameter}. If unset, the parameter value is taken from the parameter file (default). If set at compile time, e.g. via a -D option in CPPFLAGS, this overrides the parameter database, and DECLARE_CCTK_PARAMETERS will always use this value. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4989 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib')
-rw-r--r--lib/sbin/CreateParameterBindings.pl14
-rw-r--r--lib/sbin/create_c_stuff.pl21
2 files changed, 26 insertions, 9 deletions
diff --git a/lib/sbin/CreateParameterBindings.pl b/lib/sbin/CreateParameterBindings.pl
index 52862243..f3c55faa 100644
--- a/lib/sbin/CreateParameterBindings.pl
+++ b/lib/sbin/CreateParameterBindings.pl
@@ -202,7 +202,9 @@ sub CreateParameterBindings
push(@data, " DECLARE_PRIVATE_\U$thorn\E_STRUCT_PARAMS \\")
if($header_files{"\U$thorn\E PRIVATE"});
- my $delim = ' ';
+ # double this loop, add #defines for RESTRICTED_STRUCT.$realname, set these via #ifdef, use these #defines
+
+ my @data2;
foreach $friend (split(' ',$rhparameter_db->{"\U$thorn\E SHARES implementations"}))
{
$rhinterface_db->{"IMPLEMENTATION \U$friend\E THORNS"} =~ m:([^ ]*):;
@@ -223,12 +225,18 @@ sub CreateParameterBindings
$varprefix = ' const *';
}
- push(@data, " CCTK_DECLARE_INIT ($type_string$varprefix const, $parameter, RESTRICTED_\U$friend\E_STRUCT.$realname); \\");
- $delim = ',';
+ #push(@data, " CCTK_DECLARE_INIT ($type_string$varprefix const, $parameter, RESTRICTED_\U$friend\E_STRUCT.$realname); \\");
+ push(@data, " CCTK_DECLARE_INIT ($type_string$varprefix const, $parameter, CCTK_PARAMETER__${friend_thorn}__${realname}); \\");
+ push(@data2,
+ "#ifndef CCTK_PARAMETER__${friend_thorn}__${realname}\n" .
+ "# define CCTK_PARAMETER__${friend_thorn}__${realname} RESTRICTED_\U$friend\E_STRUCT.$realname\n" .
+ "#endif");
}
}
push(@data, '');
+ push(@data, @data2);
+ push(@data, '');
push(@data, "#endif /* _\U$thorn\E_PARAMETERS_H_ */");
push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline
diff --git a/lib/sbin/create_c_stuff.pl b/lib/sbin/create_c_stuff.pl
index 3277c15f..71087362 100644
--- a/lib/sbin/create_c_stuff.pl
+++ b/lib/sbin/create_c_stuff.pl
@@ -175,7 +175,13 @@ sub CreateCStructureParameterHeader
my($line,@data);
my(%parameters);
my($type, $type_string);
- my(@definition);
+ my(@definition, @definition2);
+
+ # determine thorn name from structure name
+ # TODO: pass thorn name explicitly
+ my $thorn = $structure;
+ $thorn =~ s{^[^_]*_}{}; # remove PRIVATE_ or RESTRICTED_ prefix
+ $thorn =~ s{_STRUCT$}{};
# Create the structure
push(@data, '#ifdef __cplusplus');
@@ -185,7 +191,6 @@ sub CreateCStructureParameterHeader
push(@data, '');
push(@data, 'extern struct');
push(@data, '{');
- my $delim = ' ';
foreach $parameter (&order_params($rhparameters, $rhparameter_db))
{
@@ -206,8 +211,12 @@ sub CreateCStructureParameterHeader
my $realname = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E realname"};
push(@data, " $type_string $realname$suffix;");
- push(@definition, " CCTK_DECLARE_INIT ($type_string$varprefix const, $parameter, $structure.$realname); \\");
- $delim = ',';
+ #push(@definition, " CCTK_DECLARE_INIT ($type_string$varprefix const, $parameter, $structure.$realname); \\");
+ push(@definition, " CCTK_DECLARE_INIT ($type_string$varprefix const, $parameter, CCTK_PARAMETER__${thorn}__$realname); \\");
+ push(@definition2,
+ "#ifndef CCTK_PARAMETER__${thorn}__$realname\n" .
+ "# define CCTK_PARAMETER__${thorn}__$realname $structure.$realname\n" .
+ "#endif");
}
# Some compilers don't like an empty structure.
@@ -226,8 +235,8 @@ sub CreateCStructureParameterHeader
push(@data, "#define DECLARE_${structure}_PARAMS \\");
push(@data, @definition);
-
- push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline
+ push(@data, "\n");
+ push(@data, @definition2);
return join ("\n", @data);
}