MATRIXx

cancel
Showing results for 
Search instead for 
Did you mean: 

Using global variables in autocode

I am trying to get Autocode to generate code that uses global variables for the input and output signals instead of using procedure parameters.
The reason I am doing this is that there seems like parameter transfered variables will result in additional execution load, especially if a lot of input/output signals are used (which is true in my case).
 
I my case I have a number of SystemBuild models which I want to generate code from and link together, and if I can't get Autocode to use global variables it seems that the performance will be significantly lower than otherwise due to all the copying that will take place.
 
I have tried the "allgscope" option, but it is not useful for me; since, firstly it only applies to output variables, and secondly, it seems that the content of the global variables will also be written to local copies of the variables (which means that there will be no performance benefit).
 
I have also tried setting "Input scope" for the input parameters, but since that option is only available for procedure superblocks, it is not useful in my case. (My models use discrete superblock as the topmost block.)
 
I have searched the MatrixX documentation, but found no solution that seems to work for me.
I am thankful for any advice regarding this.
 
Currently I am generating C code (although it seems like these kinds of settings should be language-independent).
0 Kudos
Message 1 of 2
(7,415 Views)
It sounds like there may be a couple ways that I've used in the past to satisfy these type of code optimization techniques.
 
1.  Use Read/Write variable block connections to SuperBlock inputs and outputs then using Procedure Superblocks.  This allows for both simulation and autocode to have similar implementation and responses.  A system designed in this manner would consist of top level Superblocks that would have no connections (or minimul) and all data interfaces would be through these Global variable interfaces.  Strategic use of sequence blocks would also be necessary since the evaluation order would have to be manually controlled.  The disadvantage of this technique is that id does not allow the SystemBuild analysis the capability to detect any algebraic loop situations that may exist.
 
2.  Modify the architecture of the Model to use strategic set of Procedure Superblocks.  Also to minimize a lot of "copying", strategic use of Inline Procedure blocks can be used.  This provides a tradeoff of code space for execution time.  One thing to watch out for in use of "Inline" procedure blocks is the use of "Local" Read/Write variables.  If using "Re-Use temporary variables" optimization settings of the autocoder, this can cause incorrect results.  The work-around is to force evaluation order through the use of Sequencing blocks.
 
Hope that helps, as there are lots of tradeoffs available for optimal code generation techniques.
 
0 Kudos
Message 2 of 2
(7,412 Views)