BwUniCluster2.0/Software/R/Rstan: Difference between revisions
Line 1: | Line 1: | ||
= General information = |
|||
⚫ | |||
rstan provides the R interface for [https://mc-stan.org/ Stan], a platform for statistical modeling and high-performance statistical computation. |
|||
⚫ | |||
Note: Rstan depends on the V8 R package. |
|||
To be compatible with our R installation, we recommend to install the development version of rstan. |
|||
⚫ | |||
== Preparations == |
|||
Prepare .R directory (if it does not already exists). This is then filled with information how R should compile the packages ('compilation flags'). These are written (and can be reviewed) into the (text) file Makevars. |
|||
If you already have a .R/Makevars file, check whether these flags are already set. |
|||
<pre> |
<pre> |
||
cat ~/.R/Makevars |
|||
# Load the R software module, e.g. |
|||
</pre> |
|||
⚫ | |||
In this case, skip the following five command block |
|||
# Prepare .R directory (if it does not already exists) |
|||
⚫ | |||
<pre> |
|||
# Write the following environment variables to Makevars |
|||
⚫ | |||
echo "CXX14=icpc" >> ~/.R/Makevars |
echo "CXX14=icpc" >> ~/.R/Makevars |
||
echo "CXX14FLAGS=-O3 -fPIC -std=c++14 -axCORE-AVX512,CORE-AVX2,AVX -xSSE4.2 -fp-model strict -qopenmp" >> ~/.R/Makevars |
echo "CXX14FLAGS=-O3 -fPIC -std=c++14 -wd308 -axCORE-AVX512,CORE-AVX2,AVX -xSSE4.2 -fp-model strict -qopenmp" >> ~/.R/Makevars |
||
echo "CXXFLAGS += -std=c++14 -wd308" >> ~/.R/Makevars |
|||
echo "PKG_CXXFLAGS += -std=c++14 -wd308" >> ~/.R/Makevars |
|||
</pre> |
|||
The installation of rstan and its dependencies makes use other libraries (TBB, Threading Building Blocks) which need to be loaded before installation (and R, of course). |
|||
# Set up environment for V8 |
|||
<pre> |
|||
module purge |
|||
⚫ | |||
module load devel/tbb/2021.4.0 |
|||
</pre> |
|||
### 3a. Setting building environment |
|||
The installation process of rstan and its dependencies (Rcpp) needs input of how to use the TBB module. This is provided via specific environment variables. We also need to provide a further configuration information to install the R package v8 rstan depends on. |
|||
<pre> |
|||
export TBB_LIB=$TBB_LIB_DIR |
|||
export TBB_INC=$TBB_INC_DIR |
|||
export TBB_INTERFACE_NEW='true' |
|||
export DOWNLOAD_STATIC_LIBV8=1 |
export DOWNLOAD_STATIC_LIBV8=1 |
||
</pre> |
|||
== Installing the R package(s) [takes roughly 20 min] == |
|||
# Install V8 and Rstan packages from within R session |
|||
We can now install rstan (in its development version) and its dependencies within a R session |
|||
⚫ | |||
<pre> |
|||
salloc -t 30 -n 1 --mem=5000 -p dev_single |
|||
</pre> |
|||
Now, start R and install |
|||
<pre> |
|||
R -q |
R -q |
||
> install.packages |
> 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) |
|||
</pre> |
|||
== Testing the installation == |
|||
# Run a quick test |
|||
To check whether the installation worked, make a test run in R |
|||
<pre> |
|||
> library(rstan) |
|||
> example(stan_model, package = "rstan", run.dontrun = TRUE) |
> example(stan_model, package = "rstan", run.dontrun = TRUE) |
||
</pre> |
</pre> |
||
Additional information can be found at: https://github.com/stan-dev/rstan/wiki/Configuring-C-Toolchain-for-Linux |
|||
= Preparations to use the rstan package = |
|||
To run its applications, rstan compiles new scripts. For this, it again uses TBB, so you need to set the corresponding environment variables whenever you use rstan - as well as to load the R and TBB modules. |
|||
For this, we recommend to add the modules |
|||
<pre> |
|||
module load math/R/4.1.2 |
|||
module load devel/tbb/2021.4.0 |
|||
</pre> |
|||
as well as the three export commands |
|||
<pre> |
|||
export TBB_LIB=$TBB_LIB_DIR |
|||
export TBB_INC=$TBB_INC_DIR |
|||
export TBB_INTERFACE_NEW='true' |
|||
</pre> |
|||
to your [[BwUniCluster_2.0_Slurm_common_Features#sbatch_Examples | batch job scripts]] that use rstan or to run them directly in the command line if you use an [[BwUniCluster_2.0_Batch_Queues | interactive session]]. |
|||
---- |
|||
[[Category:BwUniCluster]] |
|||
[[Category:BwUniCluster_2.0]] |
Revision as of 13:41, 23 June 2022
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
Preparations
Prepare .R directory (if it does not already exists). This is then filled with information how R should compile the packages ('compilation flags'). These are written (and can be reviewed) into the (text) file Makevars.
If you already have a .R/Makevars file, check whether these flags are already set.
cat ~/.R/Makevars
In this case, skip the following five command block
mkdir -p ~/.R echo "CXX14=icpc" >> ~/.R/Makevars echo "CXX14FLAGS=-O3 -fPIC -std=c++14 -wd308 -axCORE-AVX512,CORE-AVX2,AVX -xSSE4.2 -fp-model strict -qopenmp" >> ~/.R/Makevars echo "CXXFLAGS += -std=c++14 -wd308" >> ~/.R/Makevars echo "PKG_CXXFLAGS += -std=c++14 -wd308" >> ~/.R/Makevars
The installation of rstan and its dependencies makes use other libraries (TBB, Threading Building Blocks) which need to be loaded before installation (and R, of course).
module purge module load math/R/4.1.2 module load devel/tbb/2021.4.0
- 3a. Setting building environment
The installation process of rstan and its dependencies (Rcpp) needs input of how to use the TBB module. This is provided via specific environment variables. We also need to provide a further configuration information to install the R package v8 rstan depends on.
export TBB_LIB=$TBB_LIB_DIR export TBB_INC=$TBB_INC_DIR export TBB_INTERFACE_NEW='true' export DOWNLOAD_STATIC_LIBV8=1
Installing the R package(s) [takes roughly 20 min]
We can now install rstan (in its development version) and its dependencies within a R session
Consider starting an interactive job for compiling. You need at least 5000MB total memory, e.g. start
salloc -t 30 -n 1 --mem=5000 -p dev_single
Now, start R and install
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)
Preparations to use the rstan package
To run its applications, rstan compiles new scripts. For this, it again uses TBB, so you need to set the corresponding environment variables whenever you use rstan - as well as to load the R and TBB modules.
For this, we recommend to add the modules
module load math/R/4.1.2 module load devel/tbb/2021.4.0
as well as the three export commands
export TBB_LIB=$TBB_LIB_DIR export TBB_INC=$TBB_INC_DIR export TBB_INTERFACE_NEW='true'
to your batch job scripts that use rstan or to run them directly in the command line if you use an interactive session.