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 Francesco Casella)

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 Dietmar Winkler, 9 years ago

Cc: Frenkel TUD added; Jens Frenkel removed
Milestone: Future

comment:2 by Francesco Casella, 7 years ago

Cc: Henning Kiel added; Frenkel TUD removed
Component: Backend
Description: modified (diff)
Owner: changed from Martin Sjölund to Patrick Täuber
Status: newassigned

Update: with 1.12.0beta2, the current performance using OMEdit is

nTime backend (s)Memory matching and sorting (MB)Memory total(MB)
1000 1.4 97 400
2000 3.1 376 650
3000 5.7 819 850
4000 10.4 1451 2250

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?

comment:3 by Henning Kiel, 7 years ago

I committed a fix for the huge memory consumption in PR1900

Version 0, edited 7 years ago by Henning Kiel (next)

comment:4 by Martin Sjölund, 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 Henning Kiel, 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 Francesco Casella, 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

Last edited 7 years ago by Francesco Casella (previous) (diff)

comment:7 by Martin Sjölund, 7 years ago

detectJacobianSparsePattern seems to scale as poorly as sorting and matching.

comment:8 by Martin Sjölund, 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 Martin Sjölund, 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.

Note: See TracTickets for help on using tickets.