Threading (map_rect) and memory corruption errors


#1

I have been getting a great improvement in speed since I implemented threading (map_rect) on my hierarchical ODE model and I would like to thank the developing team for your effort.

I’ve been noticing that my stan programme terminates with a memory corruption error ((malloc(): memory corruption) on some, but not all instances. I have not carried out a systematic test to paint a global view of this issue, but I can anecdotally report that I have not encountered the error as long as I keep the number of threads at 2 (as in Sys.setenv(STAN_NUM_THREADS = 2). Also, the error appears more prevalent when the number of subjects increases in my fitting attempt.

I’m wondering whether this has something to do with my server (CentOS Linux 7; gcc 8.2), or there is something I can do from a coding perspective to prevent this error. Unfortunately, I don’t have the right to distribute the data that is fitted in my model, but I would be grateful if there are pointers on this issue.


#2

Bad news… we just found a serious bug only when STAN_NUM_THREADS = 2. See: stan-dev/stan#2708.

Do you know if this happens with STAN_NUM_THREADS = 1?


#3

‘STAN_NUM_THREADS = 1’ has been working fine for me.