What processes are included in the compilation of a simulink model? How can the compile time of a MATLAB function block be reduced?
7 views (last 30 days)
Show older comments
I am currently working on a simulink model which includes a MATLAB function block. This function block is used to evaluate an expression for a Jacobian of a complex function at a certain state. This expression for the Jacobian was derived using the symbolic toolbox and yields a very lengthy expression for each element in the Jacobian. Since the Jacobian has size 3x6 a total of 18 expressions need to be evaluated in the MATLAB function.
When running the model it takes a significant amount of time to compile (15-30min). But once complete the simulation itself is quite fast (+/- 20sec). I am trying to understand what is happening during the compiling of the model, so that I can perhaps alter the code. I already tried to find common terms in the lengthy expressions, as I expect that the compilation process might include this process, but this does not seem to speed up the compilation time. Is there any advice available as to how to reduce the time required for the compilation of a simulink model? specifically for simulink models that include a MATLAB function.
2 Comments
Fred Smith
on 14 Jan 2016
The compile time you are seeing are excessive for such a small example. In the past we have seen problems with code produced by the symbolic toolbox due to excessive use of specific indices x(1),x(2).... This triggered some bad combinatorics in the code generator. But in the cases I am referring to there were hundreds of thousands of specific indices. 18 should not be a problem.
What version are you using? 15a/15b have some changes that might make a difference here.
When you say compile time, do you mean update-diagram time (Ctrl-D) or build time (Ctrl-B)?
If a newer release doesn't resolve it, would you mind sharing the code? The development team would be interested in seeing this example.
Thanks!
Answers (1)
Jason Moore
on 23 Jan 2016
I have a few suggestions that you could do.
1.) Use the parallel computing toolbox with a parfor loop in your MATLAB function block. This should speed up your function. 2.) Also you could place this block into a model reference and the rest of your model could be outside of the model reference. Then you can turn on incremental build under the Configuration Parameter section for Model Reference. This way every time you rebuild the model reference will only be built when a change to that section occurs.
See Also
Categories
Find more on Manual Performance Optimization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!