diff --git a/Compiler/BackEnd/HpcOmMemory.mo b/Compiler/BackEnd/HpcOmMemory.mo index 12f6f00bb5a..d21f2a6c110 100644 --- a/Compiler/BackEnd/HpcOmMemory.mo +++ b/Compiler/BackEnd/HpcOmMemory.mo @@ -290,10 +290,10 @@ encapsulated package HpcOmMemory array> scheduleInfo; algorithm (oCacheMap,oScVarCLMapping,oNumCL) := match(iTaskGraph,iTaskGraphMeta,iAllSCVarsMapping,iSimCodeVarTypes,iScVarTaskMapping,iCacheLineSize,iAllComponents,iSchedule, iNumberOfThreads, iNodeSimCodeVarMapping) - case(_,_,_,_,_,_,_,HpcOmSimCode.LEVELSCHEDULE(tasksOfLevels=tasksOfLevels, useFixedAssignments=false),_,_) + /* case(_,_,_,_,_,_,_,HpcOmSimCode.LEVELSCHEDULE(tasksOfLevels=tasksOfLevels, useFixedAssignments=false),_,_) equation (cacheMap,scVarCLMapping,numCL) = createCacheMapLevelOptimized(iAllSCVarsMapping,iSimCodeVarTypes,iScVarTaskMapping,iCacheLineSize,iAllComponents,tasksOfLevels,iNodeSimCodeVarMapping); - then (cacheMap,scVarCLMapping,numCL); + then (cacheMap,scVarCLMapping,numCL); */ case(_,_,_,_,_,_,_,HpcOmSimCode.LEVELSCHEDULE(tasksOfLevels=tasksOfLevels, useFixedAssignments=true),_,_) equation print("Creating optimized cache map for fixed level scheduler\n"); diff --git a/Compiler/BackEnd/HpcOmScheduler.mo b/Compiler/BackEnd/HpcOmScheduler.mo index 58a32436b6d..1c0009610a9 100644 --- a/Compiler/BackEnd/HpcOmScheduler.mo +++ b/Compiler/BackEnd/HpcOmScheduler.mo @@ -2134,7 +2134,7 @@ algorithm (threadIdx, taskList) := iIdxTaskList; for taskIdx in iTaskList loop components := arrayGet(iComps, taskIdx); //Components of the task - print("createFixedLevelScheduleForLevel0: Handling task with idx: " + intString(taskIdx) + "\n"); + //print("createFixedLevelScheduleForLevel0: Handling task with idx: " + intString(taskIdx) + "\n"); simEqs := List.flatten(List.map(List.map1(components,Array.getIndexFirst,iSccSimEqMapping), listReverse)); if(intGt(listLength(simEqs), 0)) then simEqs := simEqs; diff --git a/Compiler/SimCode/SimCodeUtil.mo b/Compiler/SimCode/SimCodeUtil.mo index 0ee48fabce6..15a34db3629 100644 --- a/Compiler/SimCode/SimCodeUtil.mo +++ b/Compiler/SimCode/SimCodeUtil.mo @@ -13467,6 +13467,95 @@ algorithm simEqSysIdcs := List.map(remEqs,eqIndex); end getRemovedEquationSimEqSysIdxes; +public function getDaeEqsNotPartOfOdeSystem "Get a list of eqSystem-objects that are solved in DAE, but not in the ODE-system. +author: marcusw" + input SimCode.SimCode iSimCode; + output list oEqs; +protected + array> allEqs; + list> allEqIdxMapping; //mapping SimEqIdx -> SimEqSystem + list allEquations; + list> odeEquations; + Integer highestIdx; + list tmpEqs; +algorithm + SimCode.SIMCODE(allEquations=allEquations,odeEquations=odeEquations) := iSimCode; + ((allEqIdxMapping, highestIdx)) := List.fold(allEquations, getDaeEqsNotPartOfOdeSystem0, ({}, 0)); + allEqs := arrayCreate(highestIdx, NONE()); + allEqs := List.fold(allEqIdxMapping, getDaeEqsNotPartOfOdeSystem1, allEqs); + allEqs := List.fold(odeEquations, getDaeEqsNotPartOfOdeSystem2, allEqs); + tmpEqs := {}; + tmpEqs := Array.fold(allEqs, getDaeEqsNotPartOfOdeSystem4, tmpEqs); + oEqs := listReverse(tmpEqs); +end getDaeEqsNotPartOfOdeSystem; + +protected function getDaeEqsNotPartOfOdeSystem0 "Add the given equation system object to the mapping list (simEqIdx -> SimEqSystem). +author: marcusw" + input SimCode.SimEqSystem iEqSystem; + input tuple>, Integer> iMappingWithHighestIdx; // SimEqSystem, highestIdx> + output tuple>, Integer> oMappingWithHighestIdx; +protected + Integer index, highestIdx; + list> allEqIdxMapping; +algorithm + index := equationIndex(iEqSystem); + (allEqIdxMapping, highestIdx) := iMappingWithHighestIdx; + allEqIdxMapping := (index, iEqSystem)::allEqIdxMapping; + highestIdx := intMax(highestIdx, index); + oMappingWithHighestIdx := (allEqIdxMapping, highestIdx); +end getDaeEqsNotPartOfOdeSystem0; + +protected function getDaeEqsNotPartOfOdeSystem1 "Set the array at position simEqIdx to the simEqSystem-object. +author: marcusw" + input tuple iEqSystem; // + input array> iEqArray; + output array> oEqArray; +protected + Integer eqSysIdx; + SimCode.SimEqSystem eqSys; +algorithm + (eqSysIdx, eqSys) := iEqSystem; + oEqArray := arrayUpdate(iEqArray, eqSysIdx, SOME(eqSys)); +end getDaeEqsNotPartOfOdeSystem1; + +protected function getDaeEqsNotPartOfOdeSystem2 "Set the array at position simEqIdx to NONE(). +author: marcusw" + input list iEqSystem; + input array> iEqArray; + output array> oEqArray; +algorithm + oEqArray := List.fold(iEqSystem, getDaeEqsNotPartOfOdeSystem3, iEqArray); +end getDaeEqsNotPartOfOdeSystem2; + +protected function getDaeEqsNotPartOfOdeSystem3 "Set the array at position simEqIdx to NONE(). +author: marcusw" + input SimCode.SimEqSystem iEqSystem; + input array> iEqArray; + output array> oEqArray; +protected + Integer eqSysIdx; + SimCode.SimEqSystem eqSys; +algorithm + eqSysIdx := equationIndex(iEqSystem); + oEqArray := arrayUpdate(iEqArray, eqSysIdx, NONE()); +end getDaeEqsNotPartOfOdeSystem3; + +protected function getDaeEqsNotPartOfOdeSystem4 "Append the element to the list if it is not NONE(). +author: marcusw" + input Option iEqSystemOpt; + input list iResList; + output list oResList; +protected + SimCode.SimEqSystem eqSys; +algorithm + oResList := match(iEqSystemOpt, iResList) + case(SOME(eqSys), _) + then eqSys::iResList; + else + then iResList; + end match; +end getDaeEqsNotPartOfOdeSystem4; + public function dumpIdxScVarMapping input array> iMapping; algorithm diff --git a/Compiler/Template/CodegenCppHpcom.tpl b/Compiler/Template/CodegenCppHpcom.tpl index c60b11be9ce..c0d6346e7fc 100644 --- a/Compiler/Template/CodegenCppHpcom.tpl +++ b/Compiler/Template/CodegenCppHpcom.tpl @@ -438,6 +438,15 @@ case SIMCODE(modelInfo = MODELINFO(__)) then delete _functions; <%hpcomDestructorExtension%> } + + void <%className%>::deleteObjects() + { + + if(_functions != NULL) + delete _functions; + + deleteAlgloopSolverVariables(); + } <%Update(simCode,useFlatArrayNotation)%> @@ -716,6 +725,7 @@ template update2(list allEquationsPlusWhen, list> <%mainThreadCode%> //_evaluateBarrier.wait(); //calculation finished /*<%generateMeasureTimeEndCode("measuredFunctionStartValues", "measuredFunctionEndValues", "measureTimeFunctionsArray[0]", "evaluateODE", "MEASURETIME_MODELFUNCTIONS")%>*/ + <%generateStateVarPrefetchCode(simCode)%> } >> else "" @@ -800,6 +810,19 @@ template update2(list allEquationsPlusWhen, list> else "" end update2; +template generateStateVarPrefetchCode(SimCode simCode) +::= + match simCode + case SIMCODE(modelInfo = MODELINFO(vars = vars as SIMVARS(__))) then + << + <%(List.intRange3(0, 8, intSub(listLength(vars.stateVars), 1)) |> index => + 'PREFETCH(&__z[<%index%>], 0, 3);' + ;separator="\n")%> + >> + else '' + end match +end generateStateVarPrefetchCode; + template function_HPCOM_Level(list allEquationsPlusWhen, TaskList tasksOfLevel, String iType, Text &varDecls, SimCode simCode, Boolean useFlatArrayNotation) ::= match(tasksOfLevel) diff --git a/Compiler/Template/SimCodeTV.mo b/Compiler/Template/SimCodeTV.mo index 94580ac1062..69866c3d6fa 100644 --- a/Compiler/Template/SimCodeTV.mo +++ b/Compiler/Template/SimCodeTV.mo @@ -890,6 +890,10 @@ package SimCodeUtil output list> outColors; end translateColorsSimVarInts; + function getDaeEqsNotPartOfOdeSystem + input SimCode.SimCode iSimCode; + output list oEqs; + end getDaeEqsNotPartOfOdeSystem; end SimCodeUtil; @@ -2584,6 +2588,13 @@ package List input Integer inStop; output list outRange; end intRange; + + function intRange3 + input Integer inStart; + input Integer inStep; + input Integer inStop; + output list outRange; + end intRange3; function flatten input list> inList; diff --git a/Compiler/Util/List.mo b/Compiler/Util/List.mo index 4b0cadf05e9..85bfc58fbc5 100644 --- a/Compiler/Util/List.mo +++ b/Compiler/Util/List.mo @@ -146,7 +146,7 @@ end intRange2; public function intRange3 "Returns a list of integers from inStart to inStop with step inStep. - Example: listIntRange2(3,9,2) => {3,5,7,9}" + Example: listIntRange2(3,2,9) => {3,5,7,9}" input Integer inStart; input Integer inStep; input Integer inStop; diff --git a/SimulationRuntime/cpp/Include/Core/Modelica.h b/SimulationRuntime/cpp/Include/Core/Modelica.h index 6cc3452b6e2..bb4eb066831 100644 --- a/SimulationRuntime/cpp/Include/Core/Modelica.h +++ b/SimulationRuntime/cpp/Include/Core/Modelica.h @@ -8,6 +8,14 @@ #endif #endif +#ifndef PREFETCH + #if defined(_MSC_VER) + #define PREFETCH(add, rw, locality) + #else + #define PREFETCH(add, rw, locality) __builtin_prefetch(add, rw, locality) + #endif +#endif + #include //#include #include