Skip to Main Content Skip to Search
Product Documentation

Model Reference Simulation Targets

About Simulation Targets

A simulation target, or SIM target, is a 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 Accelerator mode instances of a given referenced model anywhere in a reference hierarchy.

Be careful not to confuse the simulation target of a submodel with any of these other types of target:

Simulink creates a simulation target only for a submodel that has one or more Accelerator mode instances in a reference hierarchy. A submodel that executes only in Normal mode always executes interpretively and does not use a simulation target. When one or more instance of a submodel executes in Normal mode, and one or more instance executes in Accelerator mode:

Because Accelerator mode requires code generation, it imposes some requirements and limitations that do not apply to Normal mode. Aside from these constraints, you can generally ignore simulation targets and their details when you execute a referenced model in Accelerator mode. See Limitations on Accelerator Mode Referenced Models for details.

Building Simulation Targets

Simulink by default generates the needed target from the referenced model:

If the simulation target already exists, then by default Simulink checks whether the submodel has structural changes since the target was last generated. If so, Simulink regenerates the target to reflect changes in the model. For details about how Simulink detects whether to rebuild a model reference target, see the Rebuild parameter documentation.

You can change this default behavior to modify the rebuild criteria or specify that Simulink always or never rebuilds targets. See Rebuild for details.

To generate simulation targets interactively for Accelerator mode referenced models, do one of these steps:

While generating a simulation target, Simulink displays status messages at the MATLAB command line to enable you to monitor the target generation process. Target generation entails generating and compiling code and linking the compiled target code with compiled code from standard code libraries to create an executable file.

Reducing Change Checking Time

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

These parameter values exist in the configuration set of a referenced model, not in the individual Model block, so setting either value for any instance of a referenced model sets it for all instances of that model.

Simulation Target Output File Control

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

By default, the files generated by Simulink diagram updates and model builds are placed in a build folder, the root of which is the current working folder (pwd). However, in some situations, you might want the generated files to go to a root folder outside the current working folder. For example:

You might also want to separate generated simulation artifacts from generated production code.

To allow you to control the output locations for the files generated by diagram updates and model builds, the software allows you to separately specify the simulation cache folder build folder. The simulation cache folder is the root folder in which to place artifacts used for simulation.

To specify the simulation cache folder, use one of these approaches:

Controlling the Output Location for Model Build Artifacts Used for Simulation

The Simulink preference Simulation cache folder provides control over the output location for files generated by Simulink diagram updates. The preference appears in the Simulink Preferences Window, Main Pane, in the File generation control group. To specify the root folder location for files generated by Simulink diagram updates, set the preference value by entering or browsing to a folder path, for example:

The folder path that you specify provides the initial default for the MATLAB session parameter CacheFolder. When you initiate a Simulink diagram update, any files generated are placed in a build folder at the root location specified by CacheFolder (if any), rather than in the current working folder (pwd).

For example, using a 32-bit Windows host platform, if you set the Simulation cache folder to 'C:\Work\mymodelsimcache' and then simulate the demo model rtwdemo_capi, files are generated into the specified folder as follows:

As an alternative to using the Simulink preferences GUI to set Simulation cache folder, you also can get and set the preference value from the command line using get_param and set_param. For example,

>> get_param(0, 'CacheFolder')

ans =

     ''

>> set_param(0, 'CacheFolder', fullfile('C:','Work','mymodelsimcache'))
>> get_param(0, 'CacheFolder')

ans =

C:\Work\mymodelsimcache

Also, you can choose to override the Simulation cache folder preference value for the current MATLAB session.

Overriding Build Folder Settings for the Current MATLAB Session

The Simulink preferences Simulation cache folder and Code generation folder provide the initial defaults for the MATLAB session parameters CacheFolder and CodeGenFolder, which determine where files generated by Simulink diagram updates and model builds are placed. However, you can override these build folder settings during the current MATLAB session, using the Simulink.fileGenControl function. This function allows you to directly manipulate the MATLAB session parameters, for example, overriding or restoring the initial default values. The values you set using Simulink.fileGenControl expire at the end of the current MATLAB session. For more information and detailed examples, see the Simulink.fileGenControl function reference page.

Parallel Building for Large Model Reference Hierarchies

In a parallel computing environment, you can increase the speed of diagram updates for models containing large model reference hierarchies by building referenced models that are configured in Accelerator mode in parallel whenever conditions allow. For example, if you have Parallel Computing Toolbox™ software, updating of each referenced model can be distributed across the cores of a multicore host computer. If you additionally have MATLAB® Distributed Computing Server™ (MDCS) software, updating of each referenced model can be distributed across remote workers in your MATLAB Distributed Computing Server configuration.

To take advantage of parallel building for a model reference hierarchy:

  1. Set up a pool of local and/or remote MATLAB workers in your parallel computing environment.

    1. Make sure that Parallel Computing Toolbox software is licensed and installed.

    2. To use remote workers, make sure that MATLAB Distributed Computing Server software is licensed and installed.

    3. Issue appropriate MATLAB commands to set up the worker pool, for example, matlabpool 4.

  2. In the Configuration Parameters dialog box, go to the Model Referencing pane and select the Enable parallel model reference builds option. This selection enables the parameter MATLAB worker initialization for builds.

    For MATLAB worker initialization for builds, select one of the following values:

    • None if the software should perform no special worker initialization. Specify this value if the child models in the model reference hierarchy do not rely on anything in the base workspace beyond what they explicitly set up (for example, with a model load function).

    • Copy base workspace if the software should attempt to copy the base workspace to each worker. Specify this value if you use a setup script to prepare the base workspace for all models to use.

    • Load top model if the software should load the top model on each worker. Specify this value if the top model in the model reference hierarchy handles all of the base workspace setup (for example, with a model load function).

  3. Optionally, inspect the model reference hierarchy to determine, based on model dependencies, which models will be built in parallel. For example, you can use the Model Dependency Viewer from the Simulink Tools menu.

  4. Update your model. Messages in the MATLAB command window record when each parallel or serial build starts and finishes.

The performance gain realized by using parallel builds for updating referenced models depends on several factors, including how many models can be built in parallel for a given model referencing hierarchy, the size of the referenced models, and parallel computing resources such as number of local and/or remote workers available and the hardware attributes of the local and remote machines (amount of RAM, number of cores, and so on).

The following notes apply to using parallel builds for updating model reference hierarchies:

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS