Main Content

Solver Profiler

Identify solver performance bottlenecks

Description

Use the Solver Profiler to examine solver and model behavior to identify issues that can contribute to poor simulation performance.

Use the Solver Profiler to analyze a model for patterns that affect its simulation. The Solver Profiler presents graphical and statistical information about the simulation, solver settings, events, and errors. You can use this data to identify locations in the model that caused simulation bottlenecks.

In addition, there are multiple factors that can limit the simulation speed. The Solver Profiler logs and reports all the major events that occur when simulating a model:

  • Zero-crossing events

  • Solver exception events

  • Solver reset events

  • Jacobian computation events

These events are common and necessary for an accurate simulation. However, they do incur computational cost and frequent occurrences can slow down or even stall the simulation.

Available actions

  • Trace

  • Configure

  • Explore

Information Panes

  • Statistics

  • Step Size

  • Suggestions

Open the Solver Profiler

Open the Solver Profiler by clicking the hyperlink in the lower-right corner of the Simulink® Editor.

Examples

expand all

This example shows how to find the source of particular solver events or zero-crossings using a model that simulates a ball bouncing off the ground. As the ball comes to rest, the density of zero-crossings increase, leading to a solver slowdown.

To begin, open the ex_spi_show_zc model, click Debug, open the drop down menu of Performance Advisor, select Solver Profiler.

Click Run to profile the model.

Notice that the model has 45 Zero Crossing events. To obtain more details, click Total zero crossing from Statistic pane or Zero Crossing tab from the suggestion pane to bring the zero-crossing table to the front. From the Zero Crossing tab, you will notice that the ex_spi_show_zc/Switch block caused all 45 zero crossing events. Click ex_spi_show_zc/Switch from the table, all zero crossing events are shown on the Step Size plot as yellow dots.

If you click on the Highlight Block from the Trace tab, you will notice that the ex_spi_show_zc/Switch block causes the zero crossing events to be highlighted in the model. All zero crossing events caused by the Switch block are highlighted in the Step Size plot.

Related Examples

Parameters

Configure

Time, in seconds, of the simulation that the profiler starts analyzing the model. This is not the same as the start time of the simulation.

Time, in seconds, of the simulation to which the profiler should profile the model. By default, the analysis continues until the end of the simulation. Changing this parameter does not change the stop time of the model which you specify in the Model Configuration Parameters.

A value less than the configured stop time of the model stops the profiling and simulation at StopTime.

Maximum number of events that are logged. If the number of logged events reaches this value and memory is available, increase BufferSize. If memory is limited, consider lowering the value.

By default, the profiler does not save the states of the model. Enabling this parameter configures the profiler to save the states to the profiler data MAT file.

If you select this parameter, it will enable the States explorer.

Enable this parameter to save Simscape states to the profiler data MAT file.

If you select this parameter, it will enable the Simscape explorer.

Enable this parameter to save zero crossing information to the profiler data MAT file

If you select this parameter, it will enable the Zero-Crossing explorer.

Option to log the solver Jacobian matrices to memory. This option is useful for simulations that use implicit solvers. For a comparison of solvers, see Compare Solvers.

For a more detailed explanation of the solver Jacobian, see Choose a Jacobian Method for an Implicit Solver.

Log stiffness analysis Simscape states, specified as an array. This parameter provides an array of time points that you want to log the Simscape Stiffness states to the profiler data MAT file. Enable this parameter to show Simscape Stiffness tab in the Suggestion Pane. 

Enable this parameter to log the stiffness analysis of Simscape states to the profiler data MAT file. For more information on Simscape representation of stiffness and other physical system concepts, see How Simscape Models Represent Physical Systems (Simscape)

Click Rule Customization in the Solver Profiler to access the rule set. You can change the thresholds for most of these rules and also select which rules you want to apply selectively during a simulation run.

To modify a rule, enable its customization and then enter a desired threshold value.

Custom Rule Set

You can override the settings on the Rule Set dialog box by specifying a custom rule set.

Create a rule set as a MATLAB® script and specify the path to the script in the Custom Rule Set section of the Rule Set dialog box.

A simple rule set example looks as follows:

function diagnosticsString = customRule(profilerData)
		if isempty(profilerData.zcEvents)
			diagnosticsString{1} = 'No zero crossing event detected.';
		else
			diagnosticsString{1} = 'Zero-crossing events detected.';
		end
end
The input to the function is an array of structures called profilerData. This array of structures organizes all the information that the Solver Profiler collects during a profiling run. It contains the following substructures.

SubstructureFields
stateInfo: Stores information on block states
  • name: Block name

  • value: State values

  • blockIdx: Block ID

blockInfo: Cross-reference of blocks and state IDs
  • name: Block name

  • stateIdx: State ID

zcSrcInfo: Stores information on blocks causing zero crossing events
  • name: Block name

  • blockIdx: Block ID

zcEvents: Cross-reference of the time stamps of zero crossing events and the corresponding state IDs
  • t: Event timestamp

  • srcIdx: Block ID

exceptionEvents: Cross-reference of exception event timestamps, the ID of the corresponding state that caused the event, and the cause.
  • t: Event timestamp

  • stateIdx: State ID

  • cause: Cause of exception

resetTime: Stores timestamps of solver resets.None
tout: Stores simulation times.None

View

Enable this parameter to highlight solver exception events in the Step Size plot of the Solver Profiler.

Enable this parameter to highlight solver reset events in the Step Size plot of the Solver Profiler.

Enable this parameter to highlight Jacobian update events in the Step Size plot of the Solver Profiler.

Enable this parameter to highlight zero crossing events in the Step Size plot of the Solver Profiler.

Version History

Introduced in R2016a