Main Content

Choose Simulation Modes for Model Hierarchies

When you simulate a model hierarchy, you should consider how top models and referenced models execute.

  • Top model — Supports all Simulink® simulation modes. To speed up execution of a top model, you can use Simulink accelerator or rapid accelerator mode.

  • Referenced model — Although you can specify any simulation mode for a model, when you reference that model, the Model block for each instance of the referenced model controls the simulation mode of the instance. The simulation mode of a parent model can override the simulation mode of a Model block.

For information on simulation modes, see Choosing a Simulation Mode and How Acceleration Modes Work.

For information on selecting solvers for models in a model hierarchy, see Set Configuration Parameters for Model Hierarchies.

Model Reference Simulation Modes

You can specify any of these simulation modes for a Model block:

  • Normal

  • Accelerator

  • Software-in-the-loop (SIL) — requires Embedded Coder®

  • Processor-in-the-loop (PIL) — requires Embedded Coder

When you choose between normal and accelerator mode, you must make a tradeoff between flexibility and speed. Normal mode supports more Simulink and Stateflow® features in referenced models, such as scopes, port value display, and debugging tools. Accelerator mode supports fewer features in referenced models, but simulates model hierarchies faster.

Modeling RequirementNormal ModeAccelerator Mode
Simulation speed

Models execute slower in normal mode than accelerator mode. However, referenced models that execute in normal mode do not delay simulation to build and compile simulation targets because normal mode executes referenced models interpretively.

Models execute faster in accelerator mode than normal mode. Before simulating the model, Simulink must build and compile simulation targets, which can be undesirable for prototyping. For more information, see Manage Simulation Targets for Referenced Models.

Debugging

With the Simulink Debugger, you can set a breakpoint inside a referenced model that executes in normal mode. For more information, see Debug Simulations Programmatically.

With the Simulink Profiler, you can enable profiling for a referenced model that executes in normal mode. Enabling profiling on a parent model does not enable profiling for referenced models. See How Simulink Profiler Captures Performance Data.

For referenced models that execute in accelerator mode, specifications made and actions taken by the Simulink Debugger and Simulink Profiler are ignored.

Testing

Simulink Coverage™ model coverage analysis supports referenced models that execute in normal mode.

Simulink Coverage model coverage analysis ignores referenced models that execute in accelerator mode.

Tunability of parameters during simulation

When a referenced model simulates only in normal mode, you can tune:

  • Parameter values in the referenced model, for example, for a Gain block that has Gain set to 5, you can change the value of Gain from 5 to 10

  • Parameter values specified by MATLAB® variables and Simulink.Parameter objects in the base workspace, a data dictionary, or the model workspace

  • Model arguments

When one or more Model blocks simulate a referenced model in accelerator mode, you can tune:

  • Parameter values specified by MATLAB variables and Simulink.Parameter objects in the base workspace or a data dictionary

  • Model arguments

For more information, see Referenced Models.

Data logging

Data logging provides extensive support for referenced models that execute in normal mode.

For referenced models that execute in accelerator mode, To Workspace blocks log data only if they use the Timeseries format for saving.

Data visualization

You can view simulation results for all instances of the referenced model with the Simulation Data Inspector.

You can view instance-specific simulation results for each instance with Display blocks in the referenced model.

Scopes and port value labels display data for only the instance of the referenced model that has normal mode visibility enabled. For more information, see Simulate Multiple Referenced Model Instances in Normal Mode.

You can view simulation results for all instances of the referenced model with the Simulation Data Inspector.

These visualization methods show no data for referenced models that execute in accelerator mode.

  • Scope, Floating Scope, and Scope Viewer blocks in the referenced model

  • Runtime displays, such as port value labels

Top model Scope blocks can display data for referenced models that execute in accelerator mode if you use the Viewers & Generators Manager to add test points in the referenced model. Adding or removing a test point requires rebuilding the model reference simulation target for a model.

Diagnostics

Configuration parameter settings are applied as specified.

For models referenced in accelerator mode, Simulink can ignore some configuration parameter settings. For details, see Diagnostics That Are Ignored in Accelerator Mode.

Runtime checks

Runtime checks are enabled.

Some blocks include runtime checks that are disabled when you include the block in a referenced model in accelerator mode. Examples of these blocks include Assignment, Selector, MATLAB Function, and MATLAB System blocks.

Linearization analysis and optimization

Normal mode allows block-by-block linearization of a referenced model, which achieves an accurate linearization.

In accelerator mode, discrete states of model references are not exposed to linearization. These discrete states are not perturbed during linearization and, therefore, are not truly free in the trimming process.

The outputs of random blocks are not kept constant during trimming. Outputs that are not kept constant can affect the optimization process.

Extrinsic functions

A MATLAB Function block in a referenced model that executes in normal mode can call MATLAB functions that are declared extrinsic for code generation.

A MATLAB Function block in a referenced model that executes in accelerator mode cannot call MATLAB functions that are declared extrinsic for code generation.

S-Functions

Referenced models that execute in normal mode support more S-functions than referenced models that execute in accelerator mode. For more information see, S-Functions in Referenced Models.

Referenced models that execute in accelerator mode support fewer S-functions than referenced models that execute in normal mode. For more information see, S-Functions in Referenced Models.

SIL and PIL simulation modes execute referenced models by generating production code for embedded processors. SIL mode provides a convenient alternative to PIL simulation because it can run on a host platform when the target hardware is not available. For more information, see SIL and PIL Simulations (Embedded Coder).

Overridden Simulation Modes

The simulation mode of the parent model can override the simulation mode of a Model block. This table shows which simulation mode the software uses for a referenced model instance based on the simulation mode of the parent model and related Model block.

Simulation Mode Used by Parent ModelSimulation Mode of Model Block
NormalAccelerator
Normal

Compatible — Referenced model simulates in normal mode.

Compatible — Referenced model simulates in accelerator mode.

Accelerator

Overridden — Referenced model simulates in accelerator mode.

Compatible — Referenced model simulates in accelerator mode.

Rapid accelerator (top model only)

For information on SIL and PIL, see Simulation Mode Override Behavior in Model Reference Hierarchy (Embedded Coder).

To manually override model reference simulation modes without dirtying any models, see Override Model Reference Simulation Modes.

Related Topics