Bug?: Preprocessor substitution of model local variables

The current version of Dynare defines all model local variables in generated c (and m) files, but then never actually uses them, instead substituting in the expression every time the model local variable appears.

Firstly, this makes the C compiler’s job a lot harder and will generally result in suboptimal code. It is a lot easier for compilers to optimise out variables than it is for them to create new variables for common expressions.

Secondly, for models with a lot of model local variables, perhaps defined recursively, this results in massive output files, which then crash the compiler. In order to facilitate finding the steady state of my model I created a static version of my model and put in model local variables where ever possible. This results in the current version of Dynare spitting out 350MB C/M files. If the model local variables were actually used rather than being substituted in these files would be more like 350KB…

Tom

For anyone else I annoyed by this I attach my own preprocessor written in C# . Consider it released under the GPL.

It is by no means as robust as the Dynare one and it works solely on static model files (with no leads and lags), but this is all you need if you’re just trying to find the steady state. The input to it is the macro expanded output of Dynare.

The key thing is that whereas Dynare was making 350MB C files, this is making 89KB ones… Guess which the compiler prefers…
Program.cs.txt (5.79 KB)

Hi,

Thanks for reporting this problem. This is indeed a bug in the preprocessor, which has been fixed in the unstable version, and will be fixed in the next release.

Best,

hello,

my model has about 200 variables but a lot more (more than 2000) model-local variables. Does the presence of so many model-local variables slow down the preprocessor and hence I should try to minimize the model-local variables, thus reducing the readability of the code?

I would not expect any issues here. You should try. If it does not work as expected, you can still modify the code.