From 28e774d72de23cb7be50194073a3627922cf9a55 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Sat, 9 Jan 2010 16:32:05 -0600 Subject: Introduce a new grid function iterator InteriorNoSync. This has the same effect as Interior, but does not synchronise the variables. This can be used e.g. to calculate the RHS terms. Introduce a way to access grid function that may or may not have storage. If a local variable name matches the pattern "eT*L", then it is read from the corresponding grid function only if the parameter useMatter is true; otherwise it is set to zero. This is obviously intended for the TmunuBase variables. This is implemented via a new Kranc function maybeAssignVariableInLoop. --- Tools/CodeGen/CalculationFunction.m | 9 ++++++++- Tools/CodeGen/CodeGen.m | 7 +++++++ Tools/CodeGen/KrancThorn.m | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'Tools/CodeGen') diff --git a/Tools/CodeGen/CalculationFunction.m b/Tools/CodeGen/CalculationFunction.m index d24431d..ecf2150 100644 --- a/Tools/CodeGen/CalculationFunction.m +++ b/Tools/CodeGen/CalculationFunction.m @@ -24,7 +24,7 @@ BeginPackage["sym`"]; {GridFunctions, Shorthands, Equations, t, DeclarationIncludes, LoopPreIncludes, GroupImplementations, PartialDerivatives, Dplus1, NoSimplify, -Dplus2, Dplus3, Boundary, Interior, Where, AddToStencilWidth, Everywhere, normal1, normal2, normal3} +Dplus2, Dplus3, Boundary, Interior, InteriorNoSync, Where, AddToStencilWidth, Everywhere, normal1, normal2, normal3} {INV, SQR, CUB, QAD, dot, pow, exp,dx,dy,dz, idx, idy, idz} @@ -556,6 +556,7 @@ CreateCalculationFunction[calc_, debug_, useLoopControl_, useCSE_] := Switch[where, Everywhere, DefineCCTKSubroutine[functionName, "GenericFD_LoopOverEverything(cctkGH, &" <> bodyFunctionName <> ");\n"], Interior, DefineCCTKSubroutine[functionName, "GenericFD_LoopOverInterior(cctkGH, &" <> bodyFunctionName <> ");\n"], + InteriorNoSync, DefineCCTKSubroutine[functionName, "GenericFD_LoopOverInterior(cctkGH, &" <> bodyFunctionName <> ");\n"], Boundary, DefineCCTKSubroutine[functionName, "GenericFD_LoopOverBoundary(cctkGH, &" <> bodyFunctionName <> ");\n"], BoundaryWithGhosts, DefineCCTKSubroutine[functionName, "GenericFD_LoopOverBoundaryWithGhosts(cctkGH, &" <> bodyFunctionName <> ");\n"], PenaltyPrim2Char, DefineFunction[functionName, "CCTK_INT", @@ -713,9 +714,15 @@ equationLoop[eqs_, (* DeclareDerivatives[pddefs, eqs], *) DeclareDerivatives[defsWithoutShorts, eqsOrdered], +(* CommentedBlock["Assign local copies of grid functions", Map[AssignVariableInLoop[localName[#], GridName[#]] &, gfsInRHS]], +*) + CommentedBlock["Assign local copies of grid functions", + Map[MaybeAssignVariableInLoop[localName[#], GridName[#], + StringMatchQ[ToString[localName[#]], "eT*L"]] &, + gfsInRHS]], (* CommentedBlock["Check for nans", diff --git a/Tools/CodeGen/CodeGen.m b/Tools/CodeGen/CodeGen.m index c51eaf0..d3d0dfc 100644 --- a/Tools/CodeGen/CodeGen.m +++ b/Tools/CodeGen/CodeGen.m @@ -62,6 +62,8 @@ AssignVariable::usage = "AssignVariable[dest_, src_] returns a block of code " < "that assigns 'src' to 'dest'."; AssignVariableInLoop::usage = "AssignVariable[dest_, src_] returns a block of code " <> "that assigns 'src' to 'dest'."; +MaybeAssignVariableInLoop::usage = "MaybeAssignVariable[dest_, src_, cond_] returns a block of code " <> + "that assigns 'src' to 'dest'."; DeclareVariablesInLoopVectorised::usage = ""; AssignVariablesInLoopVectorised::usage = ""; TestForNaN::usage = "TestForNaN[expr_] returns a block of code " <> @@ -273,6 +275,11 @@ AssignVariableInLoop[dest_, src_] := TestForNaN[dest]}; *) +MaybeAssignVariableInLoop[dest_, src_, cond_] := + If [cond, + {dest, " = useMatter ? ", src, " : 0.0", EOL[]}, + {dest, " = ", src, EOL[]}]; + (* TODO: move these into OpenMP loop *) DeclareVariablesInLoopVectorised[dests_, temps_, srcs_] := { diff --git a/Tools/CodeGen/KrancThorn.m b/Tools/CodeGen/KrancThorn.m index bce9a0f..9ca57ec 100644 --- a/Tools/CodeGen/KrancThorn.m +++ b/Tools/CodeGen/KrancThorn.m @@ -34,7 +34,7 @@ BeginPackage["sym`"]; EvolutionTimelevels, UseCSE, -PartialDerivatives, InheritedImplementations, ConditionalOnKeyword, ConditionalOnKeywords, ReflectionSymmetries, ZeroDimensions, CollectList, Interior, Boundary, BoundaryWithGhosts, Where, PreDefinitions, AllowedSymbols, UseLoopControl}; +PartialDerivatives, InheritedImplementations, ConditionalOnKeyword, ConditionalOnKeywords, ReflectionSymmetries, ZeroDimensions, CollectList, Interior, InteriorNoSync, Boundary, BoundaryWithGhosts, Where, PreDefinitions, AllowedSymbols, UseLoopControl}; EndPackage[]; -- cgit v1.2.3