My understanding is that the argument cores
refers to the maximum number of MCMC chains to run in parallel, and the argument threads
refers to the number of threads to use within an MCMC chain. So the actual number of CPU cores used will be cores
* threads
.
In your case, you should set cores = 4
and threads = threading(4)
.
You can verify this yourself by looking at parts of the brms
source code to see how the brms
arguments are passed to the cmdstanr
backend. Here’s a relevant snippet of code:
c(args) <- nlist(
iter_sampling = iter - warmup,
iter_warmup = warmup,
chains, thin,
parallel_chains = cores,
show_messages = silent < 2,
show_exceptions = silent == 0,
fixed_param = algorithm == "fixed_param"
)
if (use_threading) {
args$threads_per_chain <- threads$threads
}
So the brms
arguments chains
, cores
, and threads
correspond to chains
, parallel_chains
, and threads_per_chain
respectively in the sample
method of cmdstanr
. You can then check the cmdstanr
documentation to verify my explanation above.