How can I reduce the Update Diagram / Initialization time of my large Simulink model?

15 views (last 30 days)
I have a model with many thousands of blocks and signals. It takes several minutes for the model to Update Diagram / Initialize. What can I do to reduce this? 

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 31 Mar 2024
Edited: MathWorks Support Team on 31 Mar 2024
First, consider using Fast Restart if you are not making changes to your model. With Fast Restart we can skip the initialisation phase entirely. Also consider reading this whitepaper on Simulink Performance which covers these concepts:
Generally speaking, below are a few of the main phases in the Update Diagram phase of Simulation: 
  1. Up-to-date check on model references
  2. Rebuild model reference that are out of date
  3. Up-to-date check on top-level model
  4. Recompile top-level model
Here are some strategies to reduce time spent in these phases.

Up-To-Date Checks and Rebuilds on Model References

For Model References in Accelerator Mode, Simulink will generate a "simulation target", a MEX file containing a compiled version of the model reference. Though the first build of this simulation target takes time, if no structural changes are made to the model reference, the simulation target can be reused which speeds up later compilation. Simulation targets are saved in the model cache files, consider maintaining and sharing these files to speed up model rebuilds.
In order to determine if a rebuild is needed on a model, an up-to-date check must be done. This check can be controlled with the Rebuild option in the Model Reference pane of the Model Settings. The default is "If changes detected" which will compute a full checksum for the model, which has a computation cost (although less costly than a rebuild). In most cases "If changes in known dependencies" will be faster as it only checks to see if the file modified date has changed. You can review the limitations in the documentation page below.
 

Up-To-Date Checks and Rebuilds on Top-Level Model

A top-level model in accelerator or rapid accelerator must be checked for structural changes and rebuilt if changes are detected. Both the "up to date check" and the rebuild can take time for large models. Fast Restart will allow you to skip the Up To Date Check and rebuild of the top-level model as it will lock the model against structural changes while it is "on". This is best for iterative simulation workflows.
If you are making constant changes to your model such that Fast Restart is not suitable, consider greater model componentization through model reference. If your top-level model contains a large number of blocks or signals (in the thousands), consider breaking off larger pieces of your model into Model References so as to take advantage of model cache files. 

 

Analogy to Compiling in Other Programming Languages

If you are familiar with compiled programming languages such as C, then you may find this analogy useful. Think of each model file as its own code file (ex C source file ). If our model contains thousands of blocks then this would be similar to a code file with many thousands of lines. If we make a change to the model file, then Simulink will rebuild the model, just as making a change in a large code file will trigger a recompile of that file.  The time taken to compile in both cases will scale with the size of the model / code file.
Now think of a model reference in accelerator mode as similar to pre-compiled binary files such as an object file, a static library, or a dynamic library. If the model reference has not changed, we don't need to rebuild this file, and the top-level model can link against the model reference MEX. Similar to how when building code, we can link to previously compiled artifacts like static/dynamic libraries. 
Therefore, just as it would be good practice to separate a large C file into separate files, it can help with Update Diagram performance to separate out a large model file into multiple model references.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!