How can I improve compilation time of Simulink models?

14 次查看(过去 30 天)
One of the steps in the build procedure for Simulink model is invoking the compiler itself, how do I speed up the compilation time?

采纳的回答

Piotr Kluczek
Piotr Kluczek 2023-2-22
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by