Main Content

Virtualized Output Ports Optimization

The virtualized output ports optimization lets you store the signal entering the root output port as a global variable. Clearing the MAT-file logging option and setting the TLC variable FullRootOutputVector to 0, both defaults for Embedded Coder®, eliminate code and data storage associated with root output ports.

Consider the model in the following block diagram. The signal exportedSig has exportedGlobal storage class.

In the default case, the output of the Gain block is written to the signal storage location, exportedSig. The code generator does not generate code or data for the Out1 block, which has become a virtual block.

/* Gain Block: <Root>/Gain */
  exportedSig = rtb_PulseGen * VirtOutPortLogOFF_P.Gain_Gain;

In cases where you enable MAT-file logging or set FullRootOutputVector = 1, the generated code represents root output ports as members of an external outputs vector.

The following code fragment was generated with MAT-file logging enabled. The output port is represented as a member of the external outputs vector VirtOutPortLogON_Y. The Gain block output value is copied to exportedSig and to the external outputs vector.

/* Gain Block: <Root>/Gain */
  exportedSig = rtb_PulseGen * VirtOutPortLogON_P.Gain_Gain;

/* Outport Block: <Root>/Out1 */
  VirtOutPortLogON_Y.Out1 = exportedSig;

Data maintenance in the external outputs vector can be significant for smaller models that perform benchmarks.

You can force root output ports to be stored in the external outputs vector (regardless of the setting of MAT-file logging) by setting the TLC variable FullRootOutputVector to 1. Add the statement

%assign FullRootOutputVector = 1

to the Embedded Coder system target file. Alternatively, you can enter the assignment from the MATLAB® command line using the set_param command, the model parameter TLCOptions, and the TLC option -a. For more information, see Specify TLC for Code Generation and Configure TLC.

For more information on how to control signal storage in generated code, see How Generated Code Stores Internal Signal, State, and Parameter Data and C Data Code Interface Configuration for Model Interface Elements.

Related Topics