- Undocumented Matlab - https://undocumentedmatlab.com -
Improving Simulink performance
Posted By Yair Altman On February 12, 2014 | 3 Comments
A few days ago I happened to speak with a colleague about Simulink run-time performance, and we discussed various ideas for simulation speed-up. This topic is very important to MathWorks, as evidenced by a dedicated documentation section [1], newsletter articles (1 [2], 2 [3]), webinars (1 [4], 2 [5], 3 [6], 4 [7]) and multiple blog posts [8] on improving simulation performance using the Simulink product.
This blog covers mainly the Matlab core product and closely-related toolboxes. However, since the various suggestions for improving performance are spread across so many resources, I thought that it would be worthwhile to create a post listing all the suggestions in a single place. When faced with a slow simulation, it’s nice to know that there are so many available speed-up options, so I hope readers will find it useful. Note that these suggestions are in the large part fully documented and supported. The ideas are listed based on semantic relationship, and not by order of importance:
Matlab S-Function
and Interpreted Matlab Function
blocks. Instead, use Matlab Function
, System
and C-MEX
blocks.Matlab Function
refers to a subset of the Matlab language previously called Embedded Matlab
that can be directly converted into C-code without requiring the Matlab run-time (MCR); this is basically the language subset used by the Matlab Coder Toolbox. Interpreted Matlab Function
refers to the full Matlab functionality and requires the Matlab run-time (MCR) – it was previously called Matlab Function
.Some additional ideas can be found in the blog posts and webinars mentioned in the hyperlinks at the top of this post. One of the newsletter articles concludes [2] with an example of how applying some of these techniques to a specific model resulted in reduced simulation time, from 453 down to 5 seconds.
I would like to take this opportunity to congratulate MathWorks on a job well done with Simulink’s Performance Advisor. I expect a variant of this tool to be available for regular Matlab m-code in some future Matlab release; it would blend in nicely with the existing mlint (Code Analyzer) tool.
If this topic has piqued your interest, consider joining my Advanced Matlab Programming course [36] in London on 10-11 March, 2014. In this course/seminar I will explore numerous other ways by which we can improve Matlab’s performance and create professional code. This is a unique opportunity to take your Matlab skills to a higher level within a couple of days.
Categories: Low risk of breaking in future versions
Article printed from Undocumented Matlab: https://undocumentedmatlab.com
URL to article: https://undocumentedmatlab.com/articles/improving-simulink-performance
URLs in this post:
[1] documentation section: http://mathworks.com/help/simulink/#performance
[2] 1: http://www.mathworks.com/company/newsletters/articles/improving-simulation-performance-in-simulink.html
[3] 2: http://www.mathworks.com/company/newsletters/articles/improving-simulink-design-optimization-performance-using-parallel-computing.html
[4] 1: http://www.mathworks.com/videos/speeding-up-simulink-applications-81795.html
[5] 2: http://www.mathworks.com/videos/speeding-up-simulations-with-parallel-computing-81752.html
[6] 3: http://www.mathworks.com/videos/speeding-up-simulink-for-control-systems-applications-81736.html
[7] 4: http://www.mathworks.com/videos/speeding-up-simulink-for-signal-processing-applications-81748.html
[8] multiple blog posts: http://blogs.mathworks.com/seth/category/performance/
[9] Accelerator or Rapid Accelerator: http://www.mathworks.com/help/simulink/acceleration.html
[10] see here: http://www.mathworks.com/help/simulink/ug/comparing-performance.html
[11] Optimization pane: http://www.mathworks.com/help/simulink/gui/optimization-pane-general.html
[12] Compiler optimization: http://blogs.mathworks.com/seth/2010/10/28/tips-for-simulation-performance/
[13] options: http://www.mathworks.com/help/simulink/gui/simulation-target-pane-general.html
[14] similar configuration options: http://www.mathworks.com/help/stateflow/ug/speeding-up-simulation.html
[15] output scopes: http://www.mathworks.com/help/simulink/ug/scope-signal-viewer-characteristics.html
[16] batches: http://mathworks.com/help/dsp/ug/sample-and-frame-based-concepts.html
[17] R2011b and newer: http://mathworks.com/help/dsp/release-notes.html#bs1rpr_-1
[18] Mask Editor: http://www.mathworks.com/help/simulink/gui/mask-editor-overview.html
[19] loadable MAT files: http://www.mathworks.com/help/matlab/file-opening-loading-and-saving.html
[20] Limit or disable log output: http://www.linkedin.com/groups/Hi-Im-using-simulink-process-109866.S.192318533?view=&gid=109866&item=192318533
[21] Simulink Profiler: https://www.mathworks.com/help/simulink/ug/how-profiler-captures-performance-data.html
[22] Simulink Model Performance Advisor: http://www.mathworks.com/help/simulink/automatic-performance-optimization.html
[23] R2012b and newer: http://blogs.mathworks.com/seth/2012/11/21/automatically-improving-model-performance/
[24] this webinar: http://www.mathworks.com/videos/simulation-analysis-and-performance-74976.html
[25] faster solver: http://www.mathworks.com/help/gads/choose-a-solver.html
[26] here: http://www.mathworks.com/help/releases/R2012a/toolbox/simulink/ug/f11-69449.html
[27] Tune solver parameters: http://blogs.mathworks.com/seth/2012/06/04/the-most-useful-command-for-debugging-variable-step-solver-performance/
[28] reported: http://blogs.mathworks.com/seth/2012/06/04/the-most-useful-command-for-debugging-variable-step-solver-performance/#comment-1850
[29] excessive zero-crossing: http://blogs.mathworks.com/seth/2013/04/26/zero-crossing-detection-what-are-your-options/
[30] here: http://www.mathworks.com/help/simulink/ug/simulating-dynamic-systems.html#bridiag-5
[31] here: http://www.mathworks.com/help/stateflow/ug/when-to-enable-zero-crossing-detection.html
[32] Store the simulation state: http://www.mathworks.com/help/simulink/ug/saving-and-restoring-the-simulation-state-as-the-simstate.html
[33] Run simulations in parallel: http://www.mathworks.com/help/simulink/ug/running-parallel-simulations.html
[34] here: http://blogs.mathworks.com/seth/2009/03/31/parallel-computing-with-simulink-model-reference-builds/
[35] here: http://blogs.mathworks.com/seth/2010/10/17/parallel-computing-with-simulink-running-thousands-of-simulations/
[36] Advanced Matlab Programming course: http://undocumentedmatlab.com/training/advanced-matlab-seminars-london-10-14-march-2014/
[37] Improving fwrite performance : https://undocumentedmatlab.com/articles/improving-fwrite-performance
[38] Improving save performance : https://undocumentedmatlab.com/articles/improving-save-performance
[39] Simulink Data Dictionary : https://undocumentedmatlab.com/articles/simulink-data-dictionary
[40] Improving graphics interactivity : https://undocumentedmatlab.com/articles/improving-graphics-interactivity
[41] Callback functions performance : https://undocumentedmatlab.com/articles/callback-functions-performance
[42] Some Matlab performance-tuning tips : https://undocumentedmatlab.com/articles/some-performance-tuning-tips
[43] : http://www.mathworks.com/help/rtw/block-authoring-with-tlc.html
[44] : http://dali.feld.cvut.cz/ucebna/matlab/toolbox/rtw/tlcquick.html
[45] : http://dali.feld.cvut.cz/ucebna/matlab/pdf_doc/rtw/tlc_ref.pdf
Click here to print.
Copyright © Yair Altman - Undocumented Matlab. All rights reserved.
3 Comments To "Improving Simulink performance"
#1 Comment By Etienne On February 16, 2014 @ 13:27
I would appreciate any advice on speeding up mexCallMatlab functionality. At the moment I have a fortran mex function that calls a Matlab function via mexCallMatlab, that then calls the derivative values of a Simulink model. This is painfully slow and I am trying to figure out how to write a TLC script that can generate C-code from the Simulink model in the correct format, so that I can avoid mexCallMatlab all together, but the TLC functionality is not very well documented as far as I can tell.
#2 Comment By Yair Altman On February 16, 2014 @ 16:03
@Etienne – perhaps you haven’t looked close enough? I think that TLC is actually extensively documented [43]. If this is not enough, then there is also a [44] and even a 340-page [45] (which is admittedly quite old). I can’t vouch for the quality of the documentation as I’ve never used TLC, but at least judging by the quantity, reading all of it should keep you busy for quite some time…
#3 Comment By Etienne On February 17, 2014 @ 14:17
Thanks Yair.