I’m wondering if it’s possible to subdivide 3 chains in JAGS on 5 or 6 cores, for example. Here is my code:
library(parallel)
# There is no progression bar using parallel
jags.parallel(data = d$data,
inits = d$inits,
parameters.to.save = d$params,
model.file = model.jags,
n.chains = 3,
n.thin = 10,
n.iter = 9000,
n.burnin = 3000,
working.directory = NULL,
n.cluster = 3) ## the number of cluster it’s taking
As you can see, and this is the default, the number of chains (nc
here which is 3 in my case) equals the number of core used.
Error in res[[ch]] : subscript out of bounds
. Why? My computer has 16 cores, so I have flexibility on the number of cores (also have 64 GB of RAM and 3 GHz Intel Xeon E5 processor).
It would not be possible to split 3 chains onto multiple cores. When running JAGS in parallel here is effectively what happens:
Do the specified burn in for each chain. In your example, the three chains would run the model for 3000 steps and not store that information.
Once each chain has had the appropriate burn in time, the number of samples you want from the posterior distribution is split equally over each chain. In your example, each chain would run the sampler for 600 steps ((n.iter -n.thin)/n.chains
).
So, let's move on to your questions (# 1 is explained above).
The answer to this will depend on what else you are doing on that computer at the time. You never want to run it on all K cores of your computer as it will take up most of your computing power. I generally run K-1 chains on K-1 cores for larger models. For simple models, it does not really matter.
You could have multiple chains run on fewer cores, but then you are slowing things down because each chain on a core would have to be computed sequentially. Conversely, it would not work to farm out fewer chains onto multiple cores. If you have x
chains, you should not have > x cores
.
This is answered through questions 2 and 3. More chains should increase computing, but more cores without more chains will not.
This really cannot be answered without looking at your model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With