Skip to content

Commit

Permalink
improved sortEqnsAndVars
Browse files Browse the repository at this point in the history
  • Loading branch information
vruge authored and OpenModelica-Hudson committed Jun 22, 2015
1 parent 9594547 commit e691274
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
30 changes: 18 additions & 12 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -4134,7 +4134,7 @@ public function sortEqnsVars
input BackendDAE.BackendDAE iDAE;
output BackendDAE.BackendDAE oDAE;
algorithm
oDAE := if true then sortEqnsVarsWork(iDAE) else iDAE;
oDAE := if Flags.isSet(Flags.SORT_EQNS_AND_VARS) then sortEqnsVarsWork(iDAE) else iDAE;
end sortEqnsVars;

protected function sortEqnsVarsWork
Expand Down Expand Up @@ -4164,7 +4164,7 @@ algorithm
BackendDAE.SHARED(functionTree=functionTree) := shared;
for syst in systlst loop
BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,stateSets=stateSets,partitionKind=partitionKind) := syst;
(_, m, mT) := BackendDAEUtil.getIncidenceMatrix(syst, BackendDAE.NORMAL(), SOME(functionTree));
(_, m, mT) := BackendDAEUtil.getIncidenceMatrix(syst, BackendDAE.SPARSE(), SOME(functionTree));

BackendDAE.VARIABLES(varArr = BackendDAE.VARIABLE_ARRAY(varOptArr = varOptArr, numberOfElements = nv)) := vars;
BackendDAE.EQUATION_ARRAY(equOptArr = equOptArr, numberOfElement = ne) := eqns;
Expand All @@ -4179,13 +4179,13 @@ algorithm
sortEqnsVarsWeights(w_eqns, ne, m);

//sort vars
tplIndexWeight := list( (i, w_vars[i]) for i in 1:nv);
tplIndexWeight := list((i, w_vars[i]) for i in 1:nv);
//sorted vars
tplIndexWeight := List.sort(tplIndexWeight, compWeightsVars);
//new order vars indexs
indexs := sortEqnsVarsWorkTpl(tplIndexWeight);
var_lst := list(BackendVariable.getVarAt(vars, i) for i in indexs);
// new vars
// new vars
vars := BackendVariable.listVar1(var_lst);

//sort eqns
Expand Down Expand Up @@ -4221,31 +4221,37 @@ protected
Integer i;
algorithm
for i in 1:n loop
try
outW[i] := listLength(m[i]);
else
outW[i] := -1;
end try;
outW[i] := listLength(m[i]);
end for;
end sortEqnsVarsWeights;

// sort({2, 1, 3}, intGt) => {1, 2, 3}
// sort({2, 1, 3}, intLt) => {3, 2, 1}
protected function compWeightsVars
input tuple<Integer,Integer> inTpl1;
input tuple<Integer,Integer> inTpl2;
output Boolean b;
protected
Integer i1,i2;
algorithm
b := Util.tuple22(inTpl1) < Util.tuple22(inTpl2);
(_,i1) := inTpl1;
(_,i2) := inTpl2;
b := intGt(i1 ,i2);
end compWeightsVars;

protected function compWeightsEqns
input tuple<Integer,Integer> inTpl1;
input tuple<Integer,Integer> inTpl2;
output Boolean b;
protected
Integer i1,i2;
algorithm
b := Util.tuple22(inTpl1) > Util.tuple22(inTpl2);
(_,i1) := inTpl1;
(_,i2) := inTpl2;
//b := intLt(i1 ,i2);
b := intGt(i1 ,i2);
end compWeightsEqns;


// =============================================================================
// section for symEuler
//
Expand Down
5 changes: 4 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -446,6 +446,8 @@ constant DebugFlag RUNTIME_STATIC_LINKING = DEBUG_FLAG(138, "runtimeStaticLinkin
Util.gettext("Use the static simulation runtime libraries (C++ simulation runtime)."));
constant DebugFlag DYNAMIC_TEARING_INFO = DEBUG_FLAG(139, "dynamicTearingInfo", false,
Util.gettext("Dumps information about the strict and casual sets of the tearing system."));
constant DebugFlag SORT_EQNS_AND_VARS = DEBUG_FLAG(140, "sortEqnsAndVars", false,
Util.gettext("Heuristical sorting for equations and variables. Influenced: removeSimpleEquations and tearing."));

// This is a list of all debug flags, to keep track of which flags are used. A
// flag can not be used unless it's in this list, and the list is checked at
Expand Down Expand Up @@ -591,7 +593,8 @@ constant list<DebugFlag> allDebugFlags = {
VECTORIZE,
CHECK_EXT_LIBS,
RUNTIME_STATIC_LINKING,
DYNAMIC_TEARING_INFO
DYNAMIC_TEARING_INFO,
SORT_EQNS_AND_VARS
};

public
Expand Down

0 comments on commit e691274

Please sign in to comment.