Multithreading with map_rect takes more time

Hello all. I implemented multithreading with map_rect using this example (, but when I fit the same model with the same data with and without map_rect, it takes me 10 times longer to finish sampling with map_rect. Any ideas why this could be?
I use pystan 2.18 on mac.

Thank you!

PyStan 2.18 is pretty old and there’s a better version of map_rect called “reduce_sum” that was added to Stan 2.23 -

the CmdStan/Stan 2.24 release is due out today and CmdStanPy’s install_cmdstan() function will download and install the latest CmdStan release for you. It does require Python 3. hope this helps -

Thanks! Is pystan2.23 release any close? And is it a known issue that map_rect does not speed up sampling?
Update - I use pystan - is it still considered old?

Oh I just saw that CmdStanPy is a python module! That’s so cool. But I cannot see that it’s available for downloading…

it’s on PyPi -

1 Like

Sweet! Thanks so much – downloading rn :)

1 Like

What would be the cmdstanpy equivalent to cpp_options = list(stan_threads = TRUE) in R to compile a model that uses partial_sum? I tried different things, all failed…

When instantiating a CmdStanModel object, you can specify argument cpp_options as a dict with entries { 'STAN_THREADS' : True }, e,g:

logistic_model = CmdStanModel(stan_file=logistic_stan, cpp_options={ 'STAN_THREADS' : True})

sorry - the documentation is quite incomplete here - working on it. your feedback welcome!