Skip to content

Commit

Permalink
further extension for countOperations
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23787 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Volker Waurich committed Dec 15, 2014
1 parent cf2b87f commit 4cd26e0
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 48 deletions.
7 changes: 7 additions & 0 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -716,6 +716,13 @@ public uniontype compInfo"types to count operations for the components"
Real density;
end LES_ANALYSE;

record TORN_ANALYSE//torn system of equations
StrongComponent comp;
compInfo tornEqs;
compInfo otherEqs;
Integer tornSize;
end TORN_ANALYSE;

end compInfo;


Expand Down
104 changes: 66 additions & 38 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -2041,14 +2041,16 @@ algorithm
local
Integer eqIdx, numAdd,numMul,numTrig,numRel,numOth, numFuncs, numLog, size;
Real density;
list<Integer> eqs;
list<Integer> eqs, tornEqs,otherEqs;
BackendDAE.StrongComponent comp,comp1;
BackendDAE.StrongComponents rest;
BackendDAE.EquationArray eqns, tmpEqns;
BackendDAE.EquationArray eqns;
BackendDAE.Variables vars;
BackendDAE.Equation eqn;
BackendDAE.compInfo compInfo, allOps;
BackendDAE.compInfo compInfo, allOps, torn,other;
list<BackendDAE.Equation> eqnlst;
BackendDAE.Jacobian jac;
DAE.FunctionTree funcs;
list<BackendDAE.Var> varlst;
list<DAE.Exp> explst;
list<tuple<Integer,list<Integer>>> eqnvartpllst;
Expand Down Expand Up @@ -2079,55 +2081,77 @@ algorithm
(eqnlst,varlst,_) = BackendDAETransform.getEquationAndSolvedVar(comp, BackendEquation.getEqnsFromEqSystem(isyst), BackendVariable.daeVars(isyst));
size = listLength(eqs);
density = realDiv(intReal(getNumJacEntries(jac)),intReal(size*size ));
allOps = BackendDAE.COUNTER(List.first(inComps),0,0,0,0,0,0,0);
allOps = BackendDAE.COUNTER(comp,0,0,0,0,0,0,0);
allOps = countOperationsJac(jac,ishared,allOps);
compInfo = BackendDAE.LES_ANALYSE(List.first(inComps),allOps,size,density);
//(eqnlst,varlst,_) = BackendDAETransform.getEquationAndSolvedVar(comp, BackendEquation.getEqnsFromEqSystem(isyst), BackendVariable.daeVars(isyst));
//tpl = addJacSpecificOperations(listLength(eqnlst),inTpl);
//tpl = countOperationsJac(jac,tpl);
//(explst,_) = BackendDAEUtil.getEqnSysRhs(BackendEquation.listEquation(eqnlst),BackendVariable.listVar1(varlst),SOME(funcs));
//(_,tpl) = Expression.traverseExpList(explst,countOperationsExp,tpl);
compInfo = BackendDAE.LES_ANALYSE(comp,allOps,size,density);
then countOperationstraverseComps(rest,isyst,ishared,compInfo::compInfosIn);
/*
case ((comp as BackendDAE.EQUATIONSYSTEM())::rest,_,_,_)

case ((comp as BackendDAE.EQUATIONSYSTEM(jac=jac))::rest,_,_,_)
equation
(eqnlst,_,_) = BackendDAETransform.getEquationAndSolvedVar(comp, BackendEquation.getEqnsFromEqSystem(isyst), BackendVariable.daeVars(isyst));
tpl = BackendDAEUtil.traverseBackendDAEExpsEqns(BackendEquation.listEquation(eqnlst),countOperationsExp,inTpl);
size = listLength(eqnlst);
(numAdd,numMul,numOth,numTrig,numRel,numLog,numFuncs) = BackendDAEUtil.traverseBackendDAEExpsEqns(BackendEquation.listEquation(eqnlst),function countOperationsExp(shared=ishared),(0,0,0,0,0,0,0));
allOps = BackendDAE.COUNTER(comp,numAdd,numMul,numTrig,numRel,numLog,numOth,numFuncs);
density = realDiv(intReal(getNumJacEntries(jac)),intReal(size*size ));
compInfo = BackendDAE.LES_ANALYSE(comp,allOps,size,density);
then
countOperationstraverseComps(rest,isyst,ishared,tpl);
case (BackendDAE.SINGLEARRAY(eqn=e)::rest,_,_,_)
countOperationstraverseComps(rest,isyst,ishared,compInfo::compInfosIn);

case ((comp as BackendDAE.SINGLEARRAY(eqn=eqIdx))::rest,_,_,_)
equation
eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), e);
(_,tpl) = BackendEquation.traverseExpsOfEquation(eqn,countOperationsExp,inTpl);
eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), eqIdx);
(_,(numAdd,numMul,numOth,numTrig,numRel,numLog,numFuncs)) = BackendEquation.traverseExpsOfEquation(eqn,function countOperationsExp(shared=ishared),(0,0,0,0,0,0,0));
compInfo = BackendDAE.COUNTER(comp,numAdd,numMul,numTrig,numRel,numLog,numOth,numFuncs);
then
countOperationstraverseComps(rest,isyst,ishared,tpl);
case (BackendDAE.SINGLEIFEQUATION(eqn=e)::rest,_,_,_)
countOperationstraverseComps(rest,isyst,ishared,compInfo::compInfosIn);

case ((comp as BackendDAE.SINGLEIFEQUATION(eqn=eqIdx))::rest,_,_,_)
equation
eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), e);
(_,tpl) = BackendEquation.traverseExpsOfEquation(eqn,countOperationsExp,inTpl);
eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), eqIdx);
(_,(numAdd,numMul,numOth,numTrig,numRel,numLog,numFuncs)) = BackendEquation.traverseExpsOfEquation(eqn,function countOperationsExp(shared=ishared),(0,0,0,0,0,0,0));
compInfo = BackendDAE.COUNTER(comp,numAdd,numMul,numTrig,numRel,numLog+1,numOth,numFuncs);
then
countOperationstraverseComps(rest,isyst,ishared,tpl);
case (BackendDAE.SINGLEALGORITHM(eqn=e)::rest,_,_,_)
countOperationstraverseComps(rest,isyst,ishared,compInfo::compInfosIn);

case ((comp as BackendDAE.SINGLEALGORITHM(eqn=eqIdx))::rest,_,_,_)
equation
eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), e);
(_,tpl) = BackendEquation.traverseExpsOfEquation(eqn,countOperationsExp,inTpl);
eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), eqIdx);
(_,(numAdd,numMul,numOth,numTrig,numRel,numLog,numFuncs)) = BackendEquation.traverseExpsOfEquation(eqn,function countOperationsExp(shared=ishared),(0,0,0,0,0,0,0));
compInfo = BackendDAE.COUNTER(comp,numAdd,numMul,numTrig,numRel,numLog+1,numOth,numFuncs);
then
countOperationstraverseComps(rest,isyst,ishared,tpl);
case (BackendDAE.SINGLECOMPLEXEQUATION(eqn=e)::rest,_,_,_)
countOperationstraverseComps(rest,isyst,ishared,compInfo::compInfosIn);

case ((comp as BackendDAE.SINGLECOMPLEXEQUATION(eqn=eqIdx))::rest,_,_,_)
equation
eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), e);
(_,tpl) = BackendEquation.traverseExpsOfEquation(eqn,countOperationsExp,inTpl);
eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), eqIdx);
(_,(numAdd,numMul,numOth,numTrig,numRel,numLog,numFuncs)) = BackendEquation.traverseExpsOfEquation(eqn,function countOperationsExp(shared=ishared),(0,0,0,0,0,0,0));
compInfo = BackendDAE.COUNTER(comp,numAdd,numMul,numTrig,numRel,numLog+1,numOth,numFuncs);
then
countOperationstraverseComps(rest,isyst,ishared,tpl);
case ((comp as BackendDAE.TORNSYSTEM(tearingvars=vlst, linear=true))::rest,_,BackendDAE.SHARED(functionTree=funcs),_)
countOperationstraverseComps(rest,isyst,ishared,compInfo::compInfosIn);

case (BackendDAE.TORNSYSTEM(tearingvars=vlst, residualequations=tornEqs, otherEqnVarTpl= eqnvartpllst, linear=true)::rest,_,BackendDAE.SHARED(functionTree=funcs),_)
equation
(eqnlst,varlst,_) = BackendDAETransform.getEquationAndSolvedVar(comp, BackendEquation.getEqnsFromEqSystem(isyst), BackendVariable.daeVars(isyst));
tpl = addJacSpecificOperations(listLength(vlst),inTpl);
tmpEqns = BackendEquation.listEquation(eqnlst);
(explst,_) = BackendDAEUtil.getEqnSysRhs(tmpEqns,BackendVariable.listVar1(varlst),SOME(funcs));
(_,tpl) = Expression.traverseExpList(explst,countOperationsExp,tpl);
comp = List.first(inComps);
eqns = BackendEquation.getEqnsFromEqSystem(isyst);
vars = BackendVariable.daeVars(isyst);
// the torn equations
eqnlst = BackendEquation.getEqns(tornEqs,eqns);
varlst = List.map1(vlst,BackendVariable.getVarAtIndexFirst, vars);
(explst,_) = BackendDAEUtil.getEqnSysRhs(BackendEquation.listEquation(eqnlst),BackendVariable.listVar1(varlst),SOME(funcs));
(_,(numAdd,numMul,numOth,numTrig,numRel,numLog,numFuncs)) = Expression.traverseExpList(explst,function countOperationsExp(shared=ishared),(0,0,0,0,0,0,0));
torn = BackendDAE.COUNTER(comp,numAdd,numMul,numTrig,numRel,numLog,numOth,numFuncs);
// the other eqs
otherEqs = List.map(eqnvartpllst,Util.tuple21);
vlst = List.flatten(List.map(eqnvartpllst,Util.tuple22));
eqnlst = BackendEquation.getEqns(otherEqs,eqns);
varlst = List.map1(vlst,BackendVariable.getVarAtIndexFirst, vars);
(explst,_) = BackendDAEUtil.getEqnSysRhs(BackendEquation.listEquation(eqnlst),BackendVariable.listVar1(varlst),SOME(funcs));
(_,(numAdd,numMul,numOth,numTrig,numRel,numLog,numFuncs)) = Expression.traverseExpList(explst,function countOperationsExp(shared=ishared),(0,0,0,0,0,0,0));
other = BackendDAE.COUNTER(comp,numAdd,numMul,numTrig,numRel,numLog,numOth,numFuncs);
compInfo = BackendDAE.TORN_ANALYSE(comp,torn,other,listLength(tornEqs));
then
countOperationstraverseComps(rest,isyst,ishared,tpl);
countOperationstraverseComps(rest,isyst,ishared,compInfo::compInfosIn);
/*
case ((comp as BackendDAE.TORNSYSTEM(tearingvars=vlst, linear=false))::rest,_,BackendDAE.SHARED(),_)
equation
(eqnlst,_,_) = BackendDAETransform.getEquationAndSolvedVar(comp, BackendEquation.getEqnsFromEqSystem(isyst), BackendVariable.daeVars(isyst));
Expand Down Expand Up @@ -2271,7 +2295,7 @@ algorithm
then (e, tpl);

case (e as DAE.IFEXP(expCond=cond,expThen=exp1,expElse=exp2),_,_) equation
//count for all branches, use the complete count for the condition and one additional logical count
//count all branches, use the complete count for the condition and one additional logical count
(_,tpl) = traversecountOperationsExp(cond,shared,inTuple);
(_,tpl) = traversecountOperationsExp(exp1,shared,tpl);
(_,tpl) = traversecountOperationsExp(exp2,shared,tpl);
Expand All @@ -2294,6 +2318,10 @@ algorithm
true = stringEq(opName,"sin") or stringEq(opName,"cos") or stringEq(opName,"tan");
then (e, (i1,i2,i3,i4+1,i5,i6,i7));

case (e as DAE.CALL(path=Absyn.IDENT(name=opName)),_,(i1,i2,i3,i4,i5,i6,i7)) equation
true = stringEq(opName,"der");
then (e, (i1,i2,i3,i4,i5,i6,i7));

case (e as DAE.CALL(path=Absyn.IDENT(name=opName)),_,(i1,i2,i3,i4,i5,i6,i7)) equation
true = stringEq(opName,"exp");
then (e, (i1,i2,i3+1,i4,i5,i6,i7));
Expand Down
26 changes: 24 additions & 2 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -8037,7 +8037,7 @@ algorithm
end matchcontinue;
end getConditionList1;

public function isWhenComp
public function isWhenComp"outputs true if the strongComponent is a singleEquation"
input BackendDAE.StrongComponent comp;
output Boolean isWhen;
algorithm
Expand All @@ -8048,7 +8048,7 @@ algorithm
end match;
end isWhenComp;

public function isSingleEquationComp
public function isSingleEquationComp"outputs true if the strongComponent is a singleEquation"
input BackendDAE.StrongComponent comp;
output Boolean isWhen;
algorithm
Expand All @@ -8059,5 +8059,27 @@ algorithm
end match;
end isSingleEquationComp;

public function isLinearEqSystemComp"outputs true if the strongComponent is a linear equationsystem"
input BackendDAE.StrongComponent comp;
output Boolean isWhen;
algorithm
isWhen := match(comp)
case(BackendDAE.EQUATIONSYSTEM(jacType = BackendDAE.JAC_LINEAR()))
then true;
else then false;
end match;
end isLinearEqSystemComp;

public function isLinearTornSystem"outputs true if the strongComponent is a torn system"
input BackendDAE.StrongComponent comp;
output Boolean isWhen;
algorithm
isWhen := match(comp)
case(BackendDAE.TORNSYSTEM(linear=true))
then true;
else then false;
end match;
end isLinearTornSystem;

annotation(__OpenModelica_Interface="backend");
end BackendDAEUtil;
11 changes: 10 additions & 1 deletion Compiler/BackEnd/BackendDump.mo
Expand Up @@ -3803,7 +3803,8 @@ algorithm
local
Integer numAdds,numMul,numOth,numTrig,numRel,numLog,numFuncs, size;
Real dens;
BackendDAE.compInfo allOps;
String s;
BackendDAE.compInfo allOps, tornEqs ,otherEqs;
BackendDAE.StrongComponent comp;
case(BackendDAE.COUNTER(comp=comp,numAdds=numAdds,numMul=numMul,numTrig=numTrig,numRelations=numRel,numLog=numLog,numOth=numOth,funcCalls=numFuncs))
equation
Expand All @@ -3815,6 +3816,14 @@ algorithm
dumpCompInfo(allOps);
print("\n");
then ();
case(BackendDAE.TORN_ANALYSE(tornEqs=tornEqs, otherEqs=otherEqs,comp=comp,tornSize=size))
equation
if BackendDAEUtil.isLinearTornSystem(comp) then s = "linear"; else s = "nonlinear"; end if;
print(s+"TORN_INFO "+printComponent(comp)+"\tsize|"+intString(size)+"\n\t");
dumpCompInfo(tornEqs);
dumpCompInfo(otherEqs);
print("\n");
then ();
else
equation
print("Dont know this compInfo\n");
Expand Down
35 changes: 28 additions & 7 deletions Compiler/BackEnd/HpcOmTaskGraph.mo
Expand Up @@ -4226,8 +4226,7 @@ algorithm
then tmpTaskGraphMeta;
else
equation
//tmpTaskGraphMeta = estimateCosts(iDae,iTaskGraphMeta);
tmpTaskGraphMeta = iTaskGraphMeta;
tmpTaskGraphMeta = estimateCosts(iDae,iTaskGraphMeta);
print("Warning: The costs have been estimated. Maybe " + benchFilePrefix + "-file is missing.\n");
then tmpTaskGraphMeta;
end matchcontinue;
Expand Down Expand Up @@ -4280,7 +4279,7 @@ protected
algorithm
comps := listGet(compsLstIn,systIdx);
eqSys := listGet(eqSystemsIn,systIdx);
compsInfos := BackendDAEOptimize.countOperationstraverseComps(comps,eqSys,sharedIn,{});
compsInfos := listReverse(BackendDAEOptimize.countOperationstraverseComps(comps,eqSys,sharedIn,{}));
exeCostsOut := List.map(compsInfos,calculateCosts);
end estimateCosts0;

Expand All @@ -4291,10 +4290,10 @@ author: Waurich TUD 2014-12"
algorithm
exeCost := match(compInfo)
local
Integer numAdds,numMul,numOth,numTrig,numRel,numLog,numFuncs, costs, ops, offset,size;
Real allOpCosts,dens;
Integer numAdds,numMul,numOth,numTrig,numRel,numLog,numFuncs, costs, ops,ops1, offset,size;
Real allOpCosts,tornCosts,otherCosts,dens;
BackendDAE.StrongComponent comp;
BackendDAE.compInfo allOps;
BackendDAE.compInfo allOps, torn, other;

case(BackendDAE.COUNTER(comp=comp,numAdds=numAdds,numMul=numMul,numTrig=numTrig,numRelations=numRel,numLog=numLog,numOth=numOth,funcCalls=numFuncs))
equation
Expand All @@ -4306,12 +4305,34 @@ algorithm
costs = offset+ 5*numAdds+ 25*numMul+ 150*numOth+250*numTrig+ 5*numRel+ 10*numLog+400*numFuncs;
then (ops,intReal(costs));

case(BackendDAE.LES_ANALYSE(allOperations=allOps,size=size,density=dens))
case(BackendDAE.LES_ANALYSE(comp=comp,allOperations=allOps,size=size,density=dens))
equation
true = BackendDAEUtil.isLinearEqSystemComp(comp);
(ops,allOpCosts) = calculateCosts(allOps);
allOpCosts = 5000+allOpCosts+realMul(realPow(intReal(size),3)+realPow(intReal(size),2),dens);
then (ops,allOpCosts);

case(BackendDAE.LES_ANALYSE(comp=comp,allOperations=allOps,size=size,density=dens))
equation
(ops,allOpCosts) = calculateCosts(allOps);
allOpCosts = 5000+1000*size;
then (ops,allOpCosts);

case(BackendDAE.TORN_ANALYSE(comp=comp,tornEqs=torn,otherEqs=other,tornSize=size))
equation
true = BackendDAEUtil.isLinearTornSystem(comp);
(ops,tornCosts) = calculateCosts(torn);
(ops1,otherCosts) = calculateCosts(other);
allOpCosts = 7000;//*+realMul(realPow(intReal(size),3)+realPow(intReal(size),2)
then (ops+ops1,allOpCosts);

case(BackendDAE.TORN_ANALYSE(comp=comp,tornEqs=torn,otherEqs=other,tornSize=size))
equation
(ops,tornCosts) = calculateCosts(torn);
(ops1,otherCosts) = calculateCosts(other);
allOpCosts = 4000+size*1000;//*+realMul(realPow(intReal(size),3)+realPow(intReal(size),2)
then (ops+ops1,allOpCosts);

else
equation
print("calculate costs failed!\n");
Expand Down

0 comments on commit 4cd26e0

Please sign in to comment.