Chapter 7
Code Optimization
7-12
ni.com
Example 7-7 shows code generated without the reuse option, and
Example 7-8 shows code generated from the same models with the
maximal reuse option.
Example 7-7
Code Fragment without Reuse Optimization
/***** Local Block Outputs. *****/
RT_FLOAT model_2_1;
RT_FLOAT model_3_1;
RT_FLOAT model_4_1;
/***** Output Update. *****/
/* ---------------------------- Time Delay */
/* {model..5} */
if (INIT) {
X->model_5_S1 = 0.0;
}
Y->model_5_1 = X->model_5_S1;
/* ---------------------------- Gain Block */
/* {model..2} */
model_2_1 = 2.0*U->model_1;
/* ---------------------------- Sum of Vectors */
/* {model..3} */
model_3_1 = model_2_1 - U->model_1;
/* ---------------------------- Gain Block */
/* {model..4} */
model_4_1 = 3.0*model_3_1;
/***** State Update. *****/
/* ---------------------------- Time Delay */
/* {model..5} */
XD->model_5_S1 = model_4_1;
Example 7-8
Code Fragment Generated with Maximal Reuse Option (-Oreuse 2)
/***** Local Block Outputs. *****/
RT_FLOAT model_2_1;
RT_FLOAT model_3_1;
/***** Output Update. *****/
/* ---------------------------- Time Delay */
/* {model..5} */
if (INIT) {
X->model_5_S1 = 0.0;