Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ianhinder/Kranc
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Brandt committed May 3, 2012
2 parents 3994aba + 56a871e commit 74dbb92
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 28 deletions.
10 changes: 0 additions & 10 deletions Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c
Expand Up @@ -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];
Expand Down
15 changes: 14 additions & 1 deletion Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h
Expand Up @@ -30,6 +30,8 @@

#include "cctk.h"

#include <math.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -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);

Expand Down
Expand Up @@ -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

Expand Down
24 changes: 17 additions & 7 deletions Tools/CodeGen/Calculation.m
Expand Up @@ -37,6 +37,7 @@
AddConditionSuffix;
InNewScheduleGroup;
BoundaryCalculationQ;
GetSchedule;

Begin["`Private`"];

Expand Down Expand Up @@ -161,7 +162,7 @@
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 *)
Expand Down Expand Up @@ -213,7 +214,7 @@
{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[
Expand Down Expand Up @@ -289,7 +290,7 @@
(* 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
Expand All @@ -301,8 +302,8 @@
(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];

Expand All @@ -314,21 +315,30 @@

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[
calc,
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[];
2 changes: 1 addition & 1 deletion Tools/CodeGen/CalculationFunction.m
Expand Up @@ -501,7 +501,7 @@ pathalogical enough (e.g. {s1 -> s2, s2 -> s1} would not be
"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",
Expand Down
2 changes: 1 addition & 1 deletion Tools/CodeGen/Kranc.m
Expand Up @@ -47,7 +47,7 @@
SeparatedDerivatives2}

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

Expand Down
8 changes: 4 additions & 4 deletions Tools/CodeGen/Schedule.m
Expand Up @@ -153,7 +153,7 @@
<> If[after =!= None, " after " <> after, ""];

applyBCs = lookupDefault[calc, ApplyBCs, False];
userSchedule = lookupDefault[calc, Schedule, Automatic];
userSchedule = GetSchedule[calc];


If[userSchedule =!= Automatic && !applyBCs,
Expand All @@ -179,7 +179,7 @@
{}],
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
Expand Down Expand Up @@ -213,8 +213,8 @@
SchedulePoint -> "in " <> groupName,
Language -> CodeGenC`SOURCELANGUAGE,
Tags -> tags,
RequiredGroups -> groupsToRequire,
ProvidedGroups -> groupsToProvide,
RequiredGroups -> variablesToRead,
ProvidedGroups -> variablesToWrite,
Comment -> lookup[calc, Name]
};

Expand Down
4 changes: 2 additions & 2 deletions Tools/CodeGen/ScriptOutput.m
Expand Up @@ -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;

Expand Down Expand Up @@ -120,7 +120,7 @@
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_] :=
Expand Down

0 comments on commit 74dbb92

Please sign in to comment.