在Dymola中编译大型数组 [英] Compile large array in Dymola

查看:140
本文介绍了在Dymola中编译大型数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下小型Modelica模型和功能:

Please consider the following small Modelica model and function:

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代码,每个数组元素都被声明为新变量:

This will compile and simulate in Dymola, but looking at the C code in dsmodel.c every array element is declared as a new variable:

...
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 emissionC1002 compiler is out of heap space上失败了.

So, if I increase the array size by setting na=1000 I will have 1000*2000 variables declared. The shown example will still compile, even though it takes very long, but my more complex use case fails with compiler warning C4049: compiler limit, terminating line number emission or with C1002 compiler is out of heap space.

注释:较大的示例也将花费几分钟的时间进行检查,并且在仿真之后,在变量浏览器中展开变量时,GUI会被保留一段时间.

Sidenotes: The larger example will also take several minutes to check, and after simulation the GUI will be blocked for ages when unfolding the variables in the variable browser.

有没有解决方法,例如重写我的代码或设置一些标志?暂时增加堆空间?我只需要运行一次模型.对正在发生的事情的任何见解也将不胜感激.在Visual Studio 2017中使用Dymola 2020.

Is there any workaround, like rewriting my code or setting some flag? Temporarily increase heap space? I need to run the model only once. Any insight in what is happening would also be appreciated. Using Dymola 2020, with VisualStudio 2017.

推荐答案

默认情况下,所有Modelica编译器都会将所有数组(函数记录中的数组有某些例外)扩展为标量. OpenModelica开始在前端和后端的非扩展阵列上进行一些工作.看: http://www.ep.liu.se/ecp/157/071/ecp19157071.pdf

By default all Modelica Compilers will expand all arrays (there are some exceptions like arrays in records in functions) into scalars. OpenModelica started some work on non-expanding arrays in the front-end and back-end. See: http://www.ep.liu.se/ecp/157/071/ecp19157071.pdf

这篇关于在Dymola中编译大型数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆