Huge 6DOF model has performance issues

5 views (last 30 days)
Nikolas Maximini
Nikolas Maximini on 10 Mar 2022
Edited: Nikolas Maximini on 14 Mar 2022
Me and my team are running a 6DOF Simulink model which consists of ~200k blocks. Lately, working with this model more and more became an absolute pain. Running the model in Normal Mode is no option since it takes ages to simulate a standard scenario of about 20-60 seconds simulation time. When using Rapid Accelerator the Initialization and Building process takes 10min+ which is way to much, too. However, after finishing these steps the simulation finishes sufficiently fast. But while working we are consistently changing things and have to evalute the changes immediatly. Since every change to the model forces the Rapid Accelerator to recompile the model you can maybe imagine how hard it is to get in a workflow.
To tackle this problem we are thinking about two different approaches:
  1. Replace all embedded Matlab Functions by Simulink blocks. In out model are 241 embedded MATLAB Funcitons right now. The Simulink docu recommends replacing them but it sounds like Interpreted MATLAB Function Blocks are the real problem (from here)
  2. Trying to build a model intern library with often used subsystems, hoping that Simulink then only compiles it once, namely the one linked block in the intern library, when starting in Rapid Acceleratorand and thus saving time. Im writing model intern as we are already using libraries for each subsystem of the vehicle containing block choices for all kinds of for example "engines". But when putting together a new aircraft model we break all links to these "distributed" libraries so that everyone can work on that offline model without accidently changing the distributed library. Since we are running on R2018b we cannot utilize referenced subsystems (but would this help improving the performance anyways?)
However, it would be awesome if somebody who has experice with these approaches (and maybe other better once) could tell us if they are worth the effort. That is, "do I really get a faster compilation in Rapid Accelerator Mode after getting rid of the MATLAB Functions" and "is there a way to place a library in a model" and also "does linking the same blocks result in a better Rapid Accelerator performance?"
  4 Comments
Paul
Paul on 11 Mar 2022
Edited: Paul on 11 Mar 2022
I think there are two separate issues to consider here:
1. The time it takes from when you start the simulation process to when the simulation actually starts running (build)
2. The time it takes for the simulation to execute once it actaully starts running (execution)
I thought the Question was about (1), but I bring up (2) because it is addressed in the links you provided (as is (1), in some cases).
In this discussion three blocks are under consideration:
Model (MDL)
My understanding of these is as follows, partly based on documentation and partly based on observation to the best of my recollection (so take with a grain of salt).
iMF - Never generates code, always calls out to Matlab interpreter even in Accelerator mode. So potential slowdown for execution, but should have minimal impact on build.
MF - Always executes based on generated code, even when running in Normal mode. So has the potential to speed up execution in Normal mode as compared to using Simulink blocks for the same functionality. I thought the generated code is basically implemented in a mex file and that mex file is only regenerated if Simulink detects a change in the MF during the build process. I thought this determination is made via some sort of checksum. So there will always be a price to pay during build when it does the check, but the price might not be too high if Simulink determines there is no need to regenerate the code.
MDL - Similar to the MF wrt to the execution phase and the build phase. However, with the MDL block there is an option to tell Simulink to assume that it doesn't need to be rebuilt. This option is most useful when running multiple simulations in a loop over different input parameters and the user is willing to assert that nothing has changed in all of the MDL blocks in the simulation. Rebuild
Also, this doc page may be of interest if Simulink is generating code when you think it ought not to be: Code Regeneration in Accelerated Models
@Guy Rouleau may be willing to provide more insight into all of this.
Nikolas Maximini
Nikolas Maximini on 14 Mar 2022
Edited: Nikolas Maximini on 14 Mar 2022
Hi Paul,
I think me and my team need to take a closer look at the model referencing. As @Benjamin Thompson has also suggested in his answer they seem to be the best option for a model with a predefined set of major subsystems that shall only run through the building phase when changes are made to these particular subsystems themself and not whenever something is changed anywhere else in the model.
Thank you guys for your very construcitve advises so far!

Sign in to comment.

Answers (1)

Benjamin Thompson
Benjamin Thompson on 11 Mar 2022
Are you using model referencing with this? A reference model has its own cache file which only needs to be updated when that model or its dependencies change. Plus you can switch reference models individually between normal, accelerator, and rapid accelerator model as needed depending on what you are changing within the greater set of models.

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!