Calibration and Parallelization

Dear all,

I have a question on the usage of globals when trying to calibrate a model in Dynare. In my objective function I try to find the parameter combination that minimizes squared distances between data targets and model outcomes. In my execution file, I run my mod-file first and solve the problem (the objective function attached) using Multistart and the fmincon solver.
When the model is approximated at first order, the simulations run at a reasonable time range. However, when using order=3, the code runs for a very long time. Since MultiStart can be applied with parpool in Matlab, I tried to exploit this option. However, since in the objective function the output oo_ from Dynare is declared as a global, parallelization does not work. If I do not declare it as a global, stoch_simul does not simulate for the new parameter values specified with set_param_value.
Is there an option to get around the global variable in the objective function or to increase speed in another way when using a third order approximation?

Thank you a lot for your help! :slight_smile: :slight_smile:C11.m (4.7 KB)

Hi,

Unfortunately, I think that oo_ is not the main problem for parallelization… We have other important globals deeper in Dynare’s codes. For instance, the vector of parameter values is stored in a global structure (M_.params). This one is not apparent in your routine but it’s there (in stoch_simul).

A solution could be to simulate shorter time series in parallel and report the average of the simulated moments. This would have to replace your call to stoch_simul.

Best,
Stéphane.

Thank you for your fast reply :slight_smile: :slight_smile:
I still have some trouble in understanding how I could implement some speed-up of the code. Can you maybe give me some example, how I could get around stoch_simul?
I checked the resol function, which “only” computes the perturbation based decision rules. Then by producing my own shock sequence and using the coefficient matrices, I could simulate my own series. However, resol also needs the global variables oo_ and M_ as inputs, which will be part of my objective function. I would be very thankful for some more hints. :slight_smile:

Using low-level functions like resol to solve the model should work. The trick is to use a local copy of the globals here. Of course, you cannot use set_param_value in this case, but it is easy to replicate its functionality for you local copy of the globals. Regarding simulations, you can use a modified version of simult_ that makes the globals local. There is no particular reason they are global.

Thank you very much, I will try to follow your advice! :slight_smile: