On Building a fast R environment


In this article we will describe how to build an R distribution from source
using the Intel Compiler Suite.

Why?

The execution of R code can be significantly sped up when it is built
with a decent compiler and relies on fast mathematical libraries (mainly linear algebra).

Requirements

The installation (vide infra) was performed on a machine running on the Centos7 OS.
We also used the Intel Compiler Suite (Intel Parallel Studio XE 2017) and
its Math Kernel Library (MKL).

Installation Process

Downloading the source code

cd /uufs/chpc.utah.edu/sys/srcdir/R
wget http://cran.stat.ucla.edu/src/base/R-3/R-3.3.1.tar.gz
tar -zxvf R-3.3.1.tar.gz
mv R-3.3.1 3.3.1
cd 3.3.1

Setting up the Compiler Environment

module load intel/2017.0.098
echo $MKLROOT
export CC=icc
export CXX=icpc
export F77=ifort
export FC=ifort
export AR=xiar
export LD=xild
export CFLAGS=” -axCORE-AVX2,AVX,SSE4.2 -O3 -ipo -qopenmp -fPIC ”
export CXXFLAGS=” -axCORE-AVX2,AVX,SSE4.2 -O3 -ipo -qopenmp -fPIC ”
export FFLAGS=” -axCORE-AVX2,AVX,SSE4.2 -O3 -ipo -qopenmp -fPIC ”
export FCFLAGS=” -axCORE-AVX2,AVX,SSE4.2 -O3 -ipo -qopenmp -fPIC ”
export LIBDIR=\
/uufs/chpc.utah.edu/sys/installdir/intel/compilers_and_libraries_2017.0.098/linux/compiler/lib/intel64_lin
export LDFLAGS=” -Wl,-rpath=$MKLROOT/lib/intel64_lin \
-L$MKLROOT/lib/intel64_lin -lmkl_intel_lp64 \
-lmkl_core -lmkl_intel_thread \
-Wl,-rpath=$LIBDIR -L$LIBDIR -liomp5 -lpthread ”

Generation of the Makefile

cd /uufs/chpc.utah.edu/sys/builddir/R; mkdir 3.3.1i; cd 3.3.1i

# Configure (with BLAS & LAPACK MKL Support)
../../../srcdir/R/3.3.1/configure –prefix=/uufs/chpc.utah.edu/sys/installdir/R/3.3.1i \
–enable-R-profiling –enable-R-shlib –enable-memory-profiling \
–enable-java –enable-shared=yes –with-blas=”$LDFLAGS” \
–with-readline –with-tcltk –with-libpng –with-jpeglib –with-libtiff \
–with-ICU –with-pic –with-x –with-lapack

Output of the configure command


# ———————————————————————
R is now configured for x86_64-pc-linux-gnu

Source directory: ../../../srcdir/R/3.3.1
Installation directory: /uufs/chpc.utah.edu/sys/installdir/R/3.3.1i

C compiler: icc -std=gnu99 -axCORE-AVX2,AVX,SSE4.2 -O3 -ipo -qopenmp -fPIC
Fortran 77 compiler: ifort -axCORE-AVX2,AVX,SSE4.2 -O3 -ipo -qopenmp -fPIC

C++ compiler: icpc -axCORE-AVX2,AVX,SSE4.2 -O3 -ipo -qopenmp -fPIC
C++11 compiler: icpc -std=c++11 -axCORE-AVX2,AVX,SSE4.2 -O3 -ipo -qopenmp -fPIC
Fortran 90/95 compiler: ifort -axCORE-AVX2,AVX,SSE4.2 -O3 -ipo -qopenmp -fPIC
Obj-C compiler: gcc -g -O2 -fobjc-exceptions

Interfaces supported: X11, tcltk
External libraries: readline, BLAS(MKL), LAPACK(in blas), curl
Additional capabilities: PNG, JPEG, TIFF, NLS, cairo, ICU
Options enabled: shared R library, R profiling, memory profiling

Capabilities skipped:
Options not enabled: shared BLAS

Recommended packages: yes
# ———————————————————————

Building the executable/installation

make -j 16
make check
make install
make pdf
make install-pdf