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

Commit

Permalink
Only run SMFlatten if the model uses SMs
Browse files Browse the repository at this point in the history
The state machine handling is slow and always runs. This disables that
code unless the model actually contains a state machine.
  • Loading branch information
sjoelund committed Oct 17, 2016
1 parent c9f67a8 commit 7efbde0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Compiler/FrontEnd/StateMachineFlatten.mo
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ algorithm
assert(listLength(elementLst) == 1, "Internal compiler error: Handling of elementLst != 1 not supported\n");
DAE.COMP(ident, dAElist, source, comment) := listHead(elementLst);

if not List.exist(dAElist, isFlatSm) then
outDAElist := inDAElist;
return;
end if;

(flatSmLst, otherLst) := List.extractOnTrue(dAElist, isFlatSm);
elementLst2 := List.fold2(flatSmLst, flatSmToDataFlow, NONE(), NONE(), {});

Expand Down
2 changes: 1 addition & 1 deletion common
Submodule common updated 1 files
+27 −12 m4/qmake.m4

3 comments on commit 7efbde0

@bernhard-thiele
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this helps. We have the line

(flatSmLst, otherLst) := List.extractOnTrue(dAElist, isFlatSm);

which will return an empty list for flatSmLst if there are no state machines. All later functions iterate over lists that derive from flatSmLst. Hence, they will "iterate" over empty lists if there is no state machine.

@sjoelund
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't think I did profiling before turning this off? Just extractOnTrue takes 2% of total memory allocations (because it constructs a big list otherLst). DAEUtil.traverseDAE took 25% of total memory allocations despite there being a total of zero state machines :)
https://trac.openmodelica.org/OpenModelica/ticket/4071#comment:8

@bernhard-thiele
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I overlooked DAEUtil.traverseDAE. Pardon me, your change makes sense.

Please sign in to comment.