Map_rect, rstan, and multiple chains

I have a quick question of how rstan deals with multithreading (using map_rect) and multiple cores.

I am interested in running 2 chains at once using a node with 24 processor on it. I have the model working with map_rect now and running with 1 chain. To use multiple threads I am calling:

Sys.setenv("STAN_NUM_THREADS" = 12)
mods <- stan(file="polar_voter_map.stan", cores=1, chains=1... 

If I change cores=2, will this try to use 24 threads then total? Or will it just use all 12 threads between the 2 chains? Or something else?

I would look on your system monitor, but I believe the 12 threads would be total and at any millisecond, each chain would tend to be using six threads each.

1 Like

This is on an HPC where it is harder for me to check. I can see what happens at lower scale with my laptop though. I assume that the behavior will hopefully be not too different.


FYI. It looks like it controls the number of threads were core/process. Setting it to 2 threads, with 2 cores, I had 2 rsession processes that were running at over 100% CPU.