# 5 Resources for Simulation Performance8

Posted by Seth Popinchalk,

Following Guy's recent post with Tips for Simulation Performance, I thought I would provide a couple links for additional resources. Here they are:

The Simulink Performance Master Class

Earlier this year some of my colleagues put together a collection of tips and examples of how to speed up Simulink. They organized it into a 3 hour master class and presented it to many audiences around the world. For those of you who have not seen the live interactive presentation, we have a shortened one hour version available as a webinar. Each of these takes an example model and makes simple modifications that speed up Simulink.

Speeding Up Simulink for Control Systems Applications
Speeding Up Simulink for Signal Processing Applications

If you would like to have the MathWorks present the more detailed 3 hour version at your site, please contact your account manager for more information. (If you don't know who that is, just call the MathWorks!)

Parallel Computing Toolbox and Simulink

Another technique for improving simulation performance is to use parallel computing to break up your problem. I have written about this in previous posts about parallel model-reference build and parallel simulation. There is also a webinar entitled Speeding up your Simulations with Parallel Computing. I recommend watching this if you have never used parallel computing and want to see an overview of how it can be incorporated into your simulation workflows.

Technical Note 1806

The technical support website contains the Simulink Performance and Memory Management Guide. The guide tries to answer some common questions like:

• Why do I get 'Out of Memory' Errors in Simulink?
• How do I Avoid Out of Memory Errors in Simulink?
• Why is my Simulink Model Running Slowly?
• How can I manage memory usage to allow code generation with very large models in Real-Time Workshop?

Some of the material is focused on techniques that apply to older releases of MATLAB, but many of the basic concepts about efficient simulation still apply.

The Documentation on Solver Selection

An often overlooked resource for simulation performance tips is the Simulink documentation. I specifically recommend the section on Choosing a Solver. If you don't have the best solver settings for your system it can be inefficient at best, or worse, you may get the wrong answer. Everyone using Simulink can benefit from skimming that section of the documentation.

Adopting Model-Based Design Tech Kit

Parasar Kodati, a regular contributor to this blog, wrote a guest post about Adopting Model-Based Design. In that post he announced the Adopting Model-Based Design interactive kit. This kit is a collection of links and white papers on topics related to Model-Based Design. There is even a section on optimizing simulation performance.

Now It's Your Turn

Do you have any resources you use to get Simulink performance? Share them with a comment here.

## 8 CommentsOldest to Newest

Bob replied on : 1 of 8

This felt very timely. I had just gotten an email from a colleague complaining about running out of memory with a Simulink model, and then I saw that your post mentioned Tech Note 1806 about “How do I avoid out of memory errors in Simulink?”

I sent him a link to the post, and he came back with “Well, it all seems to be out of date.” He tried the MATLAB_MEM_MGR suggested in Tech Note 1806 using R2009b, and it spit out:

Warning: Changing the memory manager using any of the following is deprecated:
the '-memmgr' command line switch
the '-check_malloc' command line switch
the 'MATLAB_MEM_MGR' environment variable
Support for these settings will be removed in a future release.
Warning: Using the 'native' memory manager.


How often do these tech notes get reviewed & updated? How far back do you preserve information? (Do you mark it as this advice is useful in R12-R14 SP2, or do you just remove it if it no longer applies to the latest release?)

Seth Popinchalk replied on : 2 of 8

@Bob – I am glad the information was timely, and I am sorry it is also a bit out of date. We review the tech-note information as we use it and update it as needed, however, I don’t think we have done much review of 1806 recently. I’ll take a look through it and get it updated soon. Thanks!

Mahaboob Basha Qureshi replied on : 3 of 8

Dear sir,
I have tried to draw the simulation of TCSC to subsynchronous resonance in power system. please help me in this matter

Seth Popinchalk replied on : 4 of 8

@Mahaboob Basha Qureshi – I reccomend you post your question to the MATLAB Newsgroup.

Paul J. replied on : 5 of 8

Seth,

I just came across an interesting aspect of simulation performance that I hadn’t fully appreciated and I don’t fully understand.

I have a model with four identical masked subsystems. Each masked subsystem takes a single parameter which is a structure. The parameter pane of the mask editor has Tunable unchecked for the parameter (though this hasn’t seemed to make a difference one way or the other). One field of the structure parameter is an Nx4 array and the other is an Nx1 array. Each of these is a parameter in a Constant Block (there are a few other blocks in the subsystem, but the profiler showed the constant block with the Nx4 near the top of the list). I’ve been experimenting with running the simulation in four different configurations and got the following run time measurements:

parameter defined in base workspace, Inline Parameters On: 1.06 seconds

parameter defined in model workspace, Inline Parameters On: 1.8 seconds

parameter defined in base workspace, Inline Parameters Off: 7.7 seconds

parameter defined in base workspace, Inline Parameters Off: 9.2 seconds.

Based on this, perhaps you can help with the following:

0. Is this expected behavior (assuming I gave enough information)? If this is the case, is the reason just the inlining or is it really that in this simple model with inlining on, the optimization can honor the inf sample time of the constant blocks? In other words, would inlining not show this performance benefit if the output of the constant block were connected to the output of a conditionally executed system (for example)?

1. Why is there extra overhead with using the model workspace?

2. What is the purpose of the Tunable check box in the mask editor paramteter pane? It didn’t seem to do anything in my example.

3. My understanding is that Model Workspace variables are not tunable. If this is the case, why aren’t Model Workspace variables automatically inlined? Maybe this would cause problems for Reference Model Arguments?

4. I don’t want to ever change any parameters during a simulation. Consequently, is there any reason to not have Inline Parameters On? Assuming that ALL of my model parameters are defined in the Model Workspace, does having Inline Parameters On or Off have any implications as to whether or not an Accelerator rebuild is necessary if a parameter in the model workspace changes (e.g., through an hws.assignin command)?

5. How does Inline Parameters work relative to Embedded Function parameter inputs? Suppose that Inline Parameters is checked in the model configuration and an Embedded Function parameter is checked as Tunable? Which takes precedence?

As always, Thanks!

Paul

Paul J. replied on : 6 of 8

Seth,

I forgot to mention that all of my timing experiments were in Normal mode. Do you think that relative timing would change in Accelerator mode?

Paul

I’m also quite interested in the answers to Pauls questions…

However, there seems to be a reason for not using inline parameters when never changing the parameters: I’m just working on a model that only behaves as expected when built using noninline parameters. Unfortunately, I currently have no idea about the reason.

Paul J. replied on : 8 of 8

@Eike, one possibility: when you inline paramters, the sample times of Constant blocks (can) change from FiM to Inf. This can affect blocks downstream with inherited sample times. I thought I saw a bug report with an example of this behavior, but I can’t find it right now. Anyway, if you don’t have the the Sample Times/Colors displayed, you might want to try that and see if any issues pop out.

What is 1 + 7?

Preview: hide

These postings are the author's and don't necessarily represent the opinions of MathWorks.