Modelica Performance Analyzer¶
A common problem when simulating models in an equation-based language like Modelica is that the model may contain non-linear equation systems. These are solved in each time-step by extrapolating an initial guess and running a non-linear system solver. If the simulation takes too long to simulate, it is useful to run the performance analysis tool. The tool has around 5~25% overhead, which is very low compared to instruction-level profilers (30x-100x overhead). Due to being based on a single simulation run, the report may contain spikes in the charts.
When running a simulation for performance analysis, execution times of user-defined functions as well as linear, non-linear and mixed equation systems are recorded.
To start a simulation in this mode, turn on profiling with the following command line flag >>> setCommandLineOptions("--profiling=all")
The generated report is in HTML format (with images in the SVG format), stored in a file modelname_prof.html, but the XML database and measured times that generated the report and graphs are also available if you want to customize the report for comparison with other tools.
Below we use the performance profiler on the simple model A:
model ProfilingTest
function f
input Real r;
output Real o = sin(r);
end f;
String s = "abc";
Real x = f(x) "This is x";
Real y(start=1);
Real z1 = cos(z2);
Real z2 = sin(z1);
equation
der(y) = time;
end ProfilingTest;
We simulate as usual, after setting the profiling flag:
>>> setCommandLineOptions("--profiling=blocks+html")
true
>>> simulate(ProfilingTest)
record SimulationResult
resultFile = "«DOCHOME»/ProfilingTest_res.mat",
simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ProfilingTest', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
messages = "LOG_SUCCESS | info | The initialization finished successfully without homotopy method.
LOG_SUCCESS | info | The simulation finished successfully.
Warning: empty y range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
stdout | info | Time measurements are stored in ProfilingTest_prof.html (human-readable) and ProfilingTest_prof.xml (for XSL transforms or more details)
",
timeFrontend = 0.018249064,
timeBackend = 0.009558131000000001,
timeSimCode = 0.002339231,
timeTemplates = 0.033747506,
timeCompile = 0.5838955539999999,
timeSimulation = 0.07008342000000001,
timeTotal = 0.718018611
end SimulationResult;
"Warning: There are nonlinear iteration variables with default zero start attribute found in NLSJac0. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->OMCFlags, in OMNotebook call setCommandLineOptions("-d=initialization").
Warning: The initial conditions are not fully specified. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->OMCFlags, in OMNotebook call setCommandLineOptions("-d=initialization").
"
Profiling information for ProfilingTest¶
Information¶
All times are measured using a real-time wall clock. This means context switching produces bad worst-case execution times (max times) for blocks. If you want better results, use a CPU-time clock or run the command using real-time priviliges (avoiding context switches).
Note that for blocks where the individual execution time is close to the accuracy of the real-time clock, the maximum measured time may deviate a lot from the average.
For more details, see ProfilingTest_prof.xml.
Settings¶
Name |
Value |
---|---|
Integration method |
dassl |
Output format |
mat |
Output name |
|
Output size |
24.0 kB |
Profiling data |
|
Profiling size |
0 B |
Summary¶
Task |
Time |
Fraction |
---|---|---|
Pre-Initialization |
0.000178 |
2.22% |
Initialization |
0.000206 |
2.57% |
Event-handling |
0.000000 |
0.00% |
Creating output file |
0.000637 |
7.96% |
Linearization |
NaN% |
|
Time steps |
0.005735 |
71.62% |
Overhead |
0.000322 |
4.02% |
Unknown |
NaN |
NaN% |
Total simulation time |
0.008007 |
100.00% |
Global Steps¶
Steps |
Total Time |
Fractio n |
Average Time |
Max Time |
Deviati on |
|
---|---|---|---|---|---|---|
499 |
0.00573 5 |
71.62% |
0.00001 1492985 9719439 |
0.00013 8069 |
11.01x |
Measured Function Calls¶
Name |
Calls |
Time |
Fractio n |
Max Time |
Deviati on |
|
---|---|---|---|---|---|---|
|Graph thumbna il functio n fun0||Graph thumbna il count functio n fun0| |
506 |
0.00008 8574 |
1.11% |
0.00000 1292 |
6.38x |
Measured Blocks¶
Name |
Calls |
Time |
Fractio n |
Max Time |
Deviati on |
|
---|---|---|---|---|---|---|
|Graph thumbna il eq0|| Graph thumbna il count eq0| |
` <#eq0 >`__ |
7 |
0.00011 1158 |
1.39% |
0.00011 2361 |
6.08x |
` <#eq1 2>`__ |
2 |
0.00000 3756 |
0.05% |
0.00000 3956 |
1.11x |
|
` <#eq2 0>`__ |
504 |
0.00101 0318 |
12.62% |
0.00005 1637 |
24.76x |
|
` <#eq2 2>`__ |
504 |
0.00128 9230 |
16.10% |
0.00004 2139 |
15.47x |
Equations¶
Name |
Variables |
---|---|
eq0 |
|
eq1 |
|
eq2 |
|
eq3 |
|
eq4 |
|
eq5 |
|
eq6 |
` <#var0>`__ |
eq7 |
` <#var0>`__ |
eq8 |
` <#var0>`__ |
eq9 |
` <#var0>`__ |
eq10 |
|
eq11 |
|
eq12 |
|
eq13 |
|
eq14 |
|
eq15 |
|
eq16 |
` <#var0>`__ |
eq17 |
` <#var0>`__ |
eq18 |
` <#var0>`__ |
eq19 |
` <#var0>`__ |
eq20 |
|
eq21 |
|
eq22 |
|
eq23 |
Genenerated JSON for the Example¶
{
"name":"ProfilingTest",
"prefix":"ProfilingTest",
"date":"2020-02-01 17:02:53",
"method":"dassl",
"outputFormat":"mat",
"outputFilename":"ProfilingTest_res.mat",
"outputFilesize":24581,
"overheadTime":0.000352067,
"preinitTime":0.000177693,
"initTime":0.000206437,
"eventTime":0,
"outputTime":0.000637368,
"jacobianTime":4.47895e-05,
"totalTime":0.00800731,
"totalStepsTime":1.04495e-05,
"totalTimeProfileBlocks":0.00241446,
"numStep":499,
"maxTime":0.00013806947,
"functions":[
{"name":"ProfilingTest.f","ncall":506,"time":0.000088574,"maxTime":0.000001292}
],
"profileBlocks":[
{"id":0,"ncall":7,"time":0.000111158,"maxTime":0.000112361},
{"id":12,"ncall":2,"time":0.000003756,"maxTime":0.000003956},
{"id":20,"ncall":504,"time":0.001010318,"maxTime":0.000051637},
{"id":22,"ncall":504,"time":0.001289230,"maxTime":0.000042139}
]
}
Using the Profiler from OMEdit¶
When running a simulation from OMEdit, it is possible to enable profiling information, which can be combined with the transformations browser.
When profiling the DoublePendulum example from MSL, the following output in Figure 105 is a typical result. This information clearly shows which system takes longest to simulate (a linear system, where most of the time overhead probably comes from initializing LAPACK over and over).