Use Performance Advisor checks to improve model simulation time.
Establish a measurement to compare the performance of a simulation after Performance Advisor implements improvements.
These checks require that Update Diagram occurs in order to run.
These checks require simulation to run in order to collect sufficient performance data. Performance Advisor reports the results after simulation completes.
These checks evaluate simulation modes (Normal, Accelerator, Rapid Accelerator, Rapid Accelerator with up-to-date check off) and identify the optimal mode to achieve fastest simulation.
Use these checks to select compiler optimization settings for improved performance.
Select this check to create a baseline when Performance Advisor runs. You can also create a baseline manually. A baseline is the measurement of simulation performance before you run checks in Performance Advisor. The baseline includes the time to run the simulation and the simulation results (signals logged). Before you create a baseline for a model, in the Data Import/Export pane of the Configuration Parameters dialog box:
Select the States check box.
Set the Format parameter to
To improve simulation speed, disable diagnostics where possible. For example, some diagnostics, such as Solver data inconsistency or Array bounds exceeded, incur run-time overheads during simulations.
To improve simulation speed, enable optimizations where possible. For example, if some optimizations, such as Block Reduction, are disabled, enable these optimizations to improve simulation speed.
You can also trade off compile-time speed for simulation speed by setting the compiler optimization level. Compiler optimizations for accelerations are disabled by default. Enabling them accelerates simulation runs but results in longer build times. The speed and efficiency of the C compiler used for Accelerator and Rapid Accelerator modes also affects the time required in the compile step.
To improve simulation speed, use properly configured lookup table blocks.
In general, to improve simulation speed, choose
generation for the Simulate using parameter
of the MATLAB System block. Because
data exchange between MATLAB® and Simulink® passes through
several software layers,
Interpreted execution usually
slows simulations, particularly if the model needs many data exchanges.
This check identifies which MATLAB System blocks can generate
code and changes the Simulate using parameter
Code generation where possible.
Code generation does not support
all MATLAB functions, the subset of the MATLAB language
that it does support is extensive. By using this
generation, you can improve performance.
To improve simulation speed, replace Interpreted MATLAB Function blocks with MATLAB Function blocks where possible. Because data exchange between MATLAB and Simulink passes through several software layers, Interpreted MATLAB Function blocks usually slow simulations, particularly if the model needs many data exchanges.
While MATLAB Function blocks do not support all MATLAB functions, the subset of the MATLAB language that it does support is extensive. By replacing your interpreted MATLAB code with code that uses only this embeddable MATLAB subset, you can improve performance.
To improve simulation speed, disable simulation target settings where possible. For example, in the Configuration Parameters dialog box, clear the Simulation Target > Echo expression without semicolons check box to improve simulation speed.
To improve simulation speed, in the Configuration Parameters
dialog box, verify that the Model Referencing > Rebuild parameter is set to
any changes in known dependencies detected.
Opened and uncommented Scope blocks can impact simulation performance. To improve simulation performance, close and comment out Scope blocks. Right-click a scope block, and then select Comment Out.
For opened Scopes, you can improve simulation speed by reducing updates. From the Scope Simulation menu, select Reduce Updates to Improve Performance.
Identify active instrumentation settings on the model. The fixed-point instrumentation mode controls which objects log minimum, maximum, and overflow data during simulation. Instrumentation is required to collect simulation ranges using the Fixed-Point Tool. These ranges are used to propose data types for the model (requires Fixed-Point Designer™). When you are not actively converting your model to fixed point, disable the fixed-point instrumentation to restore the maximum simulation speed to your model.
From the model Analysis menu, select Data Type Design > Fixed-Point Tool. Under System under design, click Continue.
In the Model Hierarchy pane, the Fixed-Point Tool denotes systems that currently have
instrumentation turned on with
Right-click the system in the model hierarchy and, under
instrumentation mode, select
Use local settings
Fixed-Point Instrumentation and Data Type Override (Fixed-Point Designer)
To improve simulation, verify the number of referenced models in the model. If there are two or more referenced models, build the model in parallel if possible.
Performance Advisor analyzes the model and estimates the build time on the current computer as if it were using several cores. It also estimates the parallel build time for the model in the same way an estimation would be performed if Parallel Computing Toolbox™ or MATLAB Distributed Computing Server™ software were installed on the computer. Performance Advisor performs this estimate as follows:
Search the model for referenced models that do not refer to other referenced models.
Calculate the average number of blocks in each of the referenced models that do not refer to other referenced models.
Of the list of referenced models that do not refer to others, select a referenced model whose number of blocks is closest to the calculated average.
Build this model to obtain the build time.
Based on the number of blocks and the build time for this referenced model, estimate the build time for all other referenced models.
Based on these build times, estimate the parallel build time for the top model.
To calculate the overhead time introduced by the parallel build mechanism, set the Parallel Build Overhead Time Estimation Factor. Performance Advisor calculates the estimated build time with overhead as:
(1 + Parallel Build Overhead Time Estimation Factor)*(Build time on a single machine)
To improve simulation, check that each Delay block in the model uses the appropriate buffer type. By default, the block uses an array buffer (the Use circular buffer for state option is not selected). However, when the delay length is large, a circular buffer can improve execution speed by keeping the number of copy operations constant.
If the Delay block is currently using an array buffer, and all of the following conditions are true, Performance Advisor selects a circular buffer:
The Delay block is in sample-based
mode, i.e,either the Input processing parameter
is set to
Elements as channels (sample based),
or the input signal type is set to
The value or upper limit of the delay length is 10 or greater.
The size of the state—equal to the delay length multiplied by the total of all output signal widths—is 1000 or greater.
If your model contains both discrete and continuous rates, the coupling between these rates can slow down simulation. Performance Advisor checks for these conditions in your model.
The model is using a variable step solver.
The model contains both continuous and discrete rates.
The fastest discrete rate is relatively smaller than Max step size determined by the solver.
DecoupledContinuousIntegration parameter to
on might speed up simulation.
Run this check if your simulation has many unnecessary resets. A discrete signal driving a block with continuous states triggers a reset at every sample time hit of the block. These resets are computationally expensive. Performance Advisor checks for these signals and blocks and provides a list of the same.
You can edit the model around the discovered discrete signals that drive these blocks to remove such cases. For example, inserting a Zero Order Hold block between the discrete signal and the corresponding block with continuous states might help resolve the issue.
To improve simulation, check that the model uses the appropriate solver type.
Selecting a solver depends on the approximation of the model stiffness at the beginning of the simulation. A stiff system has both slowly and quickly varying continuous dynamics. Implicit solvers are specifically designed for stiff problems, whereas explicit solvers are designed for non-stiff problems. Using non-stiff solvers to solve stiff systems is inefficient and can lead to incorrect results. If a non-stiff solver uses a very small step size to solve your model, check to see if you have a stiff system.
|Represents a stiff system||ode15s|
|Does not represent a stiff system||ode45|
Performance Advisor uses the heuristic shown in the table to choose between explicit and implicit solvers.
|Original Solver||Performance Advisor Action|
|Variable step solver|
Calculates the system stiffness at 0 first. Then:
|Fixed-step continuous solver|
This heuristic works best if the system stiffness does not vary during simulation. If the system stiffness varies with time, choose the most appropriate solver for that system rather than the one Performance Advisor suggests.
To achieve fastest simulation time, use this check to evaluate the following modes and identify the optimal selection:
Rapid Accelerator with up-to-date check off
In Normal mode,Simulink interprets your model during each simulation run. If you change the model frequently, this is generally the preferred mode to use because it requires no separate compilation step. It also offers the most flexibility to make changes to your model.
In Accelerator mode,Simulink compiles a model into a binary shared library or DLL where possible, eliminating the block-to-block overhead of an interpreted simulation in Normal mode. Accelerator mode supports the debugger and profiler, but not runtime diagnostics.
In Rapid Accelerator mode, simulation speeds are fastest but this mode only works with models where C-code is available for all blocks in the model. Also, this mode does not support the debugger or profiler.
When choosing Rapid Accelerator with up-to-date check off, Performance Advisor does not perform an up-to-date check during simulation. You can run the Rapid Accelerator executable repeatedly while tuning parameters without incurring the overhead of up-to-date checks. For instance, if you have a large model or a model that makes extensive use of model reference, this method of execution can increase efficiency.
For models with 3–D signals, Normal or Accelerator modes work best.
Use this check to determine whether performing compiler optimization can help improve simulation speed. The optimization can only be performed in Accelerator or Rapid Accelerator modes.
This check will be skipped if MATLAB is not configured to use an optimizing compiler.
This check validates the overall performance improvement of simulation time and accuracy in a model. If the performance is worse than the original model, Performance Advisor discards all changes to the model and loads the original model.
Global settings for validation do not apply to this check. If you have not validated the performance improvement from changes resulting from other checks, use this check to perform a final validation of all changes to a model.