Are there any tools to optimize autogenerated code to reduce time and memory?

The autogenerated code generates very reliable code. How ever lots of "extra" steps are generated that require a lot more memory than needed. Is there a 3rd party product that can reduce the amount of unneeded code?

Answers (1)

I've noticed the autocoder stores the initial matrix from a constant block in global memory even if the matrix is all zeros or is initialized to zero on each iteration.
For example, I have a matrix of size 30x30 and I want to initialize the matrix to zero then set the elements of the matrix individually. I've noticed the autocoder stores the initial matrix as global variable even (if it is ALL zeros) then copies the zero matrix to the variable using a for loop. I thought I had found a solution by using a gain block of zero immediately after the constant block because in some instances I get the desired behavior of using memset():
/* Gain: '<S10>/Replace memcpy() with memset()' incorporates:
* Constant: '<S10>/Constant'
*/
memset((void *)
(&localB->B
[0]), 0, 900U * sizeof(real_T));
but in other instances the autocode uses a for loop and the global variable:
/* Gain: '<S17>/Replace memcpy() with memset()' incorporates:
* Constant: '<S17>/Constant'
*/
for (i = 0; i < 900; i++) {
Subsystem_1Hz_B.Q_g[i] = 0.0 * zero_ns_x_ns[i];
}
to set the matrix equal to zero.
I was hoping the autocoder would always use memset() so I could get rid of the zero_ns_x_ns variable from global memory. Note: zero_ns_x_ns is not used anywhere else in the code except to initialize a variable to zero.
Any recommendation on an efficient way to create a zero matrix and set the elements?

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Asked:

on 4 Jun 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!