Skip to content

Commit

Permalink
Add a Calculation option SimpleCode
Browse files Browse the repository at this point in the history
This is currently very elementary and only works in very specific cases.  It avoids precomputing derivatives and introducing temporary variables for grid functions.  This works around compilers which are not able to optimize these things away.
  • Loading branch information
ianhinder committed Apr 14, 2012
1 parent 5c7d898 commit b865739
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 26 additions & 2 deletions Tools/CodeGen/CalculationFunction.m
Expand Up @@ -145,7 +145,7 @@ indentation after each line break (this will push the line length
Shorthands, ConditionalOnKeyword, Before, After,
ConditionalOnTextuals, Where, ConditionalOnKeywords,
CollectList, AllowedSymbols, ApplyBCs, Conditional, CachedVariables, SplitBy,
SeparatedDerivatives, LocalGroups, NoSimplify, UseDGFE};
SeparatedDerivatives, LocalGroups, NoSimplify, UseDGFE, SimpleCode};

usedKeys = Map[First, calc];
unknownKeys = Complement[usedKeys, allowedKeys];
Expand Down Expand Up @@ -725,7 +725,9 @@ pathalogical enough (e.g. {s1 -> s2, s2 -> s1} would not be

If[gfs != {},
{
eqLoop = equationLoop[eqs, cleancalc, gfs, shorts, {}, groups, odeGroups,
eqLoop = If[lookup[calcp, SimpleCode, False],
simpleEquationLoop,
equationLoop][eqs, cleancalc, gfs, shorts, {}, groups, odeGroups,
pddefs, where, addToStencilWidth, opts]},
{}]

Expand Down Expand Up @@ -996,6 +998,28 @@ it is only possible to do this outside all if(){} statements. *)

If[debugInLoop, Map[InfoVariable[gridName[#]] &, gfsInLHS], ""]}, opts]}]];

Options[simpleEquationLoop] = ThornOptions;
DefFn[
simpleEquationLoop[eqs_, cleancalc_, gfs_, shorts_, incs_, groups_, odeGroups_, pddefs_,
where_, addToStencilWidth_,
opts:OptionsPattern[]] :=
Module[
{functionName, eqs2, gridName},
functionName = ToString@lookup[cleancalc, Name];
eqs2 = eqs;
eqs2 = ReplaceDerivatives[pddefs, eqs2, False, OptionValue[ZeroDimensions],
lookup[cleancalc, MacroPointer]];
gridName = lookup[cleancalc, GFAccessFunction];

lookup[cleancalc,LoopFunction][
{
CommentedBlock[
"Calculate temporaries and grid functions",
Map[
assignVariableFromExpression[FlattenBlock@gridName[#[[1]]], #[[2]], False, False, True] &, eqs2]]
}, opts]]];


(* Unsorted *)

GridFunctionsInExpression[x_, groups_] :=
Expand Down
3 changes: 2 additions & 1 deletion Tools/CodeGen/Kranc.m
Expand Up @@ -47,7 +47,8 @@

{ConditionalOnKeyword, ConditionalOnKeywords, CollectList, Interior,
InteriorNoSync, Boundary, BoundaryWithGhosts, Where, PreDefinitions,
AllowedSymbols, Parameters, ConditionalOnTextuals, ApplyBCs};
AllowedSymbols, Parameters, ConditionalOnTextuals, ApplyBCs,
SimpleCode};

(* Differencing.m *)

Expand Down

0 comments on commit b865739

Please sign in to comment.