aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Tools/CodeGen/CalculationFunction.m2
-rw-r--r--Tools/CodeGen/Kranc.m2
-rw-r--r--Tools/CodeGen/Schedule.m8
-rw-r--r--Tools/CodeGen/Thorn.m35
4 files changed, 31 insertions, 16 deletions
diff --git a/Tools/CodeGen/CalculationFunction.m b/Tools/CodeGen/CalculationFunction.m
index 13ceec3..136f15d 100644
--- a/Tools/CodeGen/CalculationFunction.m
+++ b/Tools/CodeGen/CalculationFunction.m
@@ -144,7 +144,7 @@ VerifyCalculation[calc_] :=
PartialDerivatives, PreDefinitions, Schedule,Equations,
Shorthands, ConditionalOnKeyword, Before, After,
ConditionalOnTextuals, Where, ConditionalOnKeywords,
- CollectList, AllowedSymbols, ApplyBCs};
+ CollectList, AllowedSymbols, ApplyBCs, Conditional};
usedKeys = Map[First, calc];
unknownKeys = Complement[usedKeys, allowedKeys];
diff --git a/Tools/CodeGen/Kranc.m b/Tools/CodeGen/Kranc.m
index 149f3c1..c61ee8e 100644
--- a/Tools/CodeGen/Kranc.m
+++ b/Tools/CodeGen/Kranc.m
@@ -107,7 +107,7 @@ Directory, Configuration, Interface, Param, Schedule, Sources, Makefile,
Filename,
Contents, ThornName, BaseImplementation, EvolvedGFs, EvolvedArrays, PrimitiveGFs,
Groups, Calculation, GridFunctions, Shorthands, Equations, Parameter,
-Value, UsesFunctions, ArgString, Conditional, Conditionals, D1, D2, D3, D11, D22,
+Value, UsesFunctions, ArgString, Conditional, Conditionals, NewConditional, D1, D2, D3, D11, D22,
D33, D21, D31, D32, Textual, TriggerGroups, Include, RHSGroups, Tags,
Steerable, Never, Always, Recover, Primitives, CaKernel};
diff --git a/Tools/CodeGen/Schedule.m b/Tools/CodeGen/Schedule.m
index b3a5868..aba7add 100644
--- a/Tools/CodeGen/Schedule.m
+++ b/Tools/CodeGen/Schedule.m
@@ -147,7 +147,8 @@ scheduleCalc[calc_, groups_, thornName_, OptionsPattern[]] :=
If[conditional, {Conditional -> {Parameter -> keyword, Value -> value}},
{}],
If[conditionals, {Conditionals -> keywordvaluepairs},
- {}]
+ {}],
+ If[mapContains[calc, Conditional], {NewConditional -> lookup[calc,Conditional]}, {}]
] &,
lookup[calc, Schedule]]],
@@ -221,7 +222,7 @@ scheduleCalc[calc_, groups_, thornName_, OptionsPattern[]] :=
Options[CreateKrancScheduleFile] = ThornOptions;
CreateKrancScheduleFile[calcs_, groups_, evolvedGroups_, rhsGroups_, nonevolvedGroups_, thornName_,
evolutionTimelevels_, opts:OptionsPattern[]] :=
- Module[{scheduledCalcs, scheduledStartup, scheduleMoLRegister, globalStorageGroups, scheduledFunctions, schedule},
+ Module[{scheduledCalcs, scheduledStartup, scheduleMoLRegister, globalStorageGroups, scheduledFunctions, schedule, allParams},
scheduledCalcs = Flatten[Map[scheduleCalc[#, groups, thornName, opts] &, calcs], 1];
scheduledStartup =
@@ -272,8 +273,9 @@ CreateKrancScheduleFile[calcs_, groups_, evolvedGroups_, rhsGroups_, nonevolvedG
If[OptionValue[UseCaKernel],
scheduledFunctions = Join[scheduledFunctions, CaKernelSchedule[]]];
+ allParams = Union@@((lookup[#,Parameters] &) /@ calcs);
schedule = CreateSchedule[globalStorageGroups,
- CactusBoundary`GetScheduledGroups[thornName], scheduledFunctions];
+ CactusBoundary`GetScheduledGroups[thornName], scheduledFunctions, allParams];
Return[schedule]];
diff --git a/Tools/CodeGen/Thorn.m b/Tools/CodeGen/Thorn.m
index 2cd9122..13f7932 100644
--- a/Tools/CodeGen/Thorn.m
+++ b/Tools/CodeGen/Thorn.m
@@ -363,7 +363,7 @@ CreateInterface[implementation_, inheritedImplementations_, includeFiles_,
(* Given a storage group structure defined above, return a CodeGen
structure for inclusion in the schedule.ccl file to allocate
storage for this group. *)
-groupStorage[spec_] :=
+groupStorage[spec_, params_] :=
If[mapContains[spec, MaxTimelevels],
Flatten[Table[{"if (", lookup[spec, MaxTimelevels], " == ", i, ")\n",
"{\n",
@@ -404,8 +404,8 @@ scheduleUnconditionalFunction[spec_] :=
Quote[lookup[spec, Comment]]]};
(* Handle the aspect of scheduling the function conditionally *)
-scheduleFunction[spec_] :=
- Module[{condition, conditions, parameter, value, u, v, w, x},
+scheduleFunction[spec_,params_] :=
+ Module[{condition, conditions, parameter, value, u, v, w, x, y},
u = scheduleUnconditionalFunction[spec];
@@ -452,25 +452,38 @@ scheduleFunction[spec_] :=
x]],
v, conditions],
v];
-
- w];
+
+ y = If[mapContains[spec, NewConditional],
+ cond = lookup[spec, NewConditional];
+ Module[
+ {render},
+ render[Equal[a_Symbol,b_String]] := {"CCTK_EQUALS(", render[a], ",", render[b],")"};
+ render[Equal[a_Symbol,b_?NumberQ]] := {"(", render[a], " == ", render[b],")"};
+ render[a_String] := a; (* Allow literal pass-through *)
+ render[a_?NumberQ] := ToString[a];
+ render[a_ /; MemberQ[params,a]] := ToString[a];
+ render[x_] := ThrowError["Unrecognized value in conditional expression:", x, "in", cond];
+ ConditionalOnParameterTextual[render[cond], w]],
+ w];
+
+ y];
(* Schedule a schedule group. Use a slightly dirty trick; given that
the structure is identical to that for a function except with the
word "GROUP" added before the function name, just use the existing
function. *)
-scheduleGroup[spec_] :=
- scheduleFunction[mapReplace[spec, Name, "group " <> lookup[spec, Name]]];
+scheduleGroup[spec_,params_] :=
+ scheduleFunction[mapReplace[spec, Name, "group " <> lookup[spec, Name]],params];
(* Taking a list of group storage specifications for global storage,
and lists of scheduled function and scheduled group structures,
return a CodeGen block representing a schedule.ccl file. *)
-CreateSchedule[globalStorageGroups_, scheduledGroups_, scheduledFunctions_] :=
+CreateSchedule[globalStorageGroups_, scheduledGroups_, scheduledFunctions_, params_] :=
{whoWhen["CCL"],
- Map[SeparatedBlock[groupStorage[#]] &, globalStorageGroups],
- Map[SeparatedBlock[scheduleFunction[#]] &, scheduledFunctions],
- Map[SeparatedBlock[scheduleGroup[#]] &, scheduledGroups]};
+ Map[SeparatedBlock[groupStorage[#,params]] &, globalStorageGroups],
+ Map[SeparatedBlock[scheduleFunction[#,params]] &, scheduledFunctions],
+ Map[SeparatedBlock[scheduleGroup[#,params]] &, scheduledGroups]};
(* ------------------------------------------------------------------------