Accelerate Simulink simulations in continuous integration workflows with Simulink cache files (2023)

In an agile development workflow, designing complex systems is a collaborative effort where large teams develop components, assemble subsystems, and integrate them into the system design. Ideally, system simulation should be an integral verification step in the component design process, enabling engineers to verify that components meet system requirements. However, simulating a system with a complex hierarchy of models can often be too time consuming.

One way Simulink®accelerates simulations of large hierarchies of reference models by creating a set of intermediate derived artifacts when the simulation is first run. For large teams, it can be difficult to share and reuse these derived files, including MEX files and other binaries. As a result, team members often spend time rebuilding and recreating files already created by other team members. This unnecessary effort consumes time that could be spent on more productive design activities. The larger the team and the more complex the model, the bigger the problem.

To solve this problem, Simulink packages and stores these derived artifactsSimulink cachefiles. In this article, we describe a method for managing and sharing Simulink cache files in a typical Agile development workflow that uses Git™ for source control and Jenkins™ for continuous integration (CI). This approach significantly speeds up system simulations.

Simulink cache

When simulating a model in Accelerator, Fast Accelerator, or Model Reference Accelerated Mode, Simulink packs the derived files for each model in the hierarchy into the appropriate Simulink Cache (SLXC) file. Team members can share these SLXC files and related Simulink model files with each other. When a team member runs a simulation on their machine, Simulink extracts the necessary derived files from the SLXC file for each model. Thanks to this, Simulink does not have to carry out unnecessary repairs, and the simulation runs much faster.

The exact performance improvement depends on several factors, such as the number of models in the hierarchy, the model reference rebuild settings, the number of blocks in the reference models, and the size and number of derived files created for each model. In our testing of various system models with reference models 0-500 and hierarchy levels 1-10, we saw improvements ranging from 2x to over 34x (Figure 1).

Accelerate Simulink simulations in continuous integration workflows with Simulink cache files (1)

Figure 1. Performance improvements obtained using Simulink cache files for various system models.

(Video) Five Practical Tips to Speed Up Your Simulink Simulations: Model References and Simulink Cache

Sharing and reusing Simulink cache files in an agile workflow with Jenkins CI is a three-step process (Figure 2):

  1. Make design changes in Git.
  2. Integrate design changes and archive SLXC files.
    • Jenkins fetches design changes from Git and runs simulations to test them.
    • Jenkins stores Simulink cache files in the Jenkins build archive.
  3. Sync design changes and SLXC files.
    • Team members sync the latest Git project changes and related cache files from the Jenkins build archive.
    • Team members simulate the system using cached files.

Accelerate Simulink simulations in continuous integration workflows with Simulink cache files (2)

Figure 2. Typical Simulink cache file reuse process with source control and continuous integration systems. The shaded areas describe the three phases of the workflow.

Before we dive into these phases, let's review the requirements and best practices for working with the Simulink cache.

Requirements and best practices for sharing and reusing Simulink cache files

The Simulink cache contains derivative files that depend on the MATLAB version, platform and compiler used during the simulation. All team members must use the same MATLAB to share and reuse these files®edition, platform and translator. For this article, we use MATLAB R2019a, Microsoft®ramen®i Microsoft Visual C++®respectively 2017

(Video) Advancing Component Reuse in Simulink

The following best practices help speed up the simulation of large hierarchical models by reusing shared cache files:

  • followcomponent-based modeling guidelinesfits your model.
  • Have each team member be responsible for a subset of the hierarchy, usually several Simulink models that together form a component such as a driver or installation with a well-defined interface. This reduces the hassle of merging design changes.
  • UseProjectwith startup and shutdown scripts to ensure a consistent work experience for all team members. The startup script initializes the environment when the project is opened, and the close script clears the environment when the project is closed.
  • List all modelsGas pedalmethod. Used to debug the reference model on the local computerNormalmethod. However, this mode does not provide the same simulation performance benefits as acceleration mode.
  • Place any modelRebuildparameter forIf changes to known dependencies are detected(Figure 3) and useModel dependenciesparameter to specify user-created dependencies. This improves the speed and accuracy of refresh detection.
  • If you are using Parallel Computing Toolbox™, selectEnable parallel model reference(Figure 3). The model reference hierarchy is then automatically built in parallel.
  • Decide whether you want to run Jenkins updates on every commit, at a specific time of day, or on demand. Your specific requirements determine which timing works best and which of the following types of middleware you can use:
    • Barren:A build where the Jenkins workspace has been stripped of artifacts or files from a previous Jenkins build. Use the sterile version if your team regularly reconfigures Simulink models. For example, changing hardware settings in the Simulink model hierarchy requires a clean workspace.
    • Increasing:A build that preserves artifacts from previous Jenkins builds. Use an incremental build if your team makes small incremental changes to individual components.

    Sterile builds tend to take longer than incremental builds, depending on the size of the model hierarchy.

Accelerate Simulink simulations in continuous integration workflows with Simulink cache files (3)

Figure 3. Model configuration parameters.

Make design changes in Git

In this step, team members modify the models, simulate the model hierarchy, run Model Advisor tests, and run unit tests. They commitonly their design filesto a source control system such as Git. Simulink cache files should not be uploaded to source control systems; these are derived binaries that can take up a lot of disk space and cannot be compared or combined. In a Git repository, you can create a filegitignoriratiso that Git ignores all derived artifacts, including SLXC files.

Integrate design changes and archive SLXC files

Refer to this document for guidance and configuration guidance for using Jenkins with Simulink

Continuous integration for Simulink model validation.

(Video) Simulink Model Comparison for GitHub Pull Requests

We use it later in this articleSample workflow for Simulink Cache and Jenkins.

In this example, the Jenkins administrator specifiesBuildcommand inMATLAB Jenkins plugin. This command starts MATLAB, builds the accelerator target, generates production C code for the embedded real-time target controller, and performs loop software equivalency (SIL) testing. Figure 4 shows the command that opens the Simulink project and runs the myBuildAndTest script.

Accelerate Simulink simulations in continuous integration workflows with Simulink cache files (4)

Figure 4. Illustration of the Jenkins Build command that opens the Simulink project and runs the myBuildAndTest script. The script builds a target accelerator for the system, generates production C code for the built-in target controller in real time, and runs multiple simulations to test the changes.

As part of simulation and code generation, Simulink creates SLXC files that contain the reference model accelerator and simulation targets for all models in the hierarchy. A subset of these SLXC files contains the production C code for the built-in target of the real-time controller. Simulink stores these SLXC files in the simulation cache folder. The location of this map is listed inProject Details(Figure 5). The script then runs multiple simulations to test design changes.

Accelerate Simulink simulations in continuous integration workflows with Simulink cache files (5)

(Video) Find and Fix Design Errors using Simulink Test

Figure 5. Project Details dialog showing the location of the cache folder where SLXC files are stored. The default value is [project root].

In addition, the administrator sets aPost-construction actionin Jenkins to archive the SLXC files (Figure 6). After the build, Jenkins copies the SLXC files from the Jenkins workspace to the build archive location.

To specify the location of the Jenkins build archive, the administrator can edit the config.xml file in the Jenkins home directory.

Accelerate Simulink simulations in continuous integration workflows with Simulink cache files (6)

Figure 6. Jenkins post-build action configured to archive all Simulink cache files from the Jenkins workspace to the build archive area after the build is complete.

Sync design changes and SLXC files

Normally Jenkins builds run every night. Each team member can then sync the sandbox based on the last successful build. Team members check changes to the project from Git, download the appropriate Simulink cache files from the build archive area, and place the Simulink cache files in their cache folders before simulating. Teams can set up a script to automate this process.

In this example, the syncSLXCForCurrentHash script accesses the SQLite database to search for successful builds, finds a valid hash from the Git commit, and copies the SLXC files from the archived build area in Jenkins to the simulation cache directory.

Workflow improvement

There are several ways to make this workflow faster and less error-prone. To easily manage SLXC files from multiple versions of Jenkins, you can use a database or repository management tool like this example. Finally, to further improve simulation performance, multiple system simulations can be run using parsing on a range of input parameter values.

(Video) Whats New in MATLAB and Simulink R2021a - MATLAB EXPO 2021


How do you accelerate simulation in Simulink? ›

Ways to Increase Simulation Speed
  1. Discretizing your electric circuit and your control system. ...
  2. If you are simulating repeatedly from a particular operating point, specify a vector of initial states: ...
  3. Reducing the number of open scopes and the number of points saved in the scope also helps in reducing the simulation time.

What are Simulink cache files? ›

Simulink Cache contains the build artifacts which can now be shared and reused across the team. Within a system model hierarchy, the cache files are created for each model that generates rapid accelerator or model reference SIM targets.

How do you accelerate simulation in Matlab? ›

To accelerate a model, first open it, and then on the Simulation tab, in the Simulate section, select Accelerator or Rapid Accelerator from the drop-down list.

What is the difference between Simulink accelerator and rapid accelerator? ›

In Simulink®, there are three desktop simulation modes: Normal, Accelerator, and Rapid Accelerator. For most models, Accelerator is faster than Normal, and Rapid Accelerator is faster still. Rapid Accelerator mode speeds up simulation by generating an executable for your model.

What is acceleration simulation? ›

In simulation acceleration, the workstation executes most of the behavioral code, and the hardware engine executes the synthesizable code. Simulation acceleration can be either signal- or transaction-based.

What is the purpose of cache files? ›

Storing data in a cache allows a computer to run faster. For example, a browser cache that stores files from previous browsing sessions speeds up access to follow up sessions. A database cache speeds up data retrieval that would otherwise take a good bit of time and resources to download.

How do I open Simulink cache files? ›

To learn what a specific Simulink cache file contains, open the report by double-clicking the file. 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.

What are cache files and do I need them? ›

Your Android phone's limited storage can fill up quickly. And one cause of this that's easy to overlook is the stored information that apps regularly create to run at their best. These temporary data files are known as a cache; a fair chunk of your Android phone's storage space might be filled up with cache files.

What is accelerator mode in Simulink? ›

In the Accelerator mode, Simulink Design Optimization software runs simulations during optimization with compiled C code. Using compiled C code speeds up the simulations and reduces the time to optimize the model response signals.

What is acceleration in MATLAB? ›

Acceleration is a mode of operation in the Simulink® product that you can use to speed up the execution of your model. The Simulink software includes two modes of acceleration: accelerator mode and rapid accelerator mode. Both modes replace the normal interpreted code with compiled target code.

Does MATLAB use GPU acceleration? ›

MATLAB automatically runs calculations on the GPU. For more information, see Run MATLAB Functions on a GPU.

Does NASA use Simulink? ›

NASA Marshall Engineers have developed an ADCS Simulink simulation to be used as a component for the flight software of a satellite.

What is the difference between virtual and atomic subsystem in Simulink? ›

Atomic Versus Virtual Subsystems

Simulink ignores virtual subsystem boundaries when determining block update order. By contrast, Simulink executes all blocks within an atomic subsystem before moving on to the next block. Conditionally executed subsystems are atomic.

What is the difference between enabled and triggered subsystem Simulink? ›

Unlike an Enabled Subsystem block, a Triggered Subsystem block always holds its outputs at the last value between triggers. Also, triggered subsystems cannot reset block states when executed; the states of any discrete block are held between triggers.

How does accelerate work? ›

acceleration, rate at which velocity changes with time, in terms of both speed and direction. A point or an object moving in a straight line is accelerated if it speeds up or slows down. Motion on a circle is accelerated even if the speed is constant, because the direction is continually changing.

What is acceleration integration? ›

The integral of acceleration over time is change in velocity (∆v = ∫a dt). The integral of velocity over time is change in position (∆s = ∫v dt).

How does acceleration work? ›

Acceleration (a) is the change in velocity (Δv) over the change in time (Δt), represented by the equation a = Δv/Δt. This allows you to measure how fast velocity changes in meters per second squared (m/s^2). Acceleration is also a vector quantity, so it includes both magnitude and direction.

What is the difference between cache and file? ›

A cache, by practical definition, is a container used to store and preserve essential items; a cache file is a digital version. When an app needs to back up information for a long-term purpose, like file recovery, they store the information in a cache file for a later date.

Why not to use cache? ›

Caches take up space on the disk, so we have to assess whether the time we are saving is worth the amount of disk space used. Cached data might not be the most accurate, particularly for volatile real-time data. Therefore, volatile data should not be cached.

Where is MATLAB cache stored? ›

How the Toolbox Path Cache Works. MATLAB caches (essentially, stores in a known files list) the names and locations of files in $matlabroot/toolbox directories. These directories are for MathWorks supplied files that should not change except for product installations and updates.

How to read CSV file in Simulink? ›

view function or the Data Inspector button in the Simulink™ toolstrip. Then, click Import . In the Import dialog, select the option to import data from a file and navigate in the file system to select the file. After you select the file, data available for import shows in the table.

How do I run a cache file? ›

Where are my Windows app cache files? Most temporary files are stored in the Windows Temp folder. Although the location varies by computer and even by user, you can access it using the Run dialog. Press Windows Key + R, type %temp% and click OK.

What happens if I empty cache? ›

After you clear cache and cookies: Some settings on sites get deleted. For example, if you were signed in, you'll need to sign in again. If you turn sync on in Chrome, you'll stay signed into the Google Account you're syncing to in order to delete your data across all your devices.

Are caches necessary? ›

Without cache, everything would need to reload. You can specifically remove the cache on certain websites but leave others in place, which can be particularly useful if you are managing multiple sites.

What happens if you delete cache files? ›

Clearing the cache will remove all the temporary copies of a website and it's files, and the next time you visit the site it will be freshly downloaded (and hopefully without problems!)

What does the accelerator control? ›

The accelerator is also known as gas pedal. It is the pedal located on the floor on the far-right. This pedal controls the amount of gas being fed into the engine and thereby controls the speed of the vehicle.

What is dynamic system in Simulink? ›

Dynamic System Models generally represent systems that have internal dynamics or memory of past states such as integrators, delays, transfer functions, and state-space models. Most commands for analyzing linear systems, such as bode , margin , and linearSystemAnalyzer , work on most Dynamic System Model objects.

How do you accelerate a for loop in MATLAB? ›

Although you have not given any details at all of your code, there are several ways you can speed up your code:
  1. use vectorized code rather than loops.
  2. preallocate arrays before loops.
  3. use logical indexing rather than subscripts.
  4. do not change a variable's data class.
  5. use tic and toc to time parts of a program.

Is acceleration a control variable? ›

Dependent Variable: The acceleration of the object. Control Variables: The mass of the object.

What variable is acceleration? ›

Variable acceleration is a situation where there is a difference in the average acceleration within different points along the path of an object in motion.Differences could be either in magnitude, direction, or in both magnitude and direction.

What is the best GPU for MATLAB? ›

The Best GPU which you can use with MATLAB is going to be the Nvidia Tesla K80 meant for server systems. It runs around $5,000 USD. It's predecessor the K40 runs about $3,000, but the K80 is basically 2 of these in one.

What is the benefit of GPU acceleration? ›

GPU acceleration is essential because it allows computers to speed up processes that work similarly to graphical processing. Acceleration boosts the speed of execution for complex computational problems that can be broken down into similar, parallel operations.

Should I turn off GPU acceleration? ›

Unless you're facing an issue that you know is because of hardware acceleration, you shouldn't turn off hardware acceleration.

How to speed up Verilog simulation? ›

You might use one or some of these options:
  1. Try VCS (Chronologic).
  2. Create fast libraries (if you run gate level simulation).
  3. Try to use distributed simulation.
  4. Avoid waves display (of any kind).
  5. If you have Verilog 1.6 upgrade it to Verilog 2.2 with.

How do you trigger a subsystem in Simulink? ›

To create a triggered subsystem: Add a Triggered Subsystem block to your model. Copy a block from the Simulink® Ports & Subsystems library to your model. Click the model diagram, start typing trigger , and then select Triggered Subsystem.

How to improve performance in MATLAB? ›

Improve the Performance of Your MATLAB Code
  1. Measure code execution time with functions like tic , toc , and timeit.
  2. Use the MATLAB Profiler to see which parts of your program take the most time to run.
  3. Use the MATLAB Code Analyzer for additional suggestions to improve performance.

Why is my Simulink simulation so slow? ›

- If the memory used by variables stored during the simulation is greater than the amount of RAM on the system, performance will be poor. The solution is to run smaller simulations or add more memory.

What is fast time simulation? ›

Fast Time Simulation (FTS) is an excellent method to tackle such challenges. FTS is a cost-effective and quick evaluation solution that can support decision-making activities.

How do I increase simulation time in Xilinx? ›

processes -> simulate behavioral model ->(right click) properties -> (check option "run for specified time" and setting "simulation run time" to 3000 ns) ->"apply" and "OK".

What is the difference between sample time and simulation time? ›

Sample time should be smaller then the simulation time. Because sample time represents the sampling period after which MATLAB will fetch the data for reading. If your simulation time is lesser then the sampling time then there is no data fetched for the simulation.

How do I change the simulation time in Simulink? ›

The Solver pane appears when you first choose Parameters from the Simulation menu or when you select the Solver tab. You can change the start time and stop time for the simulation by entering new values in the Start time and Stop time fields.

What is infinite sample time in Simulink? ›

Simulink assigns Constant blocks a sample time of infinity, also referred to as a constant sample time. Other blocks have constant sample time if they receive their input from a Constant block and do not inherit the sample time of another block.

What is the difference between trigger and enabled subsystem? ›

An Enabled and Triggered Subsystem is a conditionally executed subsystem that runs once at each simulation time step when both these conditions apply: Enabled control signal has a positive value. Trigger control signal rises or falls through zero.

How to generate impulse signal in Simulink? ›

This method is a good first approximation of an impulse, and it simply involves setting the parameters of two Step blocks to simulate an impulse. Start by dragging a Step block and a Scope block into the model. Then, hold CTRL and click and drag the Step block to add a second Step block.

How to generate ECG signal in Simulink? ›

Open the dialog of ECG Signal Selector block. Select the ECG signal mean heart rate in the drop down menu. Click Apply and observe the real-time detection results in the scopes and HeartRate display.

What is the weakness of MATLAB? ›

Disadvantage of MATLAB

This comparatively high cost is more than offset by the decreased time necessary for an engineer or scientist to create a working program, so MATLAB is cost-effective for businesses. However, it is too expensive for most individuals to consider purchasing.

Why is MATLAB suddenly running so slow? ›

MATLAB may be running slowly because you have a limited amount of RAM (i.e. under 128MB). The RAM used by MATLAB at runtime is between 40MB-60MB. The HELP browser can take up another 12MB. If you have limited memory (RAM), your processor may start using virtual memory (from your hard drive).


1. End-to-End Document Review and Management – Collaborator Announces Support of Simulink
2. Teaching Chemical Engineering with MATLAB, Simulink, and TCLab
3. FSW 2021: Real-time Rapid Control Prototyping and HIL Testing - Anish Anthony
(Flight Software Workshop)
4. Radio Deployment on SoC Platform
5. Continuous Testing of HiL Testcases Webinar
(EXAM - Testautomation)
6. Building Motor Control Applications with Embedded coder and NXP Motor Control Development Toolbox fo


Top Articles
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated: 09/23/2023

Views: 5639

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.