嵌入式 MATLAB 函数块中不支持动态内存的解决方法
背景:
我继承了离散事件模拟 MATLAB 模型,并希望自动化并加快其执行速度。我想要一个类似于调用 system('modelName.exe ...') 的解决方案,而不是调用 sim(modelName) 并让 MATLAB 运行解释代码。我这样做的动机来自于初步测试,该测试表明速度提高了近 1000%。我已成功使用带有快速模拟目标的实时研讨会来生成具有静态内存分配的 exe。问题在于模型中存在嵌入式 MATLAB 函数块,其参数在每次运行中的大小和形状都会有所不同。并且将会有数百甚至数千次运行。
根据 MathWorks 文档:
嵌入式 MATLAB Function 模块不支持动态内存分配:
“您不能对嵌入式 MATLAB Function 模块中的可变大小数据使用动态内存分配。使用有界而不是无界可变大小数据。 ”
问题:
此限制的潜在解决方法是什么?
想法:
- 使用足够大的静态变量大小,并另外传递 int 变量/可调参数来显式窗口要范围的数据部分。
- S功能?
- 我今天正在实现的内容:每次调用模拟时以编程方式重新编译模拟以动态生成静态代码。
- 将所有内容移植到真实/现代的编程语言,例如 python 或 c++。
关键字: MATLAB 动态内存分配嵌入式离散事件仿真实时研讨会 Simulink SimEvents 可调参数
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 Workshop Simulink SimEvents Tunable Parameters
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几年后的后续工作...我们采用了我那天实现的动态静态重新编译一年左右的时间,然后另一位统计开发人员用 C++ 重写了它。每次运行都使用最大可能的内存并不是一种可行的计算资源浪费。
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.
您应该观看此网络研讨会:http://www.mathworks.com/company/events /webinars/wbnr43180.html 。它解释了与您的第一个想法类似的自动解决方案。
You should view this webinar : http://www.mathworks.com/company/events/webinars/wbnr43180.html . It explains an automatic solution similar to your first thought.