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.