Skip to content

Instantly share code, notes, and snippets.

@nstjhp
Created December 22, 2021 17:27
Show Gist options
  • Save nstjhp/630a025f43e6111882b91b1c6481b8ce to your computer and use it in GitHub Desktop.
Save nstjhp/630a025f43e6111882b91b1c6481b8ce to your computer and use it in GitHub Desktop.
Test if R/Rstudio can run Stan with multiple cores or just hangs
# Test if R/Rstudio can run Stan with multiple cores or just hangs
t1dat = list(N=100, y = rnorm(100))
default_Stan_normal = "
// The input data is a vector 'y' of length 'N'.
data {
int<lower=0> N;
vector[N] y;
}
// The parameters accepted by the model. Our model
// accepts two parameters 'mu' and 'sigma'.
parameters {
real mu;
real<lower=0> sigma;
}
// The model to be estimated. We model the output
// 'y' to be normally distributed with mean 'mu'
// and standard deviation 'sigma'.
model {
y ~ normal(mu, sigma);
}
"
getOption("mc.cores")
f3 = rstan::stan(model_code = default_Stan_normal, data=t1dat)
f3
options(mc.cores = 1)
getOption("mc.cores")
f3 = rstan::stan(model_code = default_Stan_normal, data=t1dat)
f3
options(mc.cores = 2)
getOption("mc.cores")
f3 = rstan::stan(model_code = default_Stan_normal, data=t1dat)
f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment