Opened 11 years ago

Last modified 7 years ago

#2647 new enhancement

Expression.simplify is way too slow

Reported by: Willi Braun Owned by: probably noone
Priority: high Milestone: Future
Component: Backend Version: trunk
Keywords: Cc:

Description (last modified by Willi Braun)

For the following models the compile time increases heavy, if one increase the size.

  model BaseModelEquations
    parameter Integer n=100; // see Backend time for 100, 200, 400
    input Real[n] u1;
    input Real[n] u2;
    output Real[n] y1;
    output Real y2;
  equation
    y1=array(if u1[i] > 0 then u1[i] else u2[i] for i in 1:n);
    y2=sum(y1);
  end BaseModelEquations;
For n=100 : timeBackend = 0.266189871
For n=200 : timeBackend = 1.490894306
For n=400 : timeBackend = 10.56719995
For n=800 : timeBackend = 82.89054140

All the time is lost by trying to simplify expressions.
Also we try to do it 3 time, once by creating the BackendDAE structure,
once directly after that and once at the end of the Backend process.

We should do it only once and perhaps we should improve Expression.simplify further anyway.

Change History (17)

comment:1 by Willi Braun, 11 years ago

Summary: Expression.simplify is ways tooExpression.simplify is ways too slow

comment:2 by Lennart Ochel, 11 years ago

Summary: Expression.simplify is ways too slowExpression.simplify is way too slow

comment:3 by Willi Braun, 11 years ago

Description: modified (diff)

comment:4 by Martin Sjölund, 11 years ago

We could just change the +noSimplify flag to +d=slowSimplifications, and make it default off :)

comment:5 by Lennart Ochel, 11 years ago

The scaling seems to be not that bad. Simplify has a linear scaling w.r.t. the number of equations (based on this example, based on 4 data points ;-))

comment:6 by Martin Sjölund, 11 years ago

No, that is not linear scaling 0.26 * 8 = 2.08, but we got 82.9. It seems to be O(n3) or maybe O(n2log(n)).
For me (total time front-end+back-end+codegen):

n simplify1 (s) simplify (s)
100 0.3440.85
200 0.744.26
400 2.0430.24
800 5.32218.73
Last edited 11 years ago by Martin Sjölund (previous) (diff)

comment:7 by Willi Braun, 11 years ago

Yes, the real mess is simplify2 in combination with simplifyBinaryCoeff.

comment:8 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:9 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:10 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:11 by Francesco Casella, 9 years ago

See also #3491

comment:12 by Vitalij Ruge, 9 years ago

Willi, has done some anaylses for changes in simplify2

N M(countOperations) BackendTime TotalTime
100 199 0.042735523 0.576733485
200 399 0.088144779 0.825384327
400 799 0.250593965 1.431617297
800 1599 0.976192998 3.235029631
1600 3199 5.110137451 9.466115887
3200 6399 32.870996638 42.864459504

It seems to be O(N2)

M = [199, 399, 799, 1599, 3199, 6399];
t = [0.042735523, 0.088144779, 0.250593965, 0.976192998, 5.110137451, 32.870996638];
plot(M,sqrt(t))

comment:13 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:14 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:15 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:16 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:17 by Francesco Casella, 7 years ago

Milestone: 1.12.0Future

The milestone of this ticket has been reassigned to "Future".

If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.

If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".

In both cases, a short informative comment would be welcome.

Note: See TracTickets for help on using tickets.