Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Use sets instead of lists in comSubExp
Browse files Browse the repository at this point in the history
This resolves some performance problems reported in ticket:4398.

Belonging to [master]:
  - #1944
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Oct 25, 2017
1 parent 7b04aa1 commit c21c29d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
32 changes: 17 additions & 15 deletions Compiler/BackEnd/ResolveLoops.mo
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import BackendDAE;
import DAE;

protected

import Array;
import AvlSetInt;
import BackendDAEUtil;
import BackendEquation;
import BackendVariable;
Expand Down Expand Up @@ -414,9 +414,10 @@ algorithm
list<list<Integer>> paths, allPaths, simpleLoops, varEqsLst, crossEqLst, paths0, paths1, closedPaths, loopConnectors, connectedPaths;
BackendDAE.Equation resolvedEq, startEq;
list<BackendDAE.Equation> eqLst;
AvlSetInt.Tree eqCrossSet;
case(_,_::_,{},_,_)
equation
//print("partition has only eqCrossNodes\n");
//print("partition has only eqCrossNodes\n");
// get the paths between the crossEqNodes and order them according to their length
allPaths = getPathTillNextCrossEq(eqCrossLstIn,mIn,mTIn,eqCrossLstIn,{},{});
allPaths = List.sort(allPaths,List.listIsLonger);
Expand Down Expand Up @@ -485,7 +486,8 @@ algorithm
for i in 1:arrayLength(mTIn) loop
arrayUpdate(mTIn, i, List.sort(mTIn[i], intGt));
end for;
paths := getShortPathsBetweenEqCrossNodes(List.sort(eqCrossLstIn,intGt), mIn, mTIn, {});
eqCrossSet := AvlSetInt.addList(AvlSetInt.EMPTY(), eqCrossLstIn);
paths := getShortPathsBetweenEqCrossNodes(AvlSetInt.listKeysReverse(eqCrossSet), eqCrossSet, mIn, mTIn, {});
//
//print("GOT SOME NEW LOOPS: \n"+stringDelimitList(List.map(paths,HpcOmTaskGraph.intLstString)," / ")+"\n");
then
Expand Down Expand Up @@ -540,6 +542,7 @@ end hasSameIntSortedExcept;
protected function getShortPathsBetweenEqCrossNodes"find closedLoops between 2 eqCrossNode, no matter whether there are var cross nodes between them.
author: vwaurich TUD 12-2016"
input list<Integer> eqCrossLstIn;
input AvlSetInt.Tree eqCrossSet;
input BackendDAE.IncidenceMatrix mIn;
input BackendDAE.IncidenceMatrixT mTIn;
input list<list<Integer>> pathsIn;
Expand All @@ -557,19 +560,19 @@ algorithm
for adjVar in adjVars loop
//print("all adj eqs "+stringDelimitList(List.map(adjEqs, intString),",")+"\n");
//all adjEqs which are crossnodes as well
adjEqs := List.intersectionIntSorted(arrayGet(mTIn, adjVar), rest);
for adjEq in adjEqs loop
if adjEq <> crossEq then
//print("all sharedVars "+stringDelimitList(List.map(sharedVars, intString),",")+"\n");
if hasSameIntSortedExcept(adjVars, arrayGet(mIn, adjEq), adjVar) then
newPath := adjEq::{crossEq};
paths := List.unionElt(newPath, paths);
//print("found path "+stringDelimitList(List.map(newPath,intString)," ; ")+"\n");
end if;
for adjEq in arrayGet(mTIn, adjVar) loop
if if adjEq > crossEq then (not AvlSetInt.hasKey(eqCrossSet, adjEq)) else true then
continue;
end if;
//print("all sharedVars "+stringDelimitList(List.map(sharedVars, intString),",")+"\n");
if hasSameIntSortedExcept(adjVars, arrayGet(mIn, adjEq), adjVar) then
newPath := adjEq::{crossEq};
paths := List.unionElt(newPath, paths);
//print("found path "+stringDelimitList(List.map(newPath,intString)," ; ")+"\n");
end if;
end for;
end for;
paths := getShortPathsBetweenEqCrossNodes(rest, mIn, mTIn, listAppend(paths, pathsIn));
paths := getShortPathsBetweenEqCrossNodes(rest, eqCrossSet, mIn, mTIn, listAppend(paths, pathsIn));
then paths;
case({},_,_,_)
then pathsIn;
Expand Down Expand Up @@ -838,8 +841,7 @@ algorithm
else
equation
print("resolveLoops_resolveAndReplace failed!\n");
then
fail();
then fail();
end matchcontinue;
end resolveLoops_resolveAndReplace;

Expand Down
19 changes: 19 additions & 0 deletions Compiler/Util/BaseAvlSet.mo
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,25 @@ algorithm
end match;
end listKeys;

function listKeysReverse
"Converts the tree to a flat list of keys (in order)."
input Tree inTree;
input output list<Key> lst={};
algorithm
lst := match inTree
case LEAF() then inTree.key::lst;
case NODE()
algorithm
lst := listKeysReverse(inTree.left, lst);
lst := inTree.key::lst;
lst := listKeysReverse(inTree.right, lst);
then
lst;

else lst;
end match;
end listKeysReverse;

replaceable function join
"Joins two trees by adding the second one to the first."
input output Tree tree;
Expand Down

0 comments on commit c21c29d

Please sign in to comment.