Skip to content

Commit

Permalink
- HPCOM-FMU-Support added
Browse files Browse the repository at this point in the history
- the HPCOM-ODE-System size is now checked against the number of sim code equations
- Cpp-Runtime does now create a valid modelDescription.xml
  • Loading branch information
Marcus Walther committed Jul 6, 2015
1 parent 6cd6458 commit 2980576
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 77 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -106,6 +106,7 @@ Compiler/Script/OpenModelicaScriptingAPIQt.h
Compiler/Template/AbsynDumpTpl.mo
Compiler/Template/CodegenAdevs.mo
Compiler/Template/CodegenC.mo
Compiler/Template/CodegenCFunctions.mo
Compiler/Template/CodegenC.mo.log
Compiler/Template/CodegenCSharp.mo
Compiler/Template/CodegenCpp.mo
Expand All @@ -116,6 +117,7 @@ Compiler/Template/CodegenFMU1.mo
Compiler/Template/CodegenFMU2.mo
Compiler/Template/CodegenFMUCommon.mo
Compiler/Template/CodegenFMUCpp.mo
Compiler/Template/CodegenFMUCppHpcom.mo
Compiler/Template/CodegenJS.mo
Compiler/Template/CodegenJava.mo
Compiler/Template/CodegenModelica.mo
Expand Down
12 changes: 10 additions & 2 deletions Compiler/SimCode/HpcOmSimCodeMain.mo
Expand Up @@ -378,7 +378,7 @@ algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_EXECSTAT_HPCOM_MODULES);
//HpcOmTaskGraph.printTaskGraphMeta(taskGraphDataScheduled);

checkOdeSystemSize(taskGraphDataOdeScheduled,odeEquations);
checkOdeSystemSize(taskGraphDataOdeScheduled,odeEquations,sccSimEqMapping);
SimCodeFunctionUtil.execStat("hpcom check ODE system size");

//Create Memory-Map and Sim-Code
Expand Down Expand Up @@ -1249,8 +1249,10 @@ Remark: this can occur when asserts are added to the ode-system.
author:marcusw"
input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
input list<list<SimCode.SimEqSystem>> iOdeEqs;
input array<list<Integer>> iSccSimEqMapping;
output Boolean oIsCorrect;
protected
Integer scc;
list<Integer> sccs;
Integer actualSizePre, actualSize;
Integer targetSize;
Expand All @@ -1261,12 +1263,18 @@ algorithm
if(intNe(actualSizePre, actualSize)) then
print("There are simCode-equations multiple times in the graph structure.\n");
end if;
actualSize := 0;
for scc in sccs loop
actualSize := actualSize + listLength(arrayGet(iSccSimEqMapping, scc));
end for;

targetSize := listLength(List.flatten(iOdeEqs));
oIsCorrect := intEq(targetSize,actualSize);
if(oIsCorrect) then
//print("the ODE-system size is correct("+intString(actualSize)+")\n");
else
print("the size should be "+intString(targetSize)+" but it is "+intString(actualSize)+"!\n");
print("the size of the ODE-system should be "+intString(targetSize)+" but it is "+intString(actualSize)+"!\n");
print("expected the following sim code equations: " + stringDelimitList(List.map(List.map(List.flatten(iOdeEqs), SimCodeUtil.simEqSystemIndex), intString), ",") + "\n");
print("the ODE-system is NOT correct\n");
end if;
end checkOdeSystemSize;
Expand Down
9 changes: 7 additions & 2 deletions Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -62,6 +62,7 @@ import CevalScriptBackend;
import CodegenC;
import CodegenFMU;
import CodegenFMUCpp;
import CodegenFMUCppHpcom;
import CodegenQSS;
import CodegenAdevs;
import CodegenSparseFMI;
Expand Down Expand Up @@ -142,7 +143,7 @@ algorithm
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs,libPaths,includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) :=
SimCodeUtil.createFunctions(p, dae, inBackendDAE, className);
(simCode,_) := SimCodeUtil.createSimCode(outIndexedBackendDAE,
simCode := createSimCode(outIndexedBackendDAE,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, libPaths,simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
SimCodeFunctionUtil.execStat("SimCode");
Expand Down Expand Up @@ -574,7 +575,11 @@ algorithm
then ();
case (_,"Cpp")
equation
Tpl.tplNoret3(CodegenFMUCpp.translateModel, simCode, FMUVersion, FMUType);
if(Flags.isSet(Flags.HPCOM)) then
Tpl.tplNoret3(CodegenFMUCppHpcom.translateModel, simCode, FMUVersion, FMUType);
else
Tpl.tplNoret3(CodegenFMUCpp.translateModel, simCode, FMUVersion, FMUType);
end if;
then ();
else
equation
Expand Down
47 changes: 43 additions & 4 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -10052,20 +10052,44 @@ algorithm
end getVarToArrayIndexByType;

public function getVarIndexListByMapping "author: marcusw
Return the variable indices stored for the given variable in the mapping-table. If the variable is part of an array, all array indices are returned. This function is used by susan."
input HashTableCrIListArray.HashTable iVarToArrayIndexMapping;
input DAE.ComponentRef iVarName;
input String iIndexForUndefinedReferences;
output list<String> oVarIndexList; //if the variable is part of an array, all array indices are returned in this list (the list contains one element if the variable is a scalar)
algorithm
((oVarIndexList,_)) := getVarIndexInfosByMapping(iVarToArrayIndexMapping, iVarName, iIndexForUndefinedReferences);
end getVarIndexListByMapping;

public function getVarIndexByMapping "author: marcusw
Return the variable index stored for the given variable in the mapping-table. This function is used by susan."
input HashTableCrIListArray.HashTable iVarToArrayIndexMapping;
input DAE.ComponentRef iVarName;
input String iIndexForUndefinedReferences;
output String oConcreteVarIndex; //the scalar index of the variable (this value is always part of oVarIndexList)
algorithm
((_,oConcreteVarIndex)) := getVarIndexInfosByMapping(iVarToArrayIndexMapping, iVarName, iIndexForUndefinedReferences);
end getVarIndexByMapping;

protected function getVarIndexInfosByMapping "author: marcusw
Return the variable indices stored for the given variable in the mapping-table. This function is used by susan."
input HashTableCrIListArray.HashTable iVarToArrayIndexMapping;
input DAE.ComponentRef iVarName;
input String iIndexForUndefinedReferences;
output list<String> oVarIndexList;
output list<String> oVarIndexList; //if the variable is part of an array, all array indices are returned in this list (the list contains one element if the variable is a scalar)
output String oConcreteVarIndex; //the scalar index of the variable (this value is always part of oVarIndexList)
protected
DAE.ComponentRef varName = iVarName;
Integer arrayIdx, idx, arraySize;
Integer arrayIdx, idx, arraySize, concreteVarIndex;
array<Integer> varIndices;
list<String> tmpVarIndexListNew = {};
list<DAE.Subscript> arraySubscripts;
list<Integer> arrayDimensions;
algorithm
arraySubscripts := ComponentReference.crefLastSubs(varName);
varName := ComponentReference.crefStripLastSubs(varName);//removeSubscripts(varName);
if(BaseHashTable.hasKey(varName, iVarToArrayIndexMapping)) then
((_,varIndices)) := BaseHashTable.get(varName, iVarToArrayIndexMapping);
((arrayDimensions,varIndices)) := BaseHashTable.get(varName, iVarToArrayIndexMapping);
arraySize := arrayLength(varIndices);
for arrayIdx in 0:(arraySize-1) loop
idx := arrayGet(varIndices, arraySize-arrayIdx);
Expand All @@ -10080,13 +10104,28 @@ algorithm
end if;
end if;
end for;
((concreteVarIndex,_,_)) := List.fold(listReverse(arraySubscripts), getUnrolledArrayIndex, (0, 1, listReverse(arrayDimensions)));

// ignore all values that are undefined references and part of the same array
idx := 1;
while intLe (idx, concreteVarIndex) loop
if(intLt(arrayGet(varIndices, idx), 1)) then
concreteVarIndex := concreteVarIndex - 1;
end if;
idx := idx + 1;
end while;

concreteVarIndex := intAbs(arrayGet(varIndices, 1)) - 1 + concreteVarIndex;
oConcreteVarIndex := intString(concreteVarIndex);
end if;
if(listEmpty(tmpVarIndexListNew)) then
Error.addMessage(Error.INTERNAL_ERROR, {"GetVarIndexListByMapping: No Element for " + ComponentReference.printComponentRefStr(varName) + " found!"});
tmpVarIndexListNew := {iIndexForUndefinedReferences};
oConcreteVarIndex := iIndexForUndefinedReferences;
end if;
//print("SimCodeUtil.getVarIndexInfosByMapping: Variable " + ComponentReference.printComponentRefStr(iVarName) + " has variable indices {" + stringDelimitList(tmpVarIndexListNew, ",") + "} and concrete index " + oConcreteVarIndex + "\n");
oVarIndexList := tmpVarIndexListNew;
end getVarIndexListByMapping;
end getVarIndexInfosByMapping;

public function isVarIndexListConsecutive "author: marcusw
Check if all variable indices of the given variables, stored in the hash table, are consecutive."
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Template/CodegenCpp.tpl
Expand Up @@ -58,7 +58,7 @@ template translateModel(SimCode simCode)
let()= textFile(simulationWriteOutputParameterCppFile(simCode , &extraFuncs , &extraFuncsDecl, "", false),'OMCpp<%fileNamePrefix%>WriteOutputParameter.cpp')
let()= textFile(simulationWriteOutputAliasVarsCppFile(simCode , &extraFuncs , &extraFuncsDecl, "", stateDerVectorName, false),'OMCpp<%fileNamePrefix%>WriteOutputAliasVars.cpp')
let()= textFile(simulationFactoryFile(simCode , &extraFuncs , &extraFuncsDecl, ""),'OMCpp<%fileNamePrefix%>FactoryExport.cpp')
let()= textFile(modelInitXMLFile(simCode, numRealVars, numIntVars, numBoolVars),'OMCpp<%fileNamePrefix%>Init.xml')
//let()= textFile(modelInitXMLFile(simCode, numRealVars, numIntVars, numBoolVars),'OMCpp<%fileNamePrefix%>Init.xml')
let()= textFile(simulationMainRunScript(simCode , &extraFuncs , &extraFuncsDecl, "", "", "", "exec"), '<%fileNamePrefix%><%simulationMainRunScriptSuffix(simCode , &extraFuncs , &extraFuncsDecl, "")%>')
let jac = (jacobianMatrixes |> (mat, _, _, _, _, _, _) =>
(mat |> (eqs,_,_) => algloopfiles(eqs,simCode , &extraFuncs , &extraFuncsDecl, "",contextAlgloopJacobian, stateDerVectorName, false) ;separator="")
Expand Down
67 changes: 33 additions & 34 deletions Compiler/Template/CodegenCppHpcom.tpl
Expand Up @@ -25,28 +25,28 @@ template translateModel(SimCode simCode)
let useMemoryOptimization = Flags.isSet(Flags.HPCOM_MEMORY_OPT)

let className = lastIdentOfPath(modelInfo.name)
let numRealVars = numRealvars(modelInfo, hpcomData.hpcOmMemory)
let numIntVars = numIntvars(modelInfo, hpcomData.hpcOmMemory)
let numBoolVars = numBoolvars(modelInfo, hpcomData.hpcOmMemory)
let numPreVars = getPreVarsCount(modelInfo, hpcomData.hpcOmMemory)
let numRealVars = numRealvarsHpcom(modelInfo, hpcomData.hpcOmMemory)
let numIntVars = numIntvarsHpcom(modelInfo, hpcomData.hpcOmMemory)
let numBoolVars = numBoolvarsHpcom(modelInfo, hpcomData.hpcOmMemory)
let numPreVars = numPreVarsHpcom(modelInfo, hpcomData.hpcOmMemory)

let() = textFile(simulationMainFile(target, simCode, &extraFuncs, &extraFuncsDecl, "",
(if Flags.isSet(USEMPI) then "#include <mpi.h>" else ""),
(if Flags.isSet(USEMPI) then mpiInit() else ""),
(if Flags.isSet(USEMPI) then mpiFinalize() else ""),
numRealVars, numIntVars, numBoolVars, numPreVars),
'OMCpp<%fileNamePrefix%>Main.cpp')
let() = textFile(simulationCppFile(simCode, contextOther, update(allEquations, whenClauses, simCode, &extraFuncs, &extraFuncsDecl, "", contextOther, stateDerVectorName, false),
let() = textFile(simulationCppFile(simCode, contextOther, updateHpcom(allEquations, whenClauses, simCode, &extraFuncs, &extraFuncsDecl, "", contextOther, stateDerVectorName, false),
'<%numRealVars%>-1', '<%numIntVars%>-1', '<%numBoolVars%>-1', &extraFuncs, &extraFuncsDecl, className,
generateAdditionalConstructorDefinitions(hpcomData.schedules),
generateAdditionalConstructorBodyStatements(hpcomData.schedules, className, dotPath(modelInfo.name)),
generateAdditionalDestructorBodyStatements(hpcomData.schedules),
additionalHpcomConstructorDefinitions(hpcomData.schedules),
additionalHpcomConstructorBodyStatements(hpcomData.schedules, className, dotPath(modelInfo.name)),
additionalHpcomDestructorBodyStatements(hpcomData.schedules),
stateDerVectorName, false), 'OMCpp<%fileNamePrefix%>.cpp')

let() = textFile(simulationHeaderFile(simCode ,contextOther, &extraFuncs, &extraFuncsDecl, "",
generateAdditionalIncludes(simCode, &extraFuncs, &extraFuncsDecl, className, false),
additionalHpcomIncludes(simCode, &extraFuncs, &extraFuncsDecl, className, false),
"",
generateAdditionalProtectedMemberDeclaration(simCode, &extraFuncs, &extraFuncsDecl, "", false),
additionalHpcomProtectedMemberDeclaration(simCode, &extraFuncs, &extraFuncsDecl, "", false),
memberVariableDefine(modelInfo, varToArrayIndexMapping, '<%numRealVars%>-1', '<%numIntVars%>-1', '<%numBoolVars%>-1', Flags.isSet(Flags.GEN_DEBUG_SYMBOLS), false),
memberVariableDefinePreVariables(modelInfo, varToArrayIndexMapping, '<%numRealVars%>-1', '<%numIntVars%>-1', '<%numBoolVars%>-1', Flags.isSet(Flags.GEN_DEBUG_SYMBOLS), false), false),
//CodegenCpp.MemberVariablePreVariables(modelInfo,false), false),
Expand Down Expand Up @@ -93,18 +93,18 @@ template translateModel(SimCode simCode)
end translateModel;

// HEADER
template generateAdditionalIncludes(SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Boolean useFlatArrayNotation)
template additionalHpcomIncludes(SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Boolean useFlatArrayNotation)
"Generates code for header file for simulation target."
::=
match simCode
case SIMCODE(__) then
<<
<%generateAdditionalIncludesForParallelCode(simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace)%>
<%additionalHpcomIncludesForParallelCode(simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace)%>
>>
end match
end generateAdditionalIncludes;
end additionalHpcomIncludes;

template generateAdditionalIncludesForParallelCode(SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace)
template additionalHpcomIncludesForParallelCode(SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace)
::=
let type = getConfigString(HPCOM_CODE)
match type
Expand Down Expand Up @@ -139,9 +139,9 @@ template generateAdditionalIncludesForParallelCode(SimCode simCode, Text& extraF
#include <boost/thread.hpp>
>>
end match
end generateAdditionalIncludesForParallelCode;
end additionalHpcomIncludesForParallelCode;

template generateAdditionalProtectedMemberDeclaration(SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Boolean useFlatArrayNotation)
template additionalHpcomProtectedMemberDeclaration(SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Boolean useFlatArrayNotation)
"Generates class declarations."
::=
match simCode
Expand Down Expand Up @@ -196,7 +196,7 @@ template generateAdditionalProtectedMemberDeclaration(SimCode simCode, Text& ext
>>%>
>>
end match
end generateAdditionalProtectedMemberDeclaration;
end additionalHpcomProtectedMemberDeclaration;

template generateAdditionalStructHeaders(Schedule odeSchedule)
::=
Expand Down Expand Up @@ -407,7 +407,7 @@ template generateThreadFunctionHeaderDecl(Integer threadIdx)
>>
end generateThreadFunctionHeaderDecl;

template generateAdditionalConstructorDefinitions(Option<tuple<Schedule,Schedule,Schedule>> scheduleOpt)
template additionalHpcomConstructorDefinitions(Option<tuple<Schedule,Schedule,Schedule>> scheduleOpt)
::=
let type = getConfigString(HPCOM_CODE)
match scheduleOpt
Expand Down Expand Up @@ -435,9 +435,9 @@ template generateAdditionalConstructorDefinitions(Option<tuple<Schedule,Schedule
end match
else ""
end match
end generateAdditionalConstructorDefinitions;
end additionalHpcomConstructorDefinitions;

template generateAdditionalConstructorBodyStatements(Option<tuple<Schedule,Schedule,Schedule>> schedulesOpt, String modelNamePrefixStr, String fullModelName)
template additionalHpcomConstructorBodyStatements(Option<tuple<Schedule,Schedule,Schedule>> schedulesOpt, String modelNamePrefixStr, String fullModelName)
::=
let type = getConfigString(HPCOM_CODE)
match schedulesOpt
Expand Down Expand Up @@ -524,7 +524,7 @@ template generateAdditionalConstructorBodyStatements(Option<tuple<Schedule,Sched
else ""
else ""
end match
end generateAdditionalConstructorBodyStatements;
end additionalHpcomConstructorBodyStatements;

template generateThreadMeasureTimeDeclaration(String fullModelName, Integer numberOfThreads)
::=
Expand Down Expand Up @@ -632,7 +632,7 @@ match(iType)
>>
end destroyArrayLocks;

template generateAdditionalDestructorBodyStatements(Option<tuple<Schedule,Schedule,Schedule>> schedulesOpt)
template additionalHpcomDestructorBodyStatements(Option<tuple<Schedule,Schedule,Schedule>> schedulesOpt)
::=
let type = getConfigString(HPCOM_CODE)
match schedulesOpt
Expand Down Expand Up @@ -694,10 +694,9 @@ template generateAdditionalDestructorBodyStatements(Option<tuple<Schedule,Schedu
else ""
else ""
end match
end generateAdditionalDestructorBodyStatements;
end additionalHpcomDestructorBodyStatements;


template update(list<SimEqSystem> allEquationsPlusWhen, list<SimWhenClause> whenClauses, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Context context, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation)
template updateHpcom(list<SimEqSystem> allEquationsPlusWhen, list<SimWhenClause> whenClauses, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Context context, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation)
::=
let &varDecls = buffer "" /*BUFD*/

Expand All @@ -716,7 +715,7 @@ template update(list<SimEqSystem> allEquationsPlusWhen, list<SimWhenClause> when
<%parCode%>
>>
end match
end update;
end updateHpcom;

template generateParallelEvaluate(list<SimEqSystem> allEquationsPlusWhen, Absyn.Path name,
list<SimWhenClause> whenClauses, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Option<tuple<Schedule, Schedule, Schedule>> schedulesOpt, Context context, Text stateDerVectorName /*=__zDot*/,
Expand Down Expand Up @@ -1880,41 +1879,41 @@ template simulationMakefile(String target, SimCode simCode, Text& extraFuncs, Te
additionalLinkerFlags_MSVC, Flags.isSet(Flags.USEMPI))
end simulationMakefile;
template getPreVarsCount(ModelInfo modelInfo, Option<MemoryMap> hpcOmMemoryOpt)
template numPreVarsHpcom(ModelInfo modelInfo, Option<MemoryMap> hpcOmMemoryOpt)
::=
match(hpcOmMemoryOpt)
case(SOME(hpcomMemory as MEMORYMAP_ARRAY(floatArraySize=floatArraySize,intArraySize=intArraySize,boolArraySize=boolArraySize))) then
'<%floatArraySize%> + <%intArraySize%> + <%boolArraySize%>'
else
CodegenCpp.getPreVarsCount(modelInfo)
end getPreVarsCount;
end numPreVarsHpcom;
template numRealvars(ModelInfo modelInfo, Option<MemoryMap> hpcOmMemoryOpt)
template numRealvarsHpcom(ModelInfo modelInfo, Option<MemoryMap> hpcOmMemoryOpt)
::=
match(hpcOmMemoryOpt)
case(SOME(hpcomMemory as MEMORYMAP_ARRAY(floatArraySize=floatArraySize))) then
'<%floatArraySize%>'
else
'<%CodegenCpp.numRealvars(modelInfo)%>'
end numRealvars;
end numRealvarsHpcom;
template numIntvars(ModelInfo modelInfo, Option<MemoryMap> hpcOmMemoryOpt)
template numIntvarsHpcom(ModelInfo modelInfo, Option<MemoryMap> hpcOmMemoryOpt)
::=
match(hpcOmMemoryOpt)
case(SOME(hpcomMemory as MEMORYMAP_ARRAY(intArraySize=intArraySize))) then
'<%intArraySize%>'
else
CodegenCpp.numIntvars(modelInfo)
end numIntvars;
end numIntvarsHpcom;
template numBoolvars(ModelInfo modelInfo, Option<MemoryMap> hpcOmMemoryOpt)
template numBoolvarsHpcom(ModelInfo modelInfo, Option<MemoryMap> hpcOmMemoryOpt)
::=
match(hpcOmMemoryOpt)
case(SOME(hpcomMemory as MEMORYMAP_ARRAY(boolArraySize=boolArraySize))) then
'<%boolArraySize%>'
else
CodegenCpp.numBoolvars(modelInfo)
end numBoolvars;
end numBoolvarsHpcom;
annotation(__OpenModelica_Interface="backend");
end CodegenCppHpcom;

0 comments on commit 2980576

Please sign in to comment.