Best way to kill chains prior to completing using RStan

This is something I’ve been noticing for a while, but without a good way to measure or assess. When developing my models, I will occasionally halt a model prior to all chains completing (for example I notice an error in my code or in my data, or decide I want to change a prior). Typically I’ve got chains running in parallel and I use RStudio and so I’ve just been using the little Stop sign in the console (also Interrupt R in the Session menu). If I then immediately restart sampling, the next run of the model will take significantly longer to evaluate the gradient and sample. Even if I do not immediately restart sampling, I sometimes notice that my CPU fan is running loudly even when I’m not asking it to do much. I find I need to restart the computer to achieve a similar gradient evaluation time or to stop the CPU fan running.

From what I understand after doing a bit of googling R does not actually terminate the child process that run in other languages (C/FORTRAN, etc). So my hunch is that my chains are actually still running in some form even if they’re no longer communicating with R. Is there a better way to kill these chains other than restarting the computer?

Operating System: Windows 7 and Windows 10
Interface Version: Rstan 2.17.3, R 3.4.2, RStudio 1.1.383
Output of writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”))):
Output of devtools::session_info("rstan”):

1 Like

Yes. Execute

system("taskkill /F /IM R.exe /T")

in RStudio which somehow manages not to kill RStudio with it. On !Windows, the equivalent is

system("killall R")
1 Like

Newer versions of RStudio have a terminal window that you can open an independent R session in. Ctrl+c will stop all of the rstan threads.