Opened 14 years ago
Last modified 7 years ago
#1451 assigned defect
Backend scaling for simple array-equation
Reported by: | Martin Sjölund | Owned by: | Patrick Täuber |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | Backend | Version: | |
Keywords: | Cc: | Martin Sjölund, Henning Kiel |
Description (last modified by )
Scales to the power of 3.5... Horrible
n=50 0.231s
n=100 2s
n=150 9s
n=200 27s
n=10000 115 days
class A function fn input Real t; input Integer n; output Real out[n]; algorithm out := {i*t for i in 1:n}; end fn; parameter Integer n = 4000; Real r[n]; equation r = fn(time, n); end A;
Change History (9)
comment:1 by , 9 years ago
Cc: | added; removed |
---|---|
Milestone: | → Future |
comment:2 by , 7 years ago
Cc: | added; removed |
---|---|
Component: | → Backend |
Description: | modified (diff) |
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 7 years ago
comment:4 by , 7 years ago
So PR1900 simply avoids creating a new list for absInt
to treat state variables as normal variables if there are no state variables in a row. And PR1902 avoids creating a temporary list to filter out some variables.
comment:5 by , 7 years ago
Yes, and these were the culprits of O(N2) memory consumption. I suspect there are more such places in OMCompiler.
Still, there is an O(n3) algorithm at work which dominates at n=32000
I could track it down to BackendDAEEXT.matching with a matchingID of 5 ("PF+")
Is this something we can influence? Or is this 3rd party code?
comment:6 by , 7 years ago
I'm now using OMEdit v1.13.0-dev-24-g095b0ef (64-bit) connected to v1.13.0-dev-143-ged4ccd8 (64-bit), and it seems that after the last PRs, the situation has actually gotten worse.
The time spent and memory allocated by matching and sorting is roughly the same. On the other hand, the total memory peak has almost doubled, so no the PC hangs also at N = 32000
comment:7 by , 7 years ago
detectJacobianSparsePattern seems to scale as poorly as sorting and matching.
comment:8 by , 7 years ago
So the problem is that the equation (and variable) is split into 4000 separate ones for the sorting+matching. It's a 100% filled adjacency matrix (4000x4000), and just sorting the result of the matching takes 1/3 of the time.
If we would redesign the sorting+matching to handle array variables efficiently (perhaps with some heuristic) to not expand variables unless it's beneficial to do so. In this case, f(time, n)[i]
will not be helpful and then perhaps we should treat it as a scalar.
Note: If you use algorithm instead of equation, the model is even slower (3s to 37s for N=4000), but this is for created simulation system equations
.
comment:9 by , 7 years ago
We could also have some pre-sorting phase where we handle all trivial equations. This would be similar to the under/over-determined partial matching check I wrote previously. That seemed to have reasonable performance.
Update: with 1.12.0beta2, the current performance using OMEdit is
Matching and sorting takes the lion's share of memory allocation. Above n = 4000 the memory consumption blows up and the PC just hangs.
Good news: scaling in terms of time is now definitely better than O(N3.5), and it is possible to get up to n = 4000
Bad news: the memory allocation by the matching and sorting algorithm grows as O(N2) and is really huge. Why should over 1GB be spent to analyze a system with 4000 equations?