BwUniCluster2.0/Software/R/Rstan

From bwHPC Wiki
< BwUniCluster2.0‎ | Software‎ | R
Revision as of 18:08, 30 October 2024 by K Kuck (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

General information

rstan provides the R interface for Stan, a platform for statistical modeling and high-performance statistical computation.

To be compatible with our R installation, we recommend to install the development version of rstan.

Installation instructions

Please enter the following code, presented in the boxes below, directly in your shell/command line on bwUniCluster2.0.

Preparations

Installing glmnet involves compiling source code. Therefore, ensure that the following flags are set in $HOME/.R/Makevars:

cat ~/.R/Makevars

CXX14=g++
CXX17=g++
CXX14FLAGS += -std=c++14
CXX17FLAGS += -std=c++17
CXXFLAGS = -O3 -fPIC -march=cascadelake -ffp-contract=off -fno-fast-math -fno-signed-zeros -fopenmp -Wno-unknown-warning-option

If necessary, the appropriate compiler flags can be set by running the following lines of code:

mkdir -p ~/.R
echo "CXX14=g++" > ~/.R/Makevars
echo "CXX17=g++" >> ~/.R/Makevars
echo "CXXFLAGS = -O3 -fPIC -march=cascadelake -ffp-contract=off -fno-fast-math -fno-signed-zeros -fopenmp -Wno-unknown-warning-option" >> ~/.R/Makevars
echo "CXX14FLAGS += -std=c++14" >> ~/.R/Makevars
echo "CXX17FLAGS += -std=c++17" >> ~/.R/Makevars

Since installing glmnet involves compiling, we start an interactive session on one of the compute nodes:

salloc -n 1 -t 30  -p dev_single


Within the interactive session, load the R 4.4.1 module and provide configuration information to install the R package v8, rstan depends on.

# Load the R software module:
module load math/R/4.4.1-mkl-2022.2.1-gnu-13.3

# Provide configuration information for the v8 R package
export DOWNLOAD_STATIC_LIBV8=1

Installing the R package(s) [takes roughly 20 min]

Now, start R and install RStan using the lines of code below:

R -q
> install.packages("remotes")
> install.packages("RcppParallel")
> install.packages("V8")
> remotes::install_github("hsbadr/rstan/StanHeaders@develop", force = TRUE)
> remotes::install_github("hsbadr/rstan/rstan/rstan@develop", force = TRUE)

Testing the installation

To check whether the installation worked, make a test run in R

> library(rstan)
> example(stan_model, package = "rstan", run.dontrun = TRUE)