Main Content

Manage Simulation Targets for Referenced Models

A simulation target, or SIM target, is an automatically generated MEX-file that implements a referenced model that executes in accelerator mode. Simulink® invokes the simulation target as needed during simulation to compute the behavior and outputs of the referenced model. Simulink uses the same simulation target for all instances of the referenced model that execute in accelerator mode. Instances of the referenced model that execute in normal mode do not use the simulation target.

To create model reference simulation targets, Simulink generates code that imposes some requirements and limitations on referenced models that execute in accelerator mode. Aside from these constraints, you can generally ignore simulation targets when you execute a referenced model in accelerator mode. For information on these constraints, see Choose Simulation Modes for Model Hierarchies.

By default, Simulink generates the simulation target for a referenced model that executes in accelerator mode if:

  • The simulation target does not exist when you update the diagram of a direct or indirect parent of the referenced model or simulate the model hierarchy.

  • The simulation target is out of date with structural changes in the referenced model.

While generating a simulation target, the MATLAB® command window displays status messages so that you can monitor the simulation target generation process.

To programmatically build a model reference simulation target, use the slbuild function.

Note

If you have a Simulink Coder™ license, be careful not to confuse the simulation target of a referenced model with these other types of targets:

  • Hardware target — A platform for which Simulink Coder generates code

  • System target — A file that tells Simulink Coder how to generate code for particular purpose

  • Rapid Simulation target (RSim) — A system target file supplied with Simulink Coder

  • Model reference target — A library module that contains Simulink Coder code for a referenced model

Reduce Time Spent Checking for Changes

You can reduce the time that Simulink spends checking whether simulation targets require rebuilding by setting configuration parameter values as follows:

  • In all referenced models throughout the hierarchy, set the Signal resolution configuration parameter to Explicit only or None.

  • In the top model of the model hierarchy, set the Rebuild configuration parameter to If changes in known dependencies detected. Alternatively, you can use this parameter to specify that Simulink always or never rebuilds simulation targets.

These parameters exist in the configuration set of the model; they are not parameters of the Model block. Setting these parameters for any instance of a referenced model sets it for all instances of that model.

Specify Programming Language of Simulation Targets

To specify the programming language for model reference simulation targets, use the Language configuration parameter on the Simulation Target tab of the Configuration Parameters dialog box.

Use Custom Code for Simulation Targets

To use custom code with Stateflow® or with MATLAB Function blocks when building a model reference simulation target, use the Include custom code for referenced models configuration parameter.

Caution

Using custom code for referenced models in accelerator mode can produce different results than when you simulate the model without using custom code. If the custom code includes declarations of structures for buses or enumerations, the simulation target generation fails if the build results in duplicate declarations of those structures. Also, if custom code uses a structure that represents a bus or enumeration, you can get unexpected simulation results.

Control Location of Simulation Targets

Simulink creates simulation targets in the slprj build folder of the current folder. If the slprj folder does not exist, Simulink creates it.

Note

Simulink Coder code generation also uses the slprj folder. Subfolders in slprj provide separate places for simulation code, Simulink Coder code, and other files. For details, see Manage Build Process Folders (Simulink Coder).

You can place generated files in a different root folder than the current working folder. This option allows you to:

  • Store generated files separate from the models and other source materials used to generate them.

  • Reuse or share previously built simulation targets without having to set the current working folder to a previous working folder.

  • Separate generated simulation artifacts from generated production code.

The simulation cache folder is the root folder in which to place artifacts used for simulation.

To specify a simulation cache folder to use instead of the current folder (pwd), in the Simulink Preferences > General dialog box, set the Simulation cache folder by entering or browsing to a folder path.

Simulation cache folder option in Simulink Preferences dialog box

This preference provides the initial defaults for MATLAB session parameters.

Alternatively, you can set the CacheFolder MATLAB session parameter using the set_param function.

>> set_param(0, 'CacheFolder', fullfile('C:','Work','MyModelSimCache'))
>> get_param(0, 'CacheFolder')
ans =

C:\Work\MyModelSimCache

To override or restore the Simulation cache folder preference only for the current MATLAB session, use the Simulink.fileGenControl function. The values you set using Simulink.fileGenControl expire at the end of the current MATLAB session.

Related Topics