diff options
Diffstat (limited to 'Tools/CodeGen/Thorn.m')
-rw-r--r-- | Tools/CodeGen/Thorn.m | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/Tools/CodeGen/Thorn.m b/Tools/CodeGen/Thorn.m index 06b3e8d..9381948 100644 --- a/Tools/CodeGen/Thorn.m +++ b/Tools/CodeGen/Thorn.m @@ -220,7 +220,8 @@ Options[CreateConfiguration] = ThornOptions; CreateConfiguration[opts:OptionsPattern[]] := {whoWhen["CCL"], "REQUIRES GenericFD\n", - If[OptionValue[UseLoopControl], "REQUIRES LoopControl\n", {}] + If[OptionValue[UseLoopControl], "REQUIRES LoopControl\n", {}], + If[OptionValue[UseVectors], "REQUIRES Vectors\n", {}] }; (* ------------------------------------------------------------------------ @@ -473,14 +474,19 @@ CreateSchedule[globalStorageGroups_, scheduledGroups_, scheduledFunctions_] := optional LoopPreIncludes -> {include file list}, Equations -> {{K11_rhs -> 2 A K11, ...}...}} *) -calculationMacros[] := +calculationMacros[vectorise_] := CommentedBlock["Define macros used in calculations", - Map[{"#define ", #, "\n"} &, - {"INITVALUE (42)", - "INV(x) ((1.0) / (x))" , - "SQR(x) ((x) * (x))" , - "CUB(x) ((x) * (x) * (x))" , - "QAD(x) ((x) * (x) * (x) * (x))"}]]; + Map[{"#define ", #, "\n"} &, + {"INITVALUE (42)", + "QAD(x) (SQR(SQR(x)))"} ~Join~ + If[vectorise, + {"INV(x) (kdiv(ToReal(1.0),x))", + "SQR(x) (kmul(x,x))", + "CUB(x) (kmul(x,SQR(x)))"}, + {"INV(x) ((1.0) / (x))", + "SQR(x) ((x) * (x))", + "CUB(x) ((x) * (x) * (x))"}] + ]]; (* Given a list of Calculation structures as defined above, create a CodeGen representation of a source file that defines a function for @@ -488,7 +494,7 @@ calculationMacros[] := Options[CreateSetterSource] = ThornOptions; -CreateSetterSource[calcs_, debug_, useCSE_, include_, imp_, +CreateSetterSource[calcs_, debug_, include_, imp_, opts:OptionsPattern[]] := Module[{}, @@ -503,21 +509,24 @@ CreateSetterSource[calcs_, debug_, useCSE_, include_, imp_, {IncludeSystemFile["assert.h"], IncludeSystemFile["math.h"], IncludeSystemFile["stdio.h"], - IncludeSystemFile["stdlib.h"]}, + IncludeSystemFile["stdlib.h"], + IncludeSystemFile["string.h"]}, {"\n"} ], Map[IncludeFile, Join[{"cctk.h", "cctk_Arguments.h", "cctk_Parameters.h", - (*"precomputations.h",*) "GenericFD.h", "Differencing.h"}, include, - If[OptionValue[UseLoopControl], {"loopcontrol.h"}, {}]]], - calculationMacros[], + (*"precomputations.h",*) "GenericFD.h", "Differencing.h"}, + include, + If[OptionValue[UseLoopControl], {"loopcontrol.h"}, {}], + If[OptionValue[UseVectors], {"vectors.h"}, {}]]], + calculationMacros[OptionValue[UseVectors]], (* For each function structure passed, create the function and insert it *) CalculationBoundariesFunction[First[calcs], imp], - Map[CreateCalculationFunction[# , debug, useCSE, opts] &, + Map[CreateCalculationFunction[# , debug, imp, opts] &, calcs]}]; @@ -749,10 +758,10 @@ CreateMoLBoundariesSource[spec_] := "if (CCTK_EQUALS(" <> boundpar <> ", \"none\" ) ||\n", " CCTK_EQUALS(" <> boundpar <> ", \"static\") ||\n", " CCTK_EQUALS(" <> boundpar <> ", \"flat\" ) ||\n", - " CCTK_EQUALS(" <> boundpar <> ", \"zero\" ) ) \n", + " CCTK_EQUALS(" <> boundpar <> ", \"zero\" ) )\n", "{\n", - " ierr = Boundary_SelectGroupForBC(cctkGH, CCTK_ALL_FACES, 1, -1, \n", + " ierr = Boundary_SelectGroupForBC(cctkGH, CCTK_ALL_FACES, 1, -1,\n", " \"" <> fullgroupname <> "\", " <> boundpar <> ");\n", " if (ierr < 0)\n", @@ -771,10 +780,10 @@ CreateMoLBoundariesSource[spec_] := "if (CCTK_EQUALS(" <> boundpar <> ", \"none\" ) ||\n", " CCTK_EQUALS(" <> boundpar <> ", \"static\") ||\n", " CCTK_EQUALS(" <> boundpar <> ", \"flat\" ) ||\n", - " CCTK_EQUALS(" <> boundpar <> ", \"zero\" ) ) \n", + " CCTK_EQUALS(" <> boundpar <> ", \"zero\" ) )\n", "{\n", - " ierr = Boundary_SelectVarForBC(cctkGH, CCTK_ALL_FACES, 1, -1, \n", + " ierr = Boundary_SelectVarForBC(cctkGH, CCTK_ALL_FACES, 1, -1,\n", " \"" <> fullgfname <> "\", " <> boundpar <> ");\n", " if (ierr < 0)\n", @@ -1178,7 +1187,7 @@ headerComment2, " assert (len);\n\n", " for (d = 0; d < 3; ++d) {\n", -" assert (off[d] >= 0 && len[d] >= 0 && off[d] + len[d] <= cctk_lssh[CCTK_LSSH_IDX(0,d)]);\n", +" assert (off[d] >= 0 && len[d] >= 0 && off[d] + len[d] <= CCTK_LSSH(0,d));\n", " }\n\n", " assert (modes);\n", @@ -1340,7 +1349,7 @@ CreateStartupFile[thornName_, bannerText_] := tmp = {whoWhen["C"], IncludeFile["cctk.h"], - DefineFunction[thornName <> "_Startup", "int", "void", + DefineFunction[thornName <> "_Startup", "extern \"C\" int", "void", {DefineVariable["banner", "const char *", Quote[bannerText]], "CCTK_RegisterBanner(banner);\n", "return 0;\n"}]}; @@ -1354,7 +1363,7 @@ CreateStartupFile[thornName_, bannerText_] := Thorn creation ------------------------------------------------------------------------ *) -(* source = {Filename -> "MoLRegister.c", Contents -> "#include ..."} *) +(* source = {Filename -> "MoLRegister.cc", Contents -> "#include ..."} *) (* thorn = {Name -> "ClassicADMMolEvolve", Directory -> "ClassicADM", Interface -> i, Schedule -> s, Param -> p, Makefile -> m, |