Opened 10 years ago

Closed 4 years ago

#3244 closed defect (fixed)

Removing unnecessary vectorization of assignments in Front-end.

Reported by: Mahder Alemseged Gebremedhin Owned by: Willi Braun
Priority: normal Milestone: 1.16.0
Component: New Instantiation Version: trunk
Keywords: Cc:

Description

Currently we vectorize assignment statements in the front end. This is not really necessary and should be avoided since we end up having to reconstruct the arrays at runtime.

function testfunc
  input Real t;
  output Real o = t;
protected
  Real[2] r1,r2;
algorithm
  r1 := {1.0,2.0};
  r2 := r1; // This shouldn't be vectorized
end testfunc;

model vectortest
  Real i;
equation
  i = testfunc(time);
end vectortest;

The assignment r2 := r1; gets expanded to r2 := {r1[1], r1[2]}; by the front end. This ends up with code

array_alloc_scalar_real_array(&tmp1, 2, (modelica_real)(*real_array_element_addr(&_r1, 1, (modelica_integer) 1)), (modelica_real)(*real_array_element_addr(&_r1, 1, (modelica_integer) 2)));
copy_real_array_data(tmp1, &_r2);

instead of what we get for the non vectorized version

copy_real_array_data(r1, &_r2);

The case becomes worse when the arrays are bigger and in loops.

so I fixed it now except I had one model failing due to some issues with linear and non linear systems in the back-end (plus two cpp tests but those are compilation issues of generated code and should be easy to fix)

Modelica.Mechanics.MultiBody.Examples.Elementary.PointGravityWithPointMasses2 is the culprit.

Willi it's all yours now. The patch for the changes to the front end and expected outputs for some models in the testsuite is attached.

Attachments (1)

NoExpandAssignments.patch (1.4 MB ) - added by Mahder Alemseged Gebremedhin 10 years ago.
Patch file with the changes

Download all attachments as: .zip

Change History (2)

by Mahder Alemseged Gebremedhin, 10 years ago

Attachment: NoExpandAssignments.patch added

Patch file with the changes

comment:1 by Per Östlund, 4 years ago

Component: BackendNew Instantiation
Milestone: Future1.16.0
Resolution: fixed
Status: newclosed

The new frontend does not scalarize such assignments.

Note: See TracTickets for help on using tickets.