aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c10
-rw-r--r--Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h15
-rw-r--r--Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/MathematicaCompat.h4
-rw-r--r--Tools/CodeGen/Calculation.m24
-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/ScriptOutput.m4
8 files changed, 41 insertions, 28 deletions
diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c
index 1bd1a61..023e6e8 100644
--- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c
+++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c
@@ -49,16 +49,6 @@
/* TODO: provide functions for differencing, use FD macros to evaluate
corresponding functions */
-int sgn(CCTK_REAL x)
-{
- if (x < 0)
- return -1;
- else if (x > 0)
- return 1;
- else
- return 0;
-}
-
void GenericFD_GetBoundaryWidths(cGH const * restrict const cctkGH, int nboundaryzones[6])
{
int is_internal[6];
diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h
index 53e8035..6e3ed2b 100644
--- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h
+++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h
@@ -30,6 +30,8 @@
#include "cctk.h"
+#include <math.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -54,7 +56,18 @@ extern "C" {
#define KRANC_GFOFFSET3D(var,i,j,k) \
(*(CCTK_REAL const*)&((char const*)(var))[cdi*(i)+cdj*(j)+cdk*(k)])
-int sgn(CCTK_REAL x);
+/* Implement the signum function, used for Mathematica's Sign function */
+
+#ifdef __CUDACC__
+#define KRANC_WHERE __device__
+#else
+#define KRANC_WHERE
+#endif
+
+KRANC_WHERE static inline CCTK_REAL sgn(CCTK_REAL x)
+{
+ return x==(CCTK_REAL)0.0 ? (CCTK_REAL)0.0 : copysign((CCTK_REAL)1.0, x);
+}
int GenericFD_GetBoundaryWidth(cGH const * restrict const cctkGH);
diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/MathematicaCompat.h b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/MathematicaCompat.h
index 252116c..28bcebc 100644
--- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/MathematicaCompat.h
+++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/MathematicaCompat.h
@@ -40,11 +40,11 @@
#define Csch(x) (1.0/sinh(x))
#define Coth(x) (1.0/tanh(x))
+#define Sign(x) (sgn(x))
+
#ifdef KRANC_C
-# define Sign(x) (copysign( (CCTK_REAL) 1.0,(CCTK_REAL) (x)))
# define ToReal(x) ((CCTK_REAL)(x))
#else
-# define Sign(x) (sgn(x))
# define ToReal(x) (real((x),kind(khalf)))
#endif
diff --git a/Tools/CodeGen/Calculation.m b/Tools/CodeGen/Calculation.m
index 55644ed..36c8059 100644
--- a/Tools/CodeGen/Calculation.m
+++ b/Tools/CodeGen/Calculation.m
@@ -37,6 +37,7 @@ AddCondition;
AddConditionSuffix;
InNewScheduleGroup;
BoundaryCalculationQ;
+GetSchedule;
Begin["`Private`"];
@@ -161,7 +162,7 @@ DefFn[
Module[
{splitBy = lookup[calc,SplitBy, {}],
oldName = lookup[calc,Name],
- oldSchedule = lookup[calc, Schedule, Automatic],
+ oldSchedule = GetSchedule[calc],
newGroup},
(* If there is nothing to split, return the calculation without any changes *)
@@ -213,7 +214,7 @@ separateDerivativesInCalculation[calc_] :=
{sepPat = lookup[calc, SeparatedDerivatives , None],
sepPat2 = lookup[calc, SeparatedDerivatives2, None]},
If[sepPat === None, {calc},
- If[lookupDefault[calc, Schedule, Automatic] === Automatic,
+ If[GetSchedule[calc] === Automatic,
ThrowError["Separating derivatives in an automatically scheduled function is not supported"]];
Module[
@@ -289,7 +290,7 @@ separateDerivativesInCalculation[calc_] :=
(* TODO: "after" modifiers currently don't work with
CaKernel *)
afterNames = StringJoin[Map[" after " <> # &, otherNames]];
- thisSchedule = lookup[theCalc, Schedule];
+ thisSchedule = GetSchedule[theCalc];
newSchedule = Map[# <> afterNames &, thisSchedule];
mapReplace[theCalc, Schedule, newSchedule]];
(* TODO: could instead enforce order only between those
@@ -301,8 +302,8 @@ separateDerivativesInCalculation[calc_] :=
(GetEquations[calc]/.replaceSymmetric/.replaceMixed) /.
Map[# -> derivGFName[#] &, Flatten[Join[sepDerivs,sepDerivs2],1]]];
- derivCalcs = Map[mapReplace[#, Schedule, Map[#<>" before "<>GetCalculationName[calc2] &, lookup[#,Schedule]]] &, derivCalcs ];
- derivCalcs2 = Map[mapReplace[#, Schedule, Map[#<>" before "<>GetCalculationName[calc2] &, lookup[#,Schedule]]] &, derivCalcs2];
+ derivCalcs = Map[mapReplace[#, Schedule, Map[#<>" before "<>GetCalculationName[calc2] &, GetSchedule[#]]] &, derivCalcs ];
+ derivCalcs2 = Map[mapReplace[#, Schedule, Map[#<>" before "<>GetCalculationName[calc2] &, GetSchedule[#]]] &, derivCalcs2];
calc2 = InNewScheduleGroup[lookup[calc,Name], calc2];
@@ -314,14 +315,14 @@ DefFn[
DefFn[
AddConditionSuffix[calc_List, condition_] :=
- mapReplaceAdd[calc, Schedule, Map[#<>" IF "<>condition &, lookup[calc,Schedule]]]];
+ mapReplaceAdd[calc, Schedule, Map[#<>" IF "<>condition &, GetSchedule[calc]]]];
InNewScheduleGroup[groupName_String, calc_List] :=
Module[
{newGroup},
newGroup = {Name -> groupName,
Language -> "None", (* groups do not have a language *)
- SchedulePoint -> lookup[calc,Schedule,Automatic],
+ SchedulePoint -> GetSchedule[calc],
Comment -> ""};
mapReplaceAdd[
mapReplaceAdd[
@@ -329,6 +330,15 @@ InNewScheduleGroup[groupName_String, calc_List] :=
Schedule, {"in "<>groupName}],
ScheduleGroups, Append[lookup[calc, ScheduleGroups, {}],newGroup]]];
+DefFn[
+ GetSchedule[calc_List] :=
+ Module[
+ {s = lookup[calc,Schedule,Automatic]},
+ If[s =!= Automatic && !ListQ[s],
+ ThrowError["Calculation "<>lookup[calc,Name]<>" has an invalid Schedule entry: ",
+ s]];
+ s]];
+
End[];
EndPackage[];
diff --git a/Tools/CodeGen/CalculationFunction.m b/Tools/CodeGen/CalculationFunction.m
index 6a19ab4..3612e58 100644
--- a/Tools/CodeGen/CalculationFunction.m
+++ b/Tools/CodeGen/CalculationFunction.m
@@ -501,7 +501,7 @@ DefFn[
"GenericFD_LoopOverInterior(cctkGH, " <> bodyFunctionName <> ");\n",
InteriorNoSync,
"GenericFD_LoopOverInterior(cctkGH, " <> bodyFunctionName <> ");\n",
- Boundary,
+ Boundary | BoundaryNoSync,
"GenericFD_LoopOverBoundary(cctkGH, " <> bodyFunctionName <> ");\n",
BoundaryWithGhosts,
"GenericFD_LoopOverBoundaryWithGhosts(cctkGH, " <> bodyFunctionName <> ");\n",
diff --git a/Tools/CodeGen/Kranc.m b/Tools/CodeGen/Kranc.m
index a94306f..e7bd118 100644
--- a/Tools/CodeGen/Kranc.m
+++ b/Tools/CodeGen/Kranc.m
@@ -47,7 +47,7 @@ MacroPointer, CachedVariables, SplitBy, SeparatedDerivatives,
SeparatedDerivatives2}
{ConditionalOnKeyword, ConditionalOnKeywords, CollectList, Interior,
-InteriorNoSync, Boundary, BoundaryWithGhosts, Where, PreDefinitions,
+InteriorNoSync, Boundary, BoundaryNoSync, BoundaryWithGhosts, Where, PreDefinitions,
AllowedSymbols, Parameters, ConditionalOnTextuals, ApplyBCs,
SimpleCode};
diff --git a/Tools/CodeGen/Schedule.m b/Tools/CodeGen/Schedule.m
index c8fac55..24b1802 100644
--- a/Tools/CodeGen/Schedule.m
+++ b/Tools/CodeGen/Schedule.m
@@ -153,7 +153,7 @@ scheduleCalc[calc_, groups_, thornName_, OptionsPattern[]] :=
<> If[after =!= None, " after " <> after, ""];
applyBCs = lookupDefault[calc, ApplyBCs, False];
- userSchedule = lookupDefault[calc, Schedule, Automatic];
+ userSchedule = GetSchedule[calc];
If[userSchedule =!= Automatic && !applyBCs,
@@ -179,7 +179,7 @@ scheduleCalc[calc_, groups_, thornName_, OptionsPattern[]] :=
{}],
If[mapContains[calc, Conditional], {NewConditional -> lookup[calc,Conditional]}, {}]
] &,
- lookup[calc, Schedule]]],
+ GetSchedule[calc]]],
(* Scheduling is automatic. For the moment, all automatically
scheduled functions are going to be performed in
@@ -213,8 +213,8 @@ scheduleCalc[calc_, groups_, thornName_, OptionsPattern[]] :=
SchedulePoint -> "in " <> groupName,
Language -> CodeGenC`SOURCELANGUAGE,
Tags -> tags,
- RequiredGroups -> groupsToRequire,
- ProvidedGroups -> groupsToProvide,
+ RequiredGroups -> variablesToRead,
+ ProvidedGroups -> variablesToWrite,
Comment -> lookup[calc, Name]
};
diff --git a/Tools/CodeGen/ScriptOutput.m b/Tools/CodeGen/ScriptOutput.m
index 9900647..64bc7ec 100644
--- a/Tools/CodeGen/ScriptOutput.m
+++ b/Tools/CodeGen/ScriptOutput.m
@@ -18,7 +18,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)
-BeginPackage["ScriptOutput`", {"Errors`", "Helpers`", "Kranc`", "CodeGen`", "MapLookup`", "TensorTools`", "KrancGroups`"}];
+BeginPackage["ScriptOutput`", {"Errors`", "Helpers`", "Kranc`", "CodeGen`", "MapLookup`", "TensorTools`", "KrancGroups`", "Calculation`"}];
WriteScript;
@@ -120,7 +120,7 @@ DefFn[
Indent -> True]]];
writeSchedule[calc_] :=
- If[lookup[calc,Schedule,Automatic] =!= Automatic, FlattenBlock@Riffle[{"scheduled \"", #, "\""}&/@ lookup[calc,Schedule,Automatic]," "],""];
+ If[GetSchedule[calc] =!= Automatic, FlattenBlock@Riffle[{"scheduled \"", #, "\""}&/@ GetSchedule[calc]," "],""];
DefFn[
writeDerivatives[pdefs_] :=