Threading in rstan 2.18

Hi @bgoodri,

guess I could just do this

fit1 <- stan(
  file = "schools.stan",  # Stan program
  data = schools_data,    # named list of data
  chains = 4,             # number of Markov chains
  warmup = 1000,          # number of warmup iterations per chain
  iter = 2000,            # total number of iterations per chain
  cores = 2,              # number of cores (could use one per chain)
  refresh = 0             # no progress shown
  )

That does not do anything unless your model is utilizing map_rect, which the 8 schools example does not. Just specify the cores argument when you call stan or first do options(mc.cores = 4).

1 Like

Hi @bgoodri,

Got it.

If the cores are already being used in parallel, then the only way to make it more faster is to use map reduce map_rect? ( after setting CXX14FLAGS += -DSTAN_THREADS in makeovers?)

Right, and even then it is only faster in particular cases (mostly ODE models).

hi @bgoodri

Im facing an issue where running my model on a Mac takes almost the same time as running the same model on an HPC cluster. I don’t see any significant improvement between the two?

for 10k iterations, I see only an efficiency of 12 mins. will there be more efficiency if I use the HPC cluster in a better way? I think as of now it is running all the chains simultaneously in different cores.

That is not uncommon, particular if you have as many cores on your Mac as chains you want to run. But stop doing 10k iterations; keep it at the defaults.

Hi @bgoodri,

What is the default iterations in stan? and why stop 10k iterations?

more no of iterations = more accuracy, right? In Jags also we do more iterations for more acccuracy in approximating posterior distributions?

The default number of post-warmup iterations is 1000, which is more than enough to estimate most things with enough accuracy.

So no one does 10k plus iterations?

So this is one of the main differences of Jags vs Stan?

People only do 10k iterations in very specialized circumstances or when they do not understand how much more efficient Stan is at obtaining a good effective sample size.

1 Like

Hi @bgoodri,

Thanks for the information. Now it is obvious to me which segment of people I belong to rn.