From 9bc08badd6aa151ce54b3e869b56ec0cf6e12e96 Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Sat, 2 Feb 2008 15:53:29 -0500 Subject: Erik: added mandatory support for LoopControl. A subsequent patch will make this optional. --- Tools/CodeGen/CalculationFunction.m | 4 +-- Tools/CodeGen/CodeGen.m | 71 +++++++++++++++++++++++++++++++++++++ Tools/CodeGen/KrancThorn.m | 41 ++++++++++++++------- Tools/CodeGen/Thorn.m | 25 +++++++++---- 4 files changed, 120 insertions(+), 21 deletions(-) (limited to 'Tools/CodeGen') diff --git a/Tools/CodeGen/CalculationFunction.m b/Tools/CodeGen/CalculationFunction.m index f523daf..c8af34b 100644 --- a/Tools/CodeGen/CalculationFunction.m +++ b/Tools/CodeGen/CalculationFunction.m @@ -493,7 +493,7 @@ CreateCalculationFunction[calc_, debug_] := { "DECLARE_CCTK_ARGUMENTS\n", "DECLARE_CCTK_PARAMETERS\n\n", - DeclareGridLoopVariables[], + (* DeclareGridLoopVariables[], *) DeclareFDVariables[], (* declareVariablesForCalculation[cleancalc], *) (* declarePrecomputedDerivatives[dsUsed], *) @@ -682,7 +682,7 @@ equationLoop[eqs_, code = {(*InitialiseGridLoopVariables[derivSwitch, addToStencilWidth], *) functionName = ToString@lookup[cleancalc, Name]; - GenericGridLoop[ + GenericGridLoop[functionName, {declareVariablesForCalculation[cleancalc], declarePrecomputedDerivatives[dsUsed], DeclareDerivatives[pddefs, eqs], diff --git a/Tools/CodeGen/CodeGen.m b/Tools/CodeGen/CodeGen.m index 5bdcf1c..3166d97 100644 --- a/Tools/CodeGen/CodeGen.m +++ b/Tools/CodeGen/CodeGen.m @@ -69,8 +69,10 @@ DefineCCTKSubroutine::usage = "DefineCCTKSubroutine[name, block] returns a block "of code that defines a CCTK Fortran subroutine of name 'name' with body 'block'."; GridName::usage = "GridName[variable] returns the name needed to access variable " <> "assuming it is a grid variable when inside a grid loop."; +(* DeclareGridLoopVariables::usage = "DeclareGridLoopVariables[] returns a block " <> "that defines the variables needed during a grid loop."; +*) InitialiseGridLoopVariables::usage = "InitialiseGridLoopVariables[] returns a block " <> "that initialises variables needed by a grid loop."; InitialiseGridLoopVariablesWithStencil::usage = "InitialiseGridLoopVariables[] returns a block " <> @@ -78,9 +80,14 @@ InitialiseGridLoopVariablesWithStencil::usage = "InitialiseGridLoopVariables[] r ConditionalOnParameter::usage = "ConditionalOnParameter[name, value, block] returns " <> "a block that introduces a conditional expression whereby 'block' is only executed " <> "if the Cactus parameter 'name' has value 'value'."; +(* GridLoop::usage = "GridLoop[block] returns a block that is looped over for every " <> "grid point. Must have previously set up the grid loop variables (see " <> "DeclareGridLoopVariables and InitialiseGridLoopVariables."; +*) +GridLoop::usage = "GridLoop[block] returns a block that is looped over for every " <> + "grid point. Must have previously set up the grid loop variables (see " <> + "InitialiseGridLoopVariables."; SubblockGridName::usage = "" DeclareArray::usage = ""; @@ -399,6 +406,7 @@ SubblockGridName[x_] := If[SOURCELANGUAGE == "C", ToString[x] <> "(i,j,k)" ]; +(* DeclareGridLoopVariables[] := SeparatedBlock[ {insertComment["Declare the variables used for looping over grid points"], @@ -412,6 +420,8 @@ DeclareGridLoopVariables[] := If[SOURCELANGUAGE == "C", DeclareVariable["index", "CCTK_INT"], "\n"], If[SOURCELANGUAGE == "C", DeclareVariable["subblock_index", "CCTK_INT"], "\n"] }]; +*) + (* Access an element of an array; syntax is different between C and Fortran. Always give this function a C-style array index. *) @@ -477,6 +487,7 @@ ConditionalOnParameterTextual[text_, block_] := indentBlock[block], "}\n"}]; +(* GridLoop[block_] := CommentedBlock["Loop over the grid points", loopOverInteger["k", "kstart", "kend", @@ -505,6 +516,66 @@ GenericGridLoop[block_] := block } ]]]]; +*) + +(* +GridLoop[block_] := + If[SOURCELANGUAGE == "C", + CommentedBlock["Loop over the grid points", + { + "_Pragma (\"omp parallel\")\n", + "LC_LOOP3 (unnamed,\n", + " i,j,k, istart,jstart,kstart, iend,jend,kend,\n", + " cctk_lsh[0],cctk_lsh[1],cctk_lsh[2])\n", + "{\n", + indentBlock[ + { + DeclareVariable["index", "int"], + AssignVariable["index", "CCTK_GFINDEX3D(cctkGH,i,j,k)"], + block + } + ], + "}\n", + "LC_ENDLOOP3 (unnamed);\n" + } + ], + CommentedBlock["Loop over the grid points", + { + "_Pragma (\"omp parallel\")\n", + "LC_LOOP3 (unnamed,\n", + " i,j,k, istart,jstart,kstart, iend,jend,kend,\n", + " cctk_lsh(1),cctk_lsh(2),cctk_lsh(3))\n", + indentBlock[block], + "LC_ENDLOOP3 (unnamed)\n" + } + ] + ]; +*) + +GenericGridLoop[functionName_, block_] := + If[SOURCELANGUAGE == "C", + CommentedBlock["Loop over the grid points", + { + "_Pragma (\"omp parallel\")\n", + "LC_LOOP3 (", functionName, ",\n", + " i,j,k, min[0],min[1],min[2], max[0],max[1],max[2],\n", + " cctk_lsh[0],cctk_lsh[1],cctk_lsh[2])\n", + "{\n", + indentBlock[ + { + DeclareVariable["index", "int"], + DeclareVariable["subblock_index", "int"], + AssignVariable["index", "CCTK_GFINDEX3D(cctkGH,i,j,k)"], + AssignVariable["subblock_index", "i - min[0] + (max[0] - min[0]) * (j - min[1] + (max[1]-min[1]) * (k - min[2]))"], + block + } + ], + "}\n", + "LC_ENDLOOP3 (", functionName, ");\n" + } + ], + "" + ]; switchOptions[{value_, block_}] := { diff --git a/Tools/CodeGen/KrancThorn.m b/Tools/CodeGen/KrancThorn.m index 230dc5b..e678470 100644 --- a/Tools/CodeGen/KrancThorn.m +++ b/Tools/CodeGen/KrancThorn.m @@ -101,12 +101,15 @@ replaceDots[x_] := CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts___] := Module[{calcs, declaredGroups, implementation, inheritedImplementations, includeFiles, evolutionTimelevels, - realParams, intParams, keywordParams, inheritedRealParams, inheritedIntParams, - inheritedKeywordParams, extendedRealParams, extendedIntParams, - extendedKeywordParams, partialDerivs, coordGroup, evolvedGroups, - nonevolvedGroups, interface, evolvedGroupDefinitions, - rhsGroupDefinitions, thornspec, allParams, boundarySources, - reflectionSymmetries, realParamDefs, intParamDefs, pDefs}, + realParams, intParams, keywordParams, + inheritedRealParams, inheritedIntParams, inheritedKeywordParams, + extendedRealParams, extendedIntParams, extendedKeywordParams, + configuration, + partialDerivs, coordGroup, evolvedGroups, nonevolvedGroups, + interface, evolvedGroupDefinitions, rhsGroupDefinitions, thornspec, + allParams, boundarySources, reflectionSymmetries, + realParamDefs, intParamDefs, + pDefs}, (* Return[];*) @@ -177,6 +180,10 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts___] := nonevolvedGroupsWithRHS = Join[nonevolvedGroups, Map[groupName, rhsGroupDefinitions]]; + (* Construct the configuration file *) + InfoMessage[Terse, "Creating configuration file"]; + configuration = createKrancConfiguration[]; + (* Construct the interface file *) InfoMessage[Terse, "Creating interface file"]; interface = createKrancInterface[nonevolvedGroupsWithRHS, @@ -240,13 +247,14 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts___] := Map[lookup[#, Filename] &, boundarySources]]]; (* Put all the above together and generate the Cactus thorn *) - thornspec = {Name -> thornName, - Directory -> parentDirectory, - Interface -> interface, - Schedule -> schedule, - Param -> param, - Makefile -> make, - Sources -> Join[{ + thornspec = {Name -> thornName, + Directory -> parentDirectory, + Configuration -> configuration, + Interface -> interface, + Schedule -> schedule, + Param -> param, + Makefile -> make, + Sources -> Join[{ {Filename -> "Startup.c", Contents -> startup}, {Filename -> "RegisterMoL.c", Contents -> molregister}, {Filename -> "RegisterSymmetries.c", Contents -> symregister}, @@ -326,6 +334,13 @@ nonevolvedTimelevels[group_] := If[ tls === False, 1, tls]]; +createKrancConfiguration[] := + Module[{configuration}, + configuration = CreateConfiguration[]; + Return[configuration]; + ]; + + createKrancInterface[nonevolvedGroups_, evolvedGroups_, groups_, evolutionTimelevels_, implementation_, inheritedImplementations_, includeFiles_] := diff --git a/Tools/CodeGen/Thorn.m b/Tools/CodeGen/Thorn.m index 04b9f35..6ef3683 100644 --- a/Tools/CodeGen/Thorn.m +++ b/Tools/CodeGen/Thorn.m @@ -36,7 +36,8 @@ SynchronizedGroups, StorageGroups, Timelevels, MaxTimelevels, VariableType, GridType, Visibility, Variables, Implementations, Value, AllowedValues, UsedParameters, Description, ExtendedParameters, NewParameters, -Directory, Interface, Param, Schedule, Sources, Makefile, Filename, +Directory, Configuration, Interface, Param, Schedule, Sources, Makefile, +Filename, Contents, ThornName, BaseImplementation, EvolvedGFs, PrimitiveGFs, Groups, Calculation, GridFunctions, Shorthands, Equations, Parameter, Value, UsesFunctions, ArgString, Conditional, D1, D2, D3, D11, D22, @@ -52,6 +53,7 @@ BeginPackage["Thorn`", "CodeGen`", "CalculationFunction`", "MapLookup`", "KrancG interface to this package. *) CreateSchedule::usage = "Create the content of the schedule.ccl file."; CreateMakefile::usage = "Create the content of the Cactus make.code.defn file."; +CreateConfiguration::usage = "Create the content of the configuration.ccl file."; CreateInterface::usage = "Create the content of the interface.ccl file."; CreateParam::usage = "Create the content of the param.ccl file."; Quote::usage = ""; (* This should not be in this package *) @@ -217,6 +219,15 @@ CreateParam[spec_] := output a parameter block for it *) Map[{lookup[#, Visibility], ":\n", parameterBlock[#]} &, lookupDefault[spec, NewParameters, {}]]}; + +(* ------------------------------------------------------------------------ + Configuration file + ------------------------------------------------------------------------ *) + +CreateConfiguration[] := + {whoWhen["CCL"], + "REQUIRES LoopControl\n" + }; (* ------------------------------------------------------------------------ Interface file @@ -303,7 +314,7 @@ CreateInterface[implementation_, inheritedImplementations_, includeFiles_, If[mapContains[{opts}, Friends], {"friend: ", SpaceSeparated[lookup[{opts}, Friends]]},{}], "\n\n", - Map[{"USES INCLUDE: ", #, "\n"} &, includeFiles], + Map[{"USES INCLUDE: ", #, "\n"} &, Join[includeFiles,{"loopcontrol.h"}]], "\n", Map[usesFunction, lookupDefault[{opts}, UsesFunctions, {}]], @@ -467,7 +478,8 @@ CreateSetterSource[calcs_, debug_, opts___] := ], Map[IncludeFile, Join[{"cctk.h", "cctk_Arguments.h", "cctk_Parameters.h", - (*"precomputations.h",*) "GenericFD.h", "Differencing.h"}, include]], + (*"precomputations.h",*) "GenericFD.h", "Differencing.h", + "loopcontrol.h"}, include]], calculationMacros[], (* For each function structure passed, create the function and @@ -1310,9 +1322,10 @@ CreateThorn[thorn_] := EnsureDirectory[thornDirectory]; EnsureDirectory[sourceDirectory]; - GenerateFile[thornDirectory <> "/interface.ccl", lookup[thorn, Interface]]; - GenerateFile[thornDirectory <> "/param.ccl", lookup[thorn, Param]]; - GenerateFile[thornDirectory <> "/schedule.ccl", lookup[thorn, Schedule]]; + GenerateFile[thornDirectory <> "/configuration.ccl", lookup[thorn, Configuration]]; + GenerateFile[thornDirectory <> "/interface.ccl", lookup[thorn, Interface]]; + GenerateFile[thornDirectory <> "/param.ccl", lookup[thorn, Param]]; + GenerateFile[thornDirectory <> "/schedule.ccl", lookup[thorn, Schedule]]; Map[GenerateFile[sourceDirectory <> "/" <> lookup[#, Filename], lookup[#, Contents]] &, -- cgit v1.2.3