About Scalable Compilation
What Is Scalable Compilation?
Large models often take a long time to compile and simulate. Scalable compilation helps reduce compilation time for models that consist of a pattern of repeated components by compiling a repeated component once and then reusing these compilation artifacts for other instances of the same component. Scalable compilation improves compilation performance, it does not reduce the simulation time of the model.
Scalable compilation supports these types of reusable components:
Referenced subsystems — Subsystem instances using a subsystem reference, where you save the contents of a subsystem in a separate file and reference it using a Subsystem Reference block. You can create multiple instances referencing the same subsystem file. For more information, see Subsystem Reference.
Linked subsystems — Subsystem instances created from Simulink® library Subsystem blocks with link to the source. Note that if you create copies from Subsystem blocks, with
none, they are not linked subsystems.
Individual blocks where
on. For more information, see Reuse Compilation Artifacts of Individual Simscape Blocks.
Textual components with the
CompileReuseattribute set to
true. For more information, see Reuse Compilation Artifacts of Textual Components.
Local subsystems where
on get reused for scalable compilation if their contents
are the same, for example, if they were created by copy-paste. However, if your
model contains multiple instances of a local subsystem, it is recommended that
you convert them into referenced or linked subsystems, to ensure that the
contents of the subsystems remain identical.
If you have a slow-to-compile model, determine whether it can benefit from scalable compilation by asking yourself the following questions:
Does the model consist of a pattern of repeated components, such as a transmission line or a battery pack? Can you easily turn these components into reusable components, such as referenced subsystems or linked subsystems?
How much does the Simscape™ part of the model contribute to total model compilation time? Some models have complicated controllers that take a long time to compile. In such cases, even if scalable compilation can significantly reduce the compilation time of the Simscape part of the model, the impact on the entire model could be less noticeable.
Does the model use unsupported patterns, optimizations, or simulation modes? For example, scalable compilation does not support code generation, including rapid accelerator mode, or the Partitioning local solver. For more information, see Scalable Compilation Limitations.
The Advisory tool can provide information about unsupported patterns or workflows in your model, as well as guidance regarding subsystem reusability and compilation statistics. For more information, see Analyze the Model Using the Advisory Tool.
The complexity level of the repeated components has significant impact on the scalable compilation results. You can try different ways of restructuring your model into repeated components to determine the optimal configuration. For more information, see Determine Optimal Complexity Level for Reusable Components.
Scalable Compilation Workflow
The flowchart represents the scalable compilation workflow.
If you have a slow-to-compile model:
Determine whether the model is a suitable candidate for scalable compilation. Does it have a repeated pattern of components consisting of Simscape blocks?
If yes, identify a way to restructure the model into repeated components. Some models do not need restructuring because they already consist of a pattern of repeating subsystems. Other models may need reorganization into repeating subsystems. You do not have to create referenced subsystems or linked subsystems at this point. The Advisory tool lets you analyze your model as if it already contained reusable components.
Analyze the model using the Advisory tool and review the results.
If the performance improvement from scalable compilation is not satisfactory, consider whether there are other possible ways to restructure the model. The complexity level of the repeated components has significant impact on scalable compilation results. You can try different ways of restructuring your model into repeated components and use the Advisory tool to determine the optimal configuration.
Once you are satisfied with the results, turn the repeated components in your model into reusable components. For example, convert one of the repeated components into a referenced subsystem, and then replace all instances of this component in the model with Subsystem Reference blocks. For more information, see Subsystem Reference.
Scalable Compilation Limitations
Scalable compilation reduces compilation time for models that consist of a pattern of repeated components by compiling a repeated component once, and then reusing these compilation artifacts for other instances of the same component. Besides individual Simscape blocks and textual components, scalable compilation supports only two types of reusable subsystems: referenced subsystems and linked subsystems. Other types of graphical subsystems must be converted to one of these types to take advantage of scalable compilation.
Different instances of reusable subsystems can have different parameter values, by utilizing system masks. For more information, see Reference a Subsystem File in a Model. You can also parameterize a variable initialization target value within a reusable subsystem and supply different values of that initialization target to different subsystem instances, for example, from a mask parameter or from the base workspace. However, other properties of a variable, such as the initialization priority or nominal value, have to be the same in all the reusable subsystem instances.
Additionally, scalable compilation does not support the following simulation tools and workflows:
The Partitioning local solver
Nonlinear index reduction, which is a global transformation used for solving high-index nonlinear equations
The Advisory tool can provide information about unsupported patterns or workflows in your model. If the model contains unsupported patterns, workflows, or optimizations, the Advisory tool lists the applicable limitations and returns the recommendation not to enable scalable compilation.