Matlab coder automatically inlines m file returning multiple values
8 views (last 30 days)
Show older comments
I have a coder project with 2 .m files. The main .m file calls another .m file that returns multiple values. When I generate c files for the project, it automatically inlines the c code for the 2nd .m file in the c file for the main .m file (i.e. the c file generated for the 2nd .m is not used at all). I understand c functions can't return multiple values, but should the coder at least issue a warning and provide suggestions how to change the m code if I want to maintain the design hierarchy?
0 Comments
Accepted Answer
Mike Hosea
on 22 Aug 2011
Although I'm not an expert in the inlining heuristics of the compiler, I'm not aware that inlining has anything to do with the number of outputs. I should think at most it would imply a slight bias. Normally functions get inlined if they are short. You have both general and specific tools for controlling this. The general tool is
>> cfg = coder.config('lib');
>> cfg.InlineThreshold = 0;
>> codegen foo -args {blah1,blah2} -config cfg -report
This is a kind of "nuclear option". You can use a slightly larger InlineThreshold if you do want trivial functions inlined.
The specific method (and what I recommend) is
coder.inline('always')
coder.inline('never')
If you want the compiler to inline things automatically within toolbox functions but not to inline functions that you write, then you can just put coder.inline('never') at the top of each of your functions. -- Mike
4 Comments
Mike Hosea
on 26 Aug 2011
The compiler will generate such a function if there is one output and the inputs are, say, arrays, but I don't think you can coax it into generating that for a MATLAB function with multiple outputs.
Constant inputs to a function are normally specialized out by the compiler. I suppose the way around that is not to make them constants as far as the compiler knows. One trick is to have a formal input X to your testbench that you involve in the definition of these parameters. When I don't want the compiler to know something is a constant, I might add X to whatever constant value I wanted to give it. I then invoke the function with X = 0.
More Answers (0)
See Also
Categories
Find more on Execution Speed in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!