﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3252	Abnormal memory consumption during compilation of models with inlined functions and symbolic differentiation	Francesco Casella	Volker Waurich	"Please consider the SmoothSat model in the attached Save Total file. The inline smoothSat function

{{{
function smoothSat ""Smooth saturation function""
  input Real x;
  input Real xmin ""Lower bound of range where y = x"";
  input Real xmax ""Upper bound of range where y = x"";
  input Real dxmin ""Width of lower smoothing range"";
  input Real dxmax=dxmin ""Width of upper smoothing range"";
  output Real y;
algorithm
   y := if x < xmin + dxmin then xmin + dxmin - dxmin*(xmin + dxmin - x)/(dxmin^4 + (xmin + dxmin - x)^4)^0.25 else if x > xmax - dxmax then xmax - dxmax + dxmax*(x - xmax + dxmax)/(dxmax^4 + (x - xmax + dxmax)^4)^0.25 else x;
  annotation (smoothOrder=4, InLine=true);
end smoothSat;
}}}
gets differentiated 5 times in the test model SmoothSat.

The Cryogenics_Test_SmoothSat.c file defines about 10000 temporary expressions. Most of them are repeated a lot of times: for example, (1.0 + (0.1 - time)) is repeated 5021 times, (time + -1.7) is repeated 4520 times.

When compiling the C code under MinGW with the default settings, cc1.exe allocates over 3 GB of memory (!). Removing the 5th differentiation brings down memory allocation to 300 MB.

Differentiating an expression 5 times is probably a bit extreme (the idea was to check that the first 4 derivatives are continuous, and only the 5th is discontinuous), however there is something going badly wrong with common subexpressions in the differentiated functions, and I guess this is worth having a look at.
"	defect	assigned	normal	Future	Backend	trunk			stefano.carli@… Patrick Täuber
