Skip to content

Commit

Permalink
- fixed deleteObject() in hpcom cpp-runtime
Browse files Browse the repository at this point in the history
- disabled memory optimization for level scheduler

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23620 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Marcus Walther committed Dec 2, 2014
1 parent 7bfa7b6 commit d8975ae
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/HpcOmMemory.mo
Expand Up @@ -290,10 +290,10 @@ encapsulated package HpcOmMemory
array<tuple<Integer,Integer,Real>> 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");
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/HpcOmScheduler.mo
Expand Up @@ -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;
Expand Down
89 changes: 89 additions & 0 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -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<SimCode.SimEqSystem> oEqs;
protected
array<Option<SimCode.SimEqSystem>> allEqs;
list<tuple<Integer, SimCode.SimEqSystem>> allEqIdxMapping; //mapping SimEqIdx -> SimEqSystem
list<SimCode.SimEqSystem> allEquations;
list<list<SimCode.SimEqSystem>> odeEquations;
Integer highestIdx;
list<SimCode.SimEqSystem> 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<list<tuple<Integer, SimCode.SimEqSystem>>, Integer> iMappingWithHighestIdx; //<mapping simEqIdx -> SimEqSystem, highestIdx>
output tuple<list<tuple<Integer, SimCode.SimEqSystem>>, Integer> oMappingWithHighestIdx;
protected
Integer index, highestIdx;
list<tuple<Integer, SimCode.SimEqSystem>> 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<Integer, SimCode.SimEqSystem> iEqSystem; //<simEqIdx, simEqSystem>
input array<Option<SimCode.SimEqSystem>> iEqArray;
output array<Option<SimCode.SimEqSystem>> 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<SimCode.SimEqSystem> iEqSystem;
input array<Option<SimCode.SimEqSystem>> iEqArray;
output array<Option<SimCode.SimEqSystem>> 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<Option<SimCode.SimEqSystem>> iEqArray;
output array<Option<SimCode.SimEqSystem>> 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<SimCode.SimEqSystem> iEqSystemOpt;
input list<SimCode.SimEqSystem> iResList;
output list<SimCode.SimEqSystem> 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<Option<SimCodeVar.SimVar>> iMapping;
algorithm
Expand Down
23 changes: 23 additions & 0 deletions Compiler/Template/CodegenCppHpcom.tpl
Expand Up @@ -438,6 +438,15 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
delete _functions;
<%hpcomDestructorExtension%>
}

void <%className%>::deleteObjects()
{
if(_functions != NULL)
delete _functions;
deleteAlgloopSolverVariables();
}

<%Update(simCode,useFlatArrayNotation)%>

Expand Down Expand Up @@ -716,6 +725,7 @@ template update2(list<SimEqSystem> allEquationsPlusWhen, list<list<SimEqSystem>>
<%mainThreadCode%>
//_evaluateBarrier.wait(); //calculation finished
/*<%generateMeasureTimeEndCode("measuredFunctionStartValues", "measuredFunctionEndValues", "measureTimeFunctionsArray[0]", "evaluateODE", "MEASURETIME_MODELFUNCTIONS")%>*/
<%generateStateVarPrefetchCode(simCode)%>
}
>>
else ""
Expand Down Expand Up @@ -800,6 +810,19 @@ template update2(list<SimEqSystem> allEquationsPlusWhen, list<list<SimEqSystem>>
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<SimEqSystem> allEquationsPlusWhen, TaskList tasksOfLevel, String iType, Text &varDecls, SimCode simCode, Boolean useFlatArrayNotation)
::=
match(tasksOfLevel)
Expand Down
11 changes: 11 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -890,6 +890,10 @@ package SimCodeUtil
output list<list<Integer>> outColors;
end translateColorsSimVarInts;

function getDaeEqsNotPartOfOdeSystem
input SimCode.SimCode iSimCode;
output list<SimCode.SimEqSystem> oEqs;
end getDaeEqsNotPartOfOdeSystem;
end SimCodeUtil;


Expand Down Expand Up @@ -2584,6 +2588,13 @@ package List
input Integer inStop;
output list<Integer> outRange;
end intRange;

function intRange3
input Integer inStart;
input Integer inStep;
input Integer inStop;
output list<Integer> outRange;
end intRange3;

function flatten
input list<list<ElementType>> inList;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Util/List.mo
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions SimulationRuntime/cpp/Include/Core/Modelica.h
Expand Up @@ -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 <string>
//#include <vector>
#include <algorithm>
Expand Down

0 comments on commit d8975ae

Please sign in to comment.