Skip to content

Commit

Permalink
Fix slow marking of nonlinear iteration vars (#11312)
Browse files Browse the repository at this point in the history
Fixes #11302

For each SCC of the system all variables were traversed, so the time
complexity was O(N*S) where N is the number of variables and S is
the number of SCCs.
By first collecting all nonlinear iteration vars in the same set and
then marking them once it should now be O(N).
  • Loading branch information
phannebohm committed Oct 4, 2023
1 parent f373108 commit 5d55005
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -10276,21 +10276,22 @@ algorithm
syst := match syst
local
BackendDAE.StrongComponents comps;
UnorderedSet<DAE.ComponentRef> set = UnorderedSet.new(ComponentReference.hashComponentRef, ComponentReference.crefEqual);
case BackendDAE.EQSYSTEM(matching = BackendDAE.MATCHING(comps = comps)) algorithm
for comp in comps loop
syst.orderedVars := markNonlinearIterationVariablesStrongComponent(comp, syst.orderedVars);
markNonlinearIterationVariablesStrongComponent(comp, set);
end for;
(syst.orderedVars, _) := BackendVariable.traverseBackendDAEVarsWithUpdate(syst.orderedVars, markNonlinearIterationVariable, set);
then syst;
else syst;
end match;
end markNonlinearIterationVariablesEqSystem;

protected function markNonlinearIterationVariablesStrongComponent
input BackendDAE.StrongComponent comp;
input output BackendDAE.Variables vars;
input UnorderedSet<DAE.ComponentRef> set;
protected
list<BackendDAE.Var> nonlinear_iteration_vars;
UnorderedSet<DAE.ComponentRef> set = UnorderedSet.new(ComponentReference.hashComponentRef, ComponentReference.crefEqual);
algorithm
nonlinear_iteration_vars := match comp
local
Expand All @@ -10302,8 +10303,6 @@ algorithm
for var in nonlinear_iteration_vars loop
UnorderedSet.add(var.varName, set);
end for;

(vars, _) := BackendVariable.traverseBackendDAEVarsWithUpdate(vars, markNonlinearIterationVariable, set);
end markNonlinearIterationVariablesStrongComponent;

protected function markNonlinearIterationVariable
Expand Down

0 comments on commit 5d55005

Please sign in to comment.