Workaround For No Dynamic Memory Support In Embedded MATLAB Function Blocks
Background:
I have inherited a Discrete-Event Simulation MATLAB model and wish to automate and speed it's execution. Rather than calling sim(modelName) and having MATLAB run interpreted code, I would like a solution akin to calling system('modelName.exe ...'). My motivation for this comes from initial tests which suggest that a speed increase of nearly 1000%. I have managed to use the Real-Time Workshop with the Rapid Simulation target to produce an exe with static memory allocation. The problem is that there are Embedded MATLAB Function Blocks in the model for which the parameters will vary in size and shape in each run. And there will be hundreds if not thousands of runs.
According to the MathWorks documentation:
Dynamic Memory Allocation Not Supported for Embedded MATLAB Function Blocks:
"You cannot use dynamic memory allocation for variable-size data in Embedded MATLAB Function blocks. Use bounded instead of unbounded variable-size data."
Question:
What would be a potential workaround for this limitation?
Thoughts:
- Use a static variable sizes which are sufficiently large, and additionally pass int variables / tunable parameters to explicitly window the portion of the data to range over.
- S-Functions?
- What I'm implementing today: Programmatically recompile the simulation each time it's called to generate static code, dynamically.
- Port everything to a real/modern programming language such as python or c++.
Keywords: MATLAB dynamic memory allocation embedded Discrete Event Simulation Real-Time Worksho开发者_C百科p Simulink SimEvents Tunable Parameters
Following up on this years later... We went with the dynamic static recompilation I had implemented that day for a year or so, then another stats developer rewrote it in c++. Using the maximum possible memory every run simply wasn't a feasible waste of computing resources.
You should view this webinar : http://www.mathworks.com/company/events/webinars/wbnr43180.html . It explains an automatic solution similar to your first thought.
精彩评论