Optimization Pane

Optimization Overview

Set up optimizations for a model's active configuration set. Optimizations are set for both simulation and code generation.

Configuration

Set the parameters displayed.

Tips

Stateflow® software optimizations appear only when Real-Time Workshop® and Stateflow products are both installed on your system and the model includes Stateflow charts or Embedded MATLAB™ Function blocks. The settings you make for the Stateflow software options also apply to all Embedded MATLAB Function blocks in the model. You do not need a Stateflow license to use Embedded MATLAB Function blocks.

See Also

Block reduction

Reduce execution time by collapsing or removing groups of blocks.

Settings

Default: On

On

Simulink® software searches for and reduces the following block patterns:

Off

Simulink software does not search for block patterns that can be optimized. Simulation and generated code are not optimized.

Tips

Accumulators.   Simulink software recognizes the block diagram shown in the following figure as an accumulator:

Dead Code Elimination.   Any blocks or signals in an unused code path are eliminated from generated code.

Command-Line Information

Parameter: BlockReduction
Type: string
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingOff (for simulation and during development)
No impact (for production code generation)
TraceabilityOff
EfficiencyOn
Safety precautionOff

See Also

Conditional input branch execution

Improve model execution when the model contains Switch and Multiport Switch blocks.

Settings

Default: On

On

Executes only the blocks required to compute the control input and the data input selected by the control input. This optimization speeds execution of code generated from the model. Limits to Switch block optimization:

Off

Executes all blocks driving the Switch block input ports at each time step.

Command-Line Information

Parameter: ConditionallyExecuteInputs
Type: string
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityOn
EfficiencyOn
Safety precautionOff

See Also

Inline parameters

Transform tunable parameters into constant values.

Settings

Default: Off

On

Enabling Inline parameters has the following effects:

Off

Uses symbolic names for model parameters in generated code.

Tips

Dependencies

This parameter enables:

Command-Line Information

Parameter: InlineParams
Type: string
Value: 'on' | 'off'
Default: 'off'

Recommended Settings

ApplicationSetting
DebuggingOff (for simulation and during development)
On (for production code generation)
TraceabilityOn
EfficiencyOn
Safety precautionNo impact

See Also

Implement logic signals as boolean data (vs. double)

Controls the output data type of blocks that generate logic signals.

Settings

Default: On

On

Blocks that generate logic signals output a signal of boolean data type. This reduces the memory requirements of generated code.

Off

Blocks that generate logic signals output a signal of double data type. This ensures compatibility with models created by earlier versions of Simulink software.

Tips

Dependencies

Command-Line Information

Parameter: BooleanDataType
Type: string
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionOn

See Also

Signal storage reuse

Reuse signal memory.

Settings

Default: On

On

Simulink software reuses memory buffers allocated to store block input and output signals, reducing the memory requirement of your real-time program.

Off

Simulink software allocates a separate memory buffer for each block's outputs. This makes all block outputs global and unique, which in many cases significantly increases RAM and ROM usage.

Tips

Dependencies

This parameter enables:

Command-Line Information

Parameter: OptimizeBlockIOStorage
Type: string
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingOff
TraceabilityOff
EfficiencyOn
Safety precautionNo impact

See Also

Application lifespan (days)

Specify how long (in days) an application that contains blocks depending on elapsed or absolute time should be able to execute before timer overflow.

Settings

Default: inf
Min: Must be greater than zero
Max: inf

Enter a positive (nonzero) scalar value (for example, 0.5) or inf.

If you are licensed for the Real-Time Workshop® Embedded Coder™ product and select an ERT target for your model, the default value for Application lifespan (days) is 1.

This parameter is ignored when you are operating your model in external mode, have Mat-file logging enabled, or have a continuous sample time because a 64 bit timer is required in these cases.

Tips

Command-Line Information

Parameter: LifeSpan
Type: string
Value: positive (nonzero) scalar value or inf
Default: 'inf'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyFinite value
Safety precautioninf

See Also

Parameter structure

Control how parameter data is generated for reusable subsystems.

Settings

Default: NonHierarchical

Hierarchical

Generates a separate header file, defining an independent parameter structure, for each subsystem that meets the following conditions:

  • The subsystem's Real-Time Workshop system code parameter is set to Reusable function.

  • The subsystem does not violate any code reuse limitations.

  • The subsystem does not access parameters other than its own (such as parameters of the root-level model).

Each subsystem parameter structure is referenced as a substructure of the root-level parameter data structure, creating a structure hierarchy.

NonHierarchical

Generates a single, flat parameter data structure. Subsystem parameters are defined as fields within the structure. A nonhierarchical data structure can reduce compiler padding between word boundaries, producing more efficient compiled code.

Dependency

Command-Line Information

Parameter: InlinedParameterPlacement
Type: string
Value: 'Hierarchical' | 'NonHierarchical'
Default: 'NonHierarchical'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityHierarchical
EfficiencyNonHierarchical
Safety precautionNo impact

See Also

Enable local block outputs

Specify whether block signals are declared locally or globally.

Settings

Default: On

On

Block signals are declared locally in functions.

Off

Block signals are declared globally.

Tips

Dependency

Command-Line Information

Parameter: LocalBlockOutputs
Type: string
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingOff
TraceabilityNo impact
EfficiencyOn
Safety precautionNo impact

See Also

Ignore integer downcasts in folded expressions

Specify how Real-Time Workshop software handles casting of intermediate variables in mixed-bit systems.

Settings

Default: Off (GUI), 'on' (command-line)

On

Real-Time Workshop software collapses block computations into a single expression, avoiding casts of intermediate variables, improving efficiency. Check this parameter if:

  • You are concerned with generating the least amount of code possible.

  • Code generation and simulation results do not need to match.

Off (default)

The results of 8- and 16-bit integer expressions are explicitly downcast.

Tips

Dependency

This parameter requires a Real-Time Workshop license.

Command-Line Information

Parameter: EnforceIntegerDowncast
Type: string
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingOff
TraceabilityNo impact
EfficiencyOn
Safety precautionOff

See Also

Eliminate superfluous temporary variables (Expression folding)

Collapse block computations into single expressions.

Settings

Default: On

On
  • Enables expression folding.

  • Eliminates temporary variables, incorporating the information into the main code statement.

  • Improves code readability and efficiency.

Off

Disables expression folding.

Dependency

Command-Line Information

Parameter: ExpressionFolding
Type: string
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingOff
TraceabilityNo impact (for simulation and during development)
Off (for production code generation)
EfficiencyOn
Safety precautionNo impact

See Also

Reuse block outputs

Specify whether Real-Time Workshop software reuses signal memory.

Settings

Default: On

On (default)
  • Real-Time Workshop software reuses signal memory whenever possible, reducing stack size where signals are being buffered in local variables.

  • Selecting this parameter trades code traceability for code efficiency.

Off

Signals are stored in unique locations.

Dependency

Command-Line Information

Parameter: BufferReuse
Type: string
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingOff
TraceabilityOff
EfficiencyOn
Safety precautionNo impact

See Also

Inline invariant signals

Transform symbolic names of invariant signals into constant values.

Settings

Default: Off

On

Real-Time Workshop software uses the numerical values of model parameters, instead of their symbolic names, in generated code. An invariant signal is not inlined if it is nonscalar, complex, or the block inport the signal is attached to takes the address of the signal.

Off

Uses symbolic names of model parameters in generated code.

Dependency

Command-Line Information

Parameter: InlineInvariantSignals
Type: string
Value: 'on' | 'off'
Default: 'off'

Recommended Settings

ApplicationSetting
DebuggingOff
TraceabilityOff
EfficiencyOn
Safety precautionNo impact

See Also

Inlining Invariant Signals

Loop unrolling threshold

Specify the minimum signal or parameter width for which a for loop is generated.

Settings

Default: 5

Specify the array size at which the code generator begins to use a for loop instead of separate assignment statements to assign values to the elements of a signal or parameter array.

When there are perfectly nested loops, the code generator uses a for loop if the product of the loop counts for all loops in the perfect loop nest is greater than or equal to the threshold.

Dependency

This parameter requires a Real-Time Workshop license.

Command-Line Information

Parameter: RollThreshold
Type: string
Value: any valid value
Default: '5'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
Efficiency>0
Safety precaution>1

See Also

Remove root level I/O zero initialization

Specify whether to generate initialization code for root-level inports and outports set to zero.

Settings

Default: Off (GUI), 'on' (command-line)

On

Does not generate initialization code for root-level inports and outports set to zero.

Off

Generates initialization code for all root-level inports and outports. You should use the default:

  • To ensure that memory allocated for C MEX S-function wrappers is initialized to zero

  • For safety-critical applications that require that all internal and external data be initialized to zero

Dependencies

Command-Line Information

Parameter: ZeroExternalMemoryAtStartup
Type: string
Value: 'off' | 'on'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionOff

See Also

Use memset to initialize floats and doubles to 0.0

Specify whether to generate code that explicitly initializes floating-point data to 0.0.

Settings

Default: Off

On

Uses memset to clear internal storage for floating-point data to integer bit pattern 0 (all bits 0), regardless of type. An example of a case for selecting this option is to gain compiler efficiency when the compiler and target CPU both represent floating-point zero with the integer bit pattern 0.

Off

Generates extra code to explicitly initialize storage for data of types float and double to 0.0. The resulting code is slightly less efficient than code generated when you select the option.

You should not select this option if you need to ensure that memory allocated for C MEX S-function wrappers is initialized to zero.

Dependencies

Command-Line Information

Parameter: InitFltsAndDblsToZero
Type: string
Value: 'on' | 'off'
Default: 'off'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionNo impact

See Also

Remove internal state zero initialization

Specify whether to generate initialization code for internal work structures, such as block states and block outputs, to zero.

Settings

Default: Off (GUI), 'on' (command-line)

On

Does not generate code that initializes internal work structures to zero. An example of when you might select this option is to test the behavior of a design during warm boot—a restart without full system reinitialization.

Selecting this option does not guarantee that memory is in a known state each time the generated code begins execution. When you run a model or generated S-function multiple times, each run can produce a different answer.

If want to get the same answer on every run from a generated S-function, enter the command clear SFcnNam or clear mex in the MATLAB Command Window before each run.

Off

Generates code that initializes internal work structures to zero. You should use the default:

  • To ensure that memory allocated for C MEX S-function wrappers is initialized to zero

  • For safety critical applications that require that all internal and external data be initialized to zero

Dependencies

Command-Line Information

Parameter: ZeroInternalMemoryAtStartup
Type: string
Value: 'off' | 'on'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionOff

See Also

Optimize initialization code for model reference

Specify whether to generate initialization code for blocks that have states.

Settings

Default: on

On

Suppresses generation of initialization code for blocks that have states unless the blocks are in a system that can reset its states, such as an enabled subsystem. This results in more efficient code, but requires that you not refer to the model from a Model block that resides in a system that resets states. If you violate this constraint, Simulink software reports an error, in which case you can disable this optimization.

Off

Generates initialization code for all blocks that have states. Disable this option if the current model includes a subsystem that resets states, such as an enabled subsystem, and the model is referred to from another model with a Model block.

Dependencies

Command-Line Information

Parameter: OptimizeModelRefInitCode
Type: string
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionNo impact

See Also

Remove code from floating-point to integer conversions that wraps out-of-range values

Remove wrapping code that handles out-of-range floating-point to integer conversion results.

Settings

Default: Off

On

Removes code that ensures the execution of the generated code produces the same results as simulation when out-of-range conversions occur. Select this parameter if code efficiency is critical to your application and the following conditions are true for at least one block in the model:

  • Computing the block's outputs or parameters involves converting floating-point data to integer or fixed-point data.

  • The block's Saturate on integer overflow parameter is disabled.

Off

Out-of-range values simulation and generated code results match. The generated code is larger than when this parameter is checked.

Tips

cg_in_0_20_0[i1] = (int32_T)((rtb_Switch[i1] + 9.0) / 0.09375);

Dependency

This parameter requires a Real-Time Workshop license.

Command-Line Information

Parameter: EfficientFloat2IntCast
Type: string
Value: 'on' | 'off'
Default: 'off'

Recommended Settings

ApplicationSetting
DebuggingOff
TraceabilityOff
EfficiencyOn
Safety precautionOff (for simulation and during development)
On (for production code generation)

See Also

Remove code that protects against division arithmetic exceptions

Specify whether to generate code that guards against division by zero for fixed-point data.

Settings

Default: on

On

Does not generate code that guards against division by zero for fixed-point data. When you select this option, simulation results and results from generated code might not be in bit-for-bit agreement.

Off

Generates code that guards against division by zero for fixed-point data.

Dependencies

Command-Line Information

Parameter: NoFixptDivByZeroProtection
Type: string
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionOff

See Also

Use bitsets for storing state configuration

Use bitsets to reduce the amount of memory required to store state configuration variables.

Settings

Default: Off

On

Stores state configuration variables in bitsets. Potentially reduces the amount of memory required to store the variables. Potentially requires more instructions to access state configuration, which can result in less optimal code.

Off

Stores state configuration variables in unsigned bytes. Potentially increases the amount of memory required to store the variables. Potentially requires fewer instructions to access state configuration, which can result in more optimal code.

Tips

Command-Line Information

Parameter: statebitsets
Type: Boolean
Value: 1 | 0
Default: 0

Recommended Settings

ApplicationSetting
DebuggingOff
TraceabilityOff
EfficiencyOff
Safety precautionNo impact

See Also

Use bitsets for storing boolean data

Use bitsets to reduce the amount of memory required to store Boolean data.

Settings

Default: Off

On

Stores Boolean data in bitsets. Potentially reduces the amount of memory required to store the data. Potentially requires more instructions to access the data, which can result in less optimal code.

Off

Stores Boolean data in unsigned bytes. Potentially increases the amount of memory required to store the data. Potentially requires fewer instructions to access the data, which can result in more optimal code.

Tips

Command-Line Information

Parameter: databitsets
Type: Boolean
Value: 1 | 0
Default: 0

Recommended Settings

ApplicationSetting
DebuggingOff
TraceabilityOff
EfficiencyOff
Safety precautionNo impact

See Also

Minimize array reads using temporary variables

Minimize global array read operations by using temporary variables. In certain microprocessors, global array read operations are more expensive than accessing a temporary variable on the stack.

Settings

Default: Off

On

Uses temporary variables to access array data.

Off

Uses global memory to access array data.

Tips

Command-Line Information

Parameter: redundantloadelimination
Type: Boolean
Value: 1 | 0
Default: 0

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionNo impact

See Also

Model Parameter Configuration Dialog Box

The Model Parameter Configuration dialog box allows you to override the Inline parameters option (see Inline parameters) for selected parameters.

The dialog box has the following controls.

Source list

Displays a list of workspace variables. The options are:

Refresh list

Updates the source list. Click this button if you have added a variable to the workspace since the last time the list was displayed.

Add to table

Adds the variables selected in the source list to the adjacent table of tunable parameters.

New

Defines a new parameter and adds it to the list of tunable parameters. Use this button to create tunable parameters that are not yet defined in the MATLAB workspace.

Storage class

Used for code generation. See the Real-Time Workshop® User's Guide for more information.

Storage type qualifier

Used for code generation. See the Real-Time Workshop® User's Guide for more information.

Compiler optimization level

Sets the degree of optimization used by the compiler when generating code for acceleration.

Settings

Default: Optimizations off (faster builds)

Optimizations off (faster builds)

Specifies the compiler not to optimize code. This results in faster build times.

Optimizations on (faster runs)

Specifies the compiler to generate optimized code. The generated code will run faster, but the model build will take longer than if optimizations are off.

Tips

Command-Line Information

Parameter: SimCompilerOptimization
Type: string
Value: 'on' | 'off'
Default: 'off'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyNo impact
Safety precautionNo impact

See Also

Verbose accelerator builds

Select the amount of information displayed during code generation.

Settings

Default: Off

Off

Display limited amount of information during the code generation process.

On

Display progress information during code generation, and show the compiler options in use.

Command-Line Information

Parameter: AccelVerboseBuild
Type: string
Value: 'on' | 'off'
Default: 'off'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyNo impact
Safety precautionNo impact

See Also

For more information about AccelVerboseBuild , see Controlling Information During Code Generation.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS