Block reduction
Option to reduce execution time by reducing number of blocks that execute in simulation
Model Configuration Pane: Simulation Target
Description
This parameter specifies whether to reduce execution time by optimizing the block diagram to reduce the number of blocks in the model that execute during simulation. Block reduction collapses groups of blocks into a single, more efficient block or eliminates unnecessary blocks from the execution list. Block reduction does not affect the appearance of the block diagram.
The software searches for these block patterns to optimize out of the block diagram for simulation:
Blocks that simply copy their input to their output
Blocks or signals in an unused code path
When you generate code using Simulink® Coder™, block reduction is intended to remove only generated code for block execution. Other block data, such as sample time and data type definitions, might remain in the generated code.
Understand Unused Code Paths
The software considers a code path unused when the signal path meets both of these conditions:
All signal paths for a block end with a block that does not execute, such as a Terminator block, a disabled Assertion block, or an S-Function block configured for block reduction.
No signal paths for the block include global signal storage downstream from the block.
Consider the three signal paths in this block diagram. Each signal path starts with an Inport block that connects to the input port of a Gain block. The output of the Gain block connects to a different block in each signal path.
In the first signal path, the Gain block connects to an Outport block. The software does not reduce blocks in this signal path.
In the second signal path, the Gain block connects to a Terminator block. This signal path is unused because the Terminator block does not execute. These blocks are reduced for simulation and code generation when you enable Block reduction.
In the last signal path, the output of the Gain block connects to a Scope block. The Scope block does execute in simulation, so this code path is not reduced in simulation. The software generates code for this signal path only when you select MAT-file logging (Simulink Coder).
Having tunable parameters does not prevent the software from eliminating a block when block reduction is enabled.
Identify Reduced Blocks
You can identify nonvirtual blocks that block reduction removes from the execution list by highlighting the blocks in the block diagram or by using the get_param
function.
To highlight nonvirtual blocks in the block diagram that block reduction removed from the execution list, in the Simulink Toolstrip, on the Debug tab, select Information Overlays. Then, under Blocks, select Reduced Blocks.
The Reduced Blocks option in the Information Overlays menu is enabled only when Block reduction is enabled and has reduced blocks in the model.
Blocks reduced in simulation are highlighted in the model after you update the block diagram or simulate the model. Blocks reduced in generated code are highlighted after you build your model for code generation.
To identify reduced blocks programmatically, use the
reducedBlocks = get_param("ModelName","ReducedNonVirtualBlockList");
Settings
on
(default) | off
on
The software optimizes the block diagram to reduce the number of blocks that execute during simulation and for which code is generated.
off
The software does not optimize the block diagram to reduce the number of blocks that execute during simulation and for which code is generated.
Recommended Settings
Application | Setting |
---|---|
Debugging |
No impact for production code generation |
Traceability | off |
Efficiency | on |
Safety precaution | No impact |
Programmatic Use
Parameter: BlockReduction |
Type: string | character vector |
Values:
'on' | 'off' |
Default: 'on' |
Version History
Introduced in R2008a
See Also
Topics
- Eliminate Dead Code Paths in Generated Code (Simulink Coder)
- Time-Based Scheduling (Simulink Coder)
- Code Efficiency (Simulink Coder)
- Model Configuration Parameters: Simulation Target