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-6, 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 [3:3], adjusting to [2.97:3.03]
Warning: empty y range [3:3], adjusting to [2.97:3.03]
Warning: empty y range [2:2], adjusting to [1.98:2.02]
Warning: empty y range [2:2], adjusting to [1.98:2.02]
Warning: empty y range [3:3], adjusting to [2.97:3.03]
Warning: empty y range [3:3], adjusting to [2.97:3.03]
LOG_STDOUT | info | Time measurements are stored in ProfilingTest_prof.html (human-readable) and ProfilingTest_prof.xml (for XSL transforms or more details)
",
timeFrontend = 0.0026541710000000003,
timeBackend = 0.016253275,
timeSimCode = 0.002170401,
timeTemplates = 0.004278381,
timeCompile = 0.475425585,
timeSimulation = 0.060003970000000004,
timeTotal = 0.5608817129999999
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->Show additional information from the initialization process, 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->Show additional information from the initialization process, 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.000119 |
5.65% |
Initialization |
0.000129 |
6.12% |
Event-handling |
0.000000 |
0.00% |
Creating output file |
0.000137 |
6.50% |
Linearization |
NaN% |
|
Time steps |
0.001381 |
65.51% |
Overhead |
0.000158 |
7.50% |
Unknown |
NaN |
NaN% |
Total simulation time |
0.002108 |
100.00% |
Global Steps¶
Steps |
Total Time |
F raction |
Average Time |
Max Time |
De viation |
|
---|---|---|---|---|---|---|
499 |
0 .001381 |
65.51% |
2.7675 3507014 028e-06 |
0.00 0051663 |
17.67x |
Measured Function Calls¶
Name |
Calls |
Time |
F raction |
Max Time |
De viation |
|
---|---|---|---|---|---|---|
|Graph th umbnail f unction fun0|
th umbnail count f unction fun0| |
` Profili ngTest. f <#lin e=0>`__ |
1512 |
0.00 0020921 |
0.99% |
0.00 0000343 |
23.79x |
Measured Blocks¶
Name |
Calls |
Time |
F raction |
Max Time |
De viation |
|
---|---|---|---|---|---|---|
th umbnail count eq0| |
` <# eq0>`__ |
8 |
0.00 0068951 |
3.27% |
0.00 0069073 |
7.01x |
th umbnail count eq11| |
` <#e q11>`__ |
4 |
0.00 0001660 |
0.08% |
0.00 0001713 |
3.13x |
th umbnail count eq19| |
` <#e q19>`__ |
1006 |
0.00 0488026 |
23.15% |
0.00 0017513 |
35.10x |
th umbnail count eq21| |
` <#e q21>`__ |
1508 |
0.00 0506921 |
24.05% |
0.00 0015353 |
44.67x |
Equations¶
Name |
Variables |
---|---|
eq0 |
|
eq1 |
|
eq2 |
|
eq3 |
|
eq4 |
|
eq5 |
` <#var0>`__ |
eq6 |
` <#var0>`__ |
eq7 |
` <#var0>`__ |
eq8 |
` <#var0>`__ |
eq9 |
|
eq10 |
|
eq11 |
|
eq12 |
|
eq13 |
|
eq14 |
|
eq15 |
` <#var0>`__ |
eq16 |
` <#var0>`__ |
eq17 |
` <#var0>`__ |
eq18 |
` <#var0>`__ |
eq19 |
|
eq20 |
|
eq21 |
|
eq22 |
|
eq23 |
Variables¶
Name |
Comment |
---|---|
This is x |
|
This report was generated by OpenModelica on 2024-07-01 13:56:45.
Genenerated JSON for the Example¶
{
"name":"ProfilingTest",
"prefix":"ProfilingTest",
"date":"2024-07-01 13:56:45",
"method":"dassl",
"outputFormat":"mat",
"outputFilename":"ProfilingTest_res.mat",
"outputFilesize":24581,
"overheadTime":0.00015902,
"preinitTime":0.000118993,
"initTime":0.000129013,
"eventTime":0,
"outputTime":0.000137323,
"jacobianTime":5.03644e-06,
"totalTime":0.00210817,
"totalStepsTime":2.50258e-06,
"totalTimeProfileBlocks":0.00106556,
"numStep":499,
"maxTime":5.166258e-05,
"functions":[
{"name":"ProfilingTest.f","ncall":1512,"time":0.000020921,"maxTime":0.000000343}
],
"profileBlocks":[
{"id":0,"ncall":8,"time":0.000068951,"maxTime":0.000069073},
{"id":11,"ncall":4,"time":0.000001660,"maxTime":0.000001713},
{"id":19,"ncall":1006,"time":0.000488026,"maxTime":0.000017513},
{"id":21,"ncall":1508,"time":0.000506921,"maxTime":0.000015353}
]
}
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 138 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).