How can I improve compilation time of Simulink models?

조회 수: 5 (최근 30일)
Piotr Kluczek
Piotr Kluczek 2023년 2월 22일
편집: Piotr Kluczek 2023년 2월 22일
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