Page 1 of 1

Bug?: Preprocessor substitution of model local variables

PostPosted: Sat Jul 03, 2010 1:48 pm
by cfp
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

Re: Bug?: Preprocessor substitution of model local variables

PostPosted: Sun Jul 04, 2010 1:55 am
by cfp
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...

Re: Bug?: Preprocessor substitution of model local variables

PostPosted: Thu Aug 19, 2010 1:21 pm
by SébastienVillemot
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,