Parfor sucessfully implemented in Dynare

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Parfor sucessfully implemented in Dynare

Postby eastnile » Fri Jul 17, 2015 8:48 pm

Dear Community,

I've recently implemented a parallelized version of the stoch_simul.m in order to speed up my computations. As mentioned in this thread, the main obstacle was the use of global variables; I've modified many of the original Dynare functions (such as set_random_seed) slightly so that they are passed local versions of M_, oo_, etc. My initial runs show very significant speedups if I run with the 4 cores on my CPU. Are any of you guys interested in this code? If so, I will clean up the files post them.

Best,
Zhao
eastnile
 
Posts: 8
Joined: Thu May 22, 2014 3:30 am
Location: Oregon, USA

Re: Parfor sucessfully implemented in Dynare

Postby hakeru7 » Thu Jul 30, 2015 1:24 am

Hi Zhao,

I've been struggling with this precise problem. I'm simply trying to parallelize stoch_simul on a cluster for different parameterization.

Any help/hint would be greatly appreicated!
hakeru7
 
Posts: 17
Joined: Sun Apr 19, 2015 4:10 am

Re: Parfor sucessfully implemented in Dynare

Postby jpfeifer » Thu Jul 30, 2015 10:51 am

Example codes please.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Parfor sucessfully implemented in Dynare

Postby hakeru7 » Fri Jul 31, 2015 6:04 pm

Here it is. Any tips would be helpful! Thank you!
Attachments
Loop_dynare.mod
(4.9 KiB) Downloaded 252 times
Loop_main.m
(1.15 KiB) Downloaded 246 times
hakeru7
 
Posts: 17
Joined: Sun Apr 19, 2015 4:10 am

Re: Parfor sucessfully implemented in Dynare

Postby jpfeifer » Wed Aug 05, 2015 6:09 am

Ok. I will try to walk you through this, but I need you to do some changes for me.

1. The function allcomb is missing
2. I need a clean mod-file without all the loop part. Please provide a mod-file that has the correct starting values for all parameters hard-coded and runs the desired simulations.
3. Please provide a description of the targets. That is, when you write
Code: Select all
X(5,ii) = oo_.mean(10);
, please provide me with a comment showing the name of the variable you are looking for. Variable 10 for example seems to be welfare.
4. Please replace
Code: Select all
    ppsipi = X(1,ii);
    ppsiy = X(2,ii);
    rrhor = X(3,ii);
    ppibar = X(4,ii);

by set_param_value statements like
Code: Select all
set_param_value('ppsiy',start_value)

where start_value is the value for the first loop step.
5. Please get rid of all parameter dependencies defined before the model block. If you have an analytic steady state, please use a steady_state_model block.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Parfor sucessfully implemented in Dynare

Postby hakeru7 » Thu Aug 06, 2015 8:44 pm

Thank you!

Here are the fixes....As you see, I'm looping over 4 coefficients and would like to run some big grids on parallel.
Attachments
Loop_main.m
(1.79 KiB) Downloaded 226 times
Loop_dynare.mod
(4 KiB) Downloaded 205 times
allcomb.m
(4.21 KiB) Downloaded 219 times
hakeru7
 
Posts: 17
Joined: Sun Apr 19, 2015 4:10 am

Re: Parfor sucessfully implemented in Dynare

Postby hakeru7 » Mon Aug 17, 2015 2:01 am

I'm still struggling with this. Any tips or hints on how to implement this...?
hakeru7
 
Posts: 17
Joined: Sun Apr 19, 2015 4:10 am

Re: Parfor sucessfully implemented in Dynare

Postby jpfeifer » Mon Aug 17, 2015 2:51 pm

This is somewhat more involved. First, you have to alter the dynare functions stoch_simul.m and disp_th_moments.m. For the latter, change the header to
Code: Select all
function oo_=disp_th_moments(dr,var_list,M_,options_,oo_)

(note that for some reasons the underscores are not displayed; just follow the already existing statements and variable definitions) and delete the
Code: Select all
global M_ oo_ options_

In stoch_simul.m change the call to
Code: Select all
            disp_th_moments(oo_.dr,var_list);

to
Code: Select all
    oo_=disp_th_moments(oo_.dr,var_list_,M_,options_,oo_);

Upon doing this, you should be able to use the attached code.
Attachments
Loop_parfor.zip
(4.56 KiB) Downloaded 238 times
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Parfor sucessfully implemented in Dynare

Postby hakeru7 » Tue Aug 18, 2015 2:22 pm

Thank you for your help! Made a couple of fixes and it seems to be working.

Changed the parfor loop to
Code: Select all
[a,b]=wrapper_function(X_in(:,ii),M_,options_,oo_,var_list_);
X_out(:,ii)=[a;b];


Two questions though,

1) It doesn't seem like stoch_simul needs to be altered. Since the loop calls resol.m directly and stoch_simul is only called in the first run, the original stoch_simul file seems to work.
2) the moments that return from the exercise are slightly off in decimal points compared to running a standalone mod-file once. Is this expected?

Thanks!
hakeru7
 
Posts: 17
Joined: Sun Apr 19, 2015 4:10 am

Re: Parfor sucessfully implemented in Dynare

Postby jpfeifer » Tue Aug 18, 2015 2:34 pm

1) The change to stoch_simul is needed to not break Dynare when executing it standalone. If you alter disp_th_moments in the describe way, you need to adapt Dynare to the new syntax.
2) No, this is not to be expected and may indicate there is something wrong. If you did not fix 1), this may be the reason.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Parfor sucessfully implemented in Dynare

Postby hakeru7 » Tue Aug 18, 2015 7:59 pm

I've changed the stoch_simul as you suggested and it's giving the same results that are slightly off.

What's weird is that the non-parallel loop I initially had is giving the same results as this parallelized version. It's the stand-alone that I run to check that is slightly off of these two....
hakeru7
 
Posts: 17
Joined: Sun Apr 19, 2015 4:10 am

Re: Parfor sucessfully implemented in Dynare

Postby jpfeifer » Wed Aug 19, 2015 8:17 am

Please provide code and instructions to replicate the issue.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare contributions and examples

Who is online

Users browsing this forum: No registered users and 1 guest