【发布时间】:2019-12-17 02:56:40
【问题描述】:
请考虑以下小型 Modelica 模型和功能:
model VectorizeDemo
parameter Integer na=5;
final parameter Integer nb=2*na;
final parameter Real a[na] = {2*i for i in 1:na};
final parameter Real b[nb] = {3*i for i in 1:nb};
Real c[na];
Real d[na,nb];
protected
function myFun
input Real A;
input Real B;
output Real C;
algorithm
C:=tanh(A)*sin(B);
end myFun;
equation
c = sin(a);
//d = myFun(a,b);
// inner loop first
d = {myFun(a[i], b[j]) for j in 1:nb, i in 1:na};
end VectorizeDemo;
这将在 Dymola 中编译和模拟,但是查看 dsmodel.c 中的 C 代码,每个数组元素都被声明为一个新变量:
...
DeclareVariable("d[4, 10]", "", 38.0, 0.0,0.0,0.0,0,513)
DeclareVariable("d[5, 1]", "", 13.0, 0.0,0.0,0.0,0,513)
DeclareVariable("d[5, 2]", "", 16.0, 0.0,0.0,0.0,0,513)
DeclareVariable("d[5, 3]", "", 19.0, 0.0,0.0,0.0,0,513)
...
所以,如果我通过设置 na=1000 来增加数组大小,我将声明 1000*2000 个变量。显示的示例仍然可以编译,即使它需要很长时间,但我更复杂的用例在编译器 warning C4049: compiler limit, terminating line number emission 或 C1002 compiler is out of heap space 时失败。
旁注:较大的示例也需要几分钟的时间来检查,并且在模拟之后,在变量浏览器中展开变量时,GUI 将被阻塞很长时间。
是否有任何解决方法,例如重写我的代码或设置一些标志?临时增加堆空间?我只需要运行一次模型。对正在发生的事情的任何见解也将不胜感激。使用 Dymola 2020 和 VisualStudio 2017。
【问题讨论】:
-
经过思考,ScalableTestsuite 中的这个例子似乎也做了同样的事情:github.com/casella/ScalableTestSuite/blob/master/…
-
C1002 compiler is out of heap space错误有时可以通过Advanced.CompileWith64 = 2在 64 位模式下使用 Dymola 并可能还关闭其他应用程序(Chrome、Outlook 等)或使用具有更多内存的其他计算机来避免。跨度>
标签: arrays compiler-errors modelica dymola