Skip to content

Instantly share code, notes, and snippets.

@stemangiola
Last active March 21, 2019 04:47
Show Gist options
  • Save stemangiola/3aa085238738d58fa2536d4e024f12f1 to your computer and use it in GitHub Desktop.
Save stemangiola/3aa085238738d58fa2536d4e024f12f1 to your computer and use it in GitHub Desktop.
Installation of rstan for big machines
####################################################################
# From within R
####################################################################
####################################################################
# Initialisation of makefiles
####################################################################
dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "Makevars")
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native -mtune=native",
"CXX14FLAGS += -fPIC",
file = M, sep = "\n", append = TRUE)
####################################################################
# Load at startup updates modules on compiler
####################################################################
N <- file.path(Sys.getenv("HOME"), ".bashrc")
cat(
"module load gcc",
"module load openmpi",
file = N, sep = "\n", append = TRUE
)
####################################################################
# Load the file that load's the compiler. Nice eh!
####################################################################
Q <- file.path(Sys.getenv("HOME"), ".bash_profile")
if (!file.exists(Q)) file.create(Q)
cat(
"\n# Get the aliases and functions",
"if [ -f ~/.bashrc ]; then",
" . ~/.bashrc",
"fi",
file = Q, sep = "\n", append = TRUE
)
####################################################################
# Clean the environment
####################################################################
remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")
####################################################################
# Install rstan
####################################################################
install.packages("rstan", type = "source")
####################################################################
# You need to do this for some machines
####################################################################
install.packages("Rcpp")
####################################################################
# Test. Are you believer?
####################################################################
y <- as.matrix(read.table('https://raw.github.com/wiki/stan-dev/rstan/rats.txt', header = TRUE))
x <- c(8, 15, 22, 29, 36)
xbar <- mean(x)
N <- nrow(y)
T <- ncol(y)
rats_fit <- stan('https://raw.githubusercontent.com/stan-dev/example-models/master/bugs_examples/vol1/rats/rats.stan')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment