Parallel computing with WinBUGS/OpenBUGS by using the snowfall package in R: Part 2

This is the continuum of the last post about how I use the snowfall package in R to run parallel WinBUGS/OpenBUGS on multiple processors.  The last post explains the way how I run several MCMC chains on multiple processors, to be precise, 2 MCMC chains of a regression model on a PC with Intel Core2 Duo CPU.

In this post, I introduce parallel running OpenBUGS on a Linux cluster with several hundred multi-core nodes available at Brown (i.e. Oscar).  The task is the same.  I have simulated 100 datasets, for each of which I created 8th-fold subsets for the purpose of cross validation.  I need to fit a Bayesian regression model to each subset, that is, 800 regressions in total.  The approach is essentially the same as in the previous post, except that instead of distributing multiple MCMC chains, I distribute multiple datasets and the corresponding model fitting on multiple cores.

The code begins with a similar fashion.  I’m using OpenBUGS instead of WinBUGS since I’m running on a Linux cluster.  For each regression model, I run 3 MCMC chains, and for each chain, I run 50,000 iterations.

Next, I start looping through the 100 simulations, for each of which I will simultaneously fit separate regression models to the 8 cross-validation sub datasets by launching 8 parallel OpenBUGS on 8 cores.  Therefore, I initialize parallel computing setups at the beginning of the loop.  As before, the command stInit initializes a 8-core (the parameter cpus = nCPU = kFold = 8 as defined above) parallel computing.  The command sfExportAll() exports all the variables/data defined above to all the 8 cores.  The command sfLibrary(R2OpenBUGS) loads the R2OpenBUGS package on all the 8 cores in order to call OpenBUGS from R.  The command sfClusterSetupRNG() set different random streams for the 8 cores, which is actually unnecessary because I’m not running several MCMC chains for the same data on different cores.

Then, I use the command sfLapply to distribute 8 cross-validation subsets to 8 cores by putting data loading, model estimating, and results saving steps into a function.  Notice that the fancy bracket opens at line 40 and closes at line 69.  The command sfStop stops the parallel computing.  The closing fancy bracket at line 71 closes the for loop started at line 31 above.

About these ads
This entry was posted in Research. Bookmark the permalink.

1 条 Parallel computing with WinBUGS/OpenBUGS by using the snowfall package in R: Part 2 的回复

  1. Pingback引用通告: Parallelizing OpenBUGS on a single Windows PC | R you cereal?

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s