Main Content

Share Simulink Cache Files for Faster Simulation

Simulink® cache files contain build artifacts that can speed up simulation and code generation. To generate these build artifacts and automatically package them in Simulink cache files, perform one of these actions:

  • Update the diagram for a model hierarchy that contains models referenced in accelerator mode

  • Simulate a model hierarchy that contains models referenced in accelerator mode

  • Simulate a top model in accelerator or rapid accelerator mode

  • Generate code for a model or model hierarchy

The second time that you perform any of these actions, Simulink builds only the out-of-date files as long as the Rebuild configuration parameter is set to If changes detected (default) or If changes in known dependencies detected. With fewer files to build, the actions complete faster.

Note

While you can avoid all referenced model rebuilds by setting the Rebuild configuration parameter to Never, using this setting can produce invalid simulation results.

Team members and continuous integration (CI) systems can generate Simulink cache files for models that you use. To reduce the time it takes when you build those models for the first time, you can copy the corresponding Simulink cache files to your local folder specified by the Simulation cache folder preference. Simulink extracts any Simulink cache file contents that differ from the contents on disk. If Simulink generates or updates the build artifacts on disk, it locally updates the corresponding Simulink cache files.

You can identify a Simulink cache file by its .slxc extension. Its file name matches the name of the corresponding model.

Inspect Simulink Cache File Contents

Simulink cache files can contain multiple types of build artifacts, including:

  • Accelerator targets

  • Rapid accelerator targets

  • Model reference simulation targets

  • Variable usage information

  • Code generation targets (Simulink Coder™, Embedded Coder®)

  • Model representations (Simulink Design Verifier™)

  • Web views (Simulink Report Generator™)

Simulink cache files accumulate build artifacts for multiple platforms and Simulink releases.

To learn what a specific Simulink cache file contains, open the report by double-clicking the file.

Simulink cache report

Alternatively, to get the contents of the Simulink cache file in a MATLAB® table, use the slxcinfo function.

You can reuse build artifacts that support the platform and release that you are using. For example, suppose that you use a Windows® machine and the R2019a Simulink release. In the Simulink cache file described by this report, you can use the simulation targets under R2019a : win64. A team member that uses a Linux® machine and R2019b can use the simulation and code generation targets under R2019b : glnxa64 and the model representations under R2019b : all platforms.

A Simulink cache file can accumulate build artifacts for the release in which it was created and later releases. Suppose you create a Simulink cache file in R2019b. You would not be able to use that Simulink cache file in R2019a.

Use Simulink Cache Files

While most teams can benefit from using Simulink cache files, a development environment with these features is best suited for using Simulink cache files.

  • A model hierarchy that contains many referenced models.

  • A top model that simulates in accelerator or rapid accelerator mode, causing Simulink to generate a simulation target for the top model and all referenced models.

  • A standardized platform, compiler, and Simulink release for the entire development team.

  • Relative paths or consistent absolute paths, which you specify with the Include directories configuration parameter, for the entire development team.

  • A source control system, such as Git™, that manages design files. See Set Up Git Source Control.

    Note

    Since Simulink cache files are derived files, you should not manage them under source control. Even if you share Simulink cache files by storing them in a source control system, you cannot diff or merge different versions of these files.

  • A CI system, such as Jenkins®, which periodically builds the latest version of the model hierarchy using a pool of parallel workers.

    Note

    To avoid unnecessary rebuilds for simulation and coder targets that use custom code, map the CI system directories to named volumes or symbolic links that are the same in team member sandboxes. For example, have the CI system and team members store custom code in a mapped directory such as B:\path\customcode.

In this development environment, you interact with files in the source control system and build archive.

Workflow with source control system, CI system, and build archive. The CI system pulls design changes from the source control system and archives Simulink cache files in the build archive.

To reduce the amount of time that you spend updating simulation targets, follow these steps.

  1. Pull the latest version of all design files from the source control system.

  2. Copy the latest version of all Simulink cache files from the build archive and place them in your Simulation cache folder.

  3. Open the top model and simulate it.

    Simulink extracts the required build artifacts from the Simulink cache files. The simulation completes without rebuilding any models as long as the models have not changed since the most recent build completed by the CI system.

    Note

    To unpack the simulation and code generation targets from the Simulink cache files without updating, simulating, or generating code for the model hierarchy, use the slxcunpack function.

  4. Change a model and simulate the model hierarchy again.

    Simulink rebuilds the necessary models and updates the local copy of the corresponding Simulink cache file.

  5. Commit the updated model to the source control system. You do not commit the Simulink cache file, which is a derived file.

Check for Simulink Cache Files in Projects

When you create a project from a top model, the project includes the corresponding Simulink cache files for the model and its referenced models.

To view Simulink cache file dependencies in a model hierarchy, you can select Dependency Analyzer in the Views pane of the corresponding project.

Dependency Analyzer results for sldemo_mdlref_depgraph, including Simulink cache files

For more information, see Perform Impact Analysis with a Project.

See Also

|

Related Topics

External Websites