Compiling R
Overview
Unless you have very specific requirements, e.g. choice of compiler, you may use the installed R.
Instructions for compiling R 3.0.2
- source downloaded from: http://lib.stat.cmu.edu/R/CRAN/
Recipe (GCC)
Prerequisites
Modules:
- gcc/4.8.1
- proteus-lapack/gcc
NB R's use of BLAS does not conform to BLAS documentation, giving rise to run-time errors.[1] So, do not use an external BLAS.
Configure
export CFLAGS="-O2 -msse4.2 -mavx -mfpmath=sse -fPIC"
export CXXFLAGS="$CFLAGS"
export FCFLAGS="$CFLAGS"
./configure --prefix=/mnt/HA/opt/R/3.0.2 --enable-openmp \
--enable-largefile \
--with-lapack=$LAPACKLIBDIR/liblapack.a \
--with-system-zlib \
--with-system-bzlib --with-system-pcre
Recipe (ICC)
This is for R 3.4.4
Prerequisites
Modules:
- intel/composerxe/2015.1.133
- zlib/cloudflare/intel/2015/1.2.8
- bzip2/intel/2015/1.0.6
- xz/intel/2015/5.2.4 -- 5.2.3 causes errors during self tests
- pcre/intel/2015/8.40
- curl/intel/2015/7.52.1
- texinfo -- to build documentation
Configure
NOTES
- For some reason, PCRE stuff does not work when using the following.
The kluge is to hack the configure script.
- Works just fine in 3.4.4
- "-ipo" compile option may not work
- If configure gives "WARNING: you cannot build info or HTML versions of the R manuals", load texinfo module for newer texinfo
- To use MKL[2]
export CFLAGS="-O3 -ipo -xHost"
export CXXFLAGS="${CFLAGS}"
export FFLAGS="${CFLAGS}"
export FCFLAGS="${CFLAGS}"
export CPPFLAGS="-I${ZLIBINCDIR} -I${BZIP2INCDIR} -I${XZINCDIR} -I${PCREINCDIR} -I${CURLINCDIR} -I${MKLROOT}/include"
export LDFLAGS="-Wl,--no-as-needed -L${ZLIBDIR} -Wl,-rpath,${ZLIBDIR} -L${BZIP2DIR} -Wl,-rpath,${BZIP2DIR} -L${XZDIR} -Wl,-rpath,${XZDIR} -L${PCREDIR} -Wl,-rpath,${PCREDIR} -lpcre -L${CURLDIR} -Wl,-rpath,${CURLDIR}"
export MKLLINE="-L${MKLROOT}/lib/intel64 -Wl,-rpath,${MKLROOT}/lib/intel64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm -ldl"
./configure --prefix=$PREFIX --enable-openmp --enable-R-shlib --enable-shared --enable-rpath \
--enable-largefile --enable-nls \
--with-blas="${MKLLINE}" \
--with-lapack="${MKLLINE}" > & Configure.out &
Recipe (ICC 2019)
Compiler
- intel/composerxe/2019u1
Could probably work with any 2019 series.
Modules needed
- bzip2
- xz
- zlib/cloudflare
- pcre >= 8.20 with UTF-8 support
- curl >= 7.22.0
- texinfo to build documentation
Environment
export CPPFLAGS="-I${MKLROOT}/include"
export LDFLAGS="-L${MKLROOT}/lib/intel64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread"
export BLAS_LIBS=${LDFLAGS}
export LAPACK_LIBS=${LDFLAGS}
export CPPFLAGS="-I${BZIP2INCDIR} ${CPPFLAGS}"
export LDFLAGS="-L${BZIP2LIBDIR} -Wl,-rpath,${BZIP2LIBDIR} ${LDFLAGS}"
export CPPFLAGS="-I${ZLIBINCDIR} ${CPPFLAGS}"
export LDFLAGS="-L${ZLIBLIBDIR} -Wl,-rpath,${ZLIBLIBDIR} ${LDFLAGS}"
export CPPFLAGS="-I${XZINCDIR} ${CPPFLAGS}"
export LDFLAGS="-L${XZLIBDIR} -Wl,-rpath,${XZLIBDIR} ${LDFLAGS}"
export CPPFLAGS="-I${PCREINCDIR} ${CPPFLAGS}"
export LDFLAGS="-L${PCRELIBDIR} -Wl,-rpath,${PCRELIBDIR} ${LDFLAGS}"
export CPPFLAGS="-I${CURLINCDIR} ${CPPFLAGS}"
export LDFLAGS="-L${CURLLIBDIR} -Wl,-rpath,${CURLLIBDIR} ${LDFLAGS}"
export CFLAGS="-O3 -xHost"
export CXXFLAGS="${CFLAGS}"
export FCFLAGS="${CFLAGS}"
export FFLAGS="${CFLAGS}"
Configure
./configure --prefix=/mnt/HA/opt_rh68/R/intel/2019/3.5.3 --enable-R-shlib --enable-R-static-lib \
--enable-openmp --enable-largefile --enable-nls --enable-rpath \
--with-blas="-L${MKLROOT}/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -lpthread -ldl" \
--with-lapack="-L${MKLROOT}/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -lpthread -ldl"
Makevars for Compiling Packages
- Create the directory
~/.R
- Create the file
~/.R/Makevars
:
CXX14=icpc
CXX14FLAGS=-O3 -xHost
CXX14STD=-std=c++14
References
[1] https://stat.ethz.ch/pipermail/r-devel/2011-November/062581.html
[2] Intel Software Development Forums - Compiling R with MKL