How can I improve compilation time of Simulink models?

15 views (last 30 days)
One of the steps in the build procedure for Simulink model is invoking the compiler itself, how do I speed up the compilation time?

Accepted Answer

Piotr Kluczek
Piotr Kluczek on 22 Feb 2023
Intro
For increasing number of cores involved in compilation (e.g. Visual Studio one) you need to add the option -j to compiler (makefile) options in model configuration.
You can add a number of cores to be used e.g. -j4, but compiler can decide what amount is best if you leave it without the number and I trust it.
I assume you store your configuration as referenced, saved in a file, and use standard setup for compiler like this:
cs.set_param('BuildConfiguration', 'Faster Builds'); % Build configuration
Solution
The trick is to change build configuration so that it uses makefile option -j, my example:
cs.set_param('BuildConfiguration', 'Specify'); % Build configuration
cs.set_param('CustomToolchainOptions', {'C Compiler','-c -V$(QCC_TARGET) -g -O2 -ffast-math -fwrapv','Linker','-V$(QCC_TARGET) -g -std=gnu++14 -stdlib=libstdc++','Shared Library Linker','-V$(QCC_TARGET) -shared -Wl,--no-undefined -g','C++ Compiler','-c -V$(QCC_TARGET) -g -std=gnu++14 -stdlib=libstdc++ -O2 -ffast-math -fwrapv','C++ Linker','-V$(QCC_TARGET) -g -std=gnu++14 -stdlib=libstdc++','C++ Shared Library Linker','-V$(QCC_TARGET) -shared -Wl,--no-undefined -g','Archiver','ruvs','Make Tool','-f $(MAKEFILE) -j'}); % Toolchain details
As you can see, this is a lot, but it actually comes from the default setup, you can see it in here:
And after the change it looks like that:
So my tip is to select Build configuration to Faster Builds, then Specify, save it to file, look up for the CustomToolchainOptions and just add this -j at the end like I did. If you just copy my line it will not probably work for several reasons (used compiler, different target pc, matlab release etc.)
It should improve a bit, but only compilation time - it will not help with other parts like building model hierarchy, generating the code etc. But if your system is really big, you should get at least few minutes of improvement.

More Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!