Unable to install Rstan on an old linux computer cluster

Hi, I’ve been using rstan for quite a while, but am a Linux beginner. Recently I needed to install Rstan on a pretty old Linux computer cluster and ran into some hard problems.

Linux system info:

[xxngshelisheng@l01 ~]$ lsb_release -a
LSB Version:    :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 6.3 (Santiago)
Release:        6.3
Codename:       Santiago
[xxngshelisheng@l01 ~]$ cat /proc/version
Linux version 2.6.32-279.el6.x86_64 (mockbuild@x86-008.build.bos.redhat.com) (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) ) #1 SMP Wed Jun 13 18:24:36 EDT 2012

The default gcc version is too old and does not meet the minimum rstan requirement (gcc version >=4.9). Luckily, there is a newer gcc available in another directory on the cluster (/data/soft/compiler/gcc/v5.2), which I think is compatible with rstan. Then set the newer gcc as the default in .bashrc file as follows:

export PATH=/data/soft/compiler/gcc/v5.2/bin:/data/soft/compiler/gcc/v5.2/lib64:$PATH
export LD_LIBRARY_PATH=/data/soft/compiler/gcc/v5.2/lib/:$LD_LIBRARY_PATH

The problem for this newer gcc is that it’s named gcc52, rather than gcc. To address this problem, I included four additional lines at the end of the .bashrc file as follows.

alias gcc='gcc52'
alias g++='g++52'
alias c++='c++52'
alias cpp='cpp52'

Therefore, gcc52 will be recognized as gcc.

[xxngshelisheng@l01 ~]$ source ./.bashrc
[xxngshelisheng@l01 ~]$ which gcc
alias gcc='gcc52'
[xxngshelisheng@l01 ~]$ gcc --version
gcc52 (GCC) 5.2.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

After that, I opened the R-3.6.2 installed on the cluster (by the root administrator).

 [xxngshelisheng@l01 ~]$ /data/csoft/R-3.6.2/bin/R
R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Typed the following line to check the system setup:

> writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
CXX14FLAGS=-O3 -march=native -mtune=native -fPIC

Typed and ran the line that installed Rstan. NOTE: Before installing Rstan, I had successfully installed all of its dependencies (and dependencies thereof) offline. For some reason, I couldn’t install them online.

install.packages("rstanfiles/rstan_2.18.1.tar.gz", repos=NULL)
Installing package into ‘/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
* installing *source* package ‘rstan’ ...
** package ‘rstan’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++  -I"/data/csoft/R-3.6.2/lib64/R/include" -DNDEBUG -I"../inst/include" -I"`"/data/csoft/R-3.6.2/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include" -I"/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/RcppEigen/include" -I"/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/BH/include" -I"/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include" -I/data/soft/zlib-1.2.11/include  -I/data/soft/bzip2-1.0.6/include -I/data/soft/xz-5.2.4/include -I/data/soft/pcre-8.41/include -I/data/soft/curl-7.22.0/include    -O3 -march=native -mtune=native -fPIC -c chains.cpp -o chains.o
In file included from chains.cpp:19:
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp: In function ‘typename boost::math::tools::promote_args<T, float, float, float, float, float>::type stan::math::mean(const std::vector<T, std::allocator<_CharT> >&)’:
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24: error: an array reference cannot appear in a constant-expression
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24: error: ‘&’ cannot appear in a constant-expression
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24: error: ‘.’ cannot appear in a constant-expression
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24: error: a function call cannot appear in a constant-expression
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24: error: a function call cannot appear in a constant-expression
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24: error: template argument 3 is invalid
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24: error: template argument 4 is invalid
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24: error: template argument 6 is invalid
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24: error: template argument 1 is invalid
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:25: error: ‘m’ was not declared in this scope
In file included from /data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/sum.hpp:5,
                 from chains.cpp:20:
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/arr/fun/sum.hpp: In function ‘T stan::math::sum(const std::vector<T, std::allocator<_CharT> >&)’:
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/arr/fun/sum.hpp:20: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
In file included from /data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/random/detail/integer_log2.hpp:19,
                 from /data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/random/detail/large_arithmetic.hpp:19,
                 from /data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/random/detail/const_mod.hpp:23,
                 from /data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/random/linear_congruential.hpp:30,
                 from /data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/random/additive_combine.hpp:27,
                 from chains.cpp:29:
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/pending/integer_log2.hpp: At global scope:
/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/pending/integer_log2.hpp:7: note: #pragma message: This header is deprecated. Use <boost/integer/integer_log2.hpp> instead.
make: *** [chains.o] Error 1
ERROR: compilation failed for package ‘rstan’
* removing ‘/data/home/xxngshelisheng/R/x86_64-pc-linux-gnu-library/3.6/rstan’
Warning message:
In install.packages("rstanfiles/rstan_2.18.1.tar.gz", repos = NULL) :
  installation of package ‘rstanfiles/rstan_2.18.1.tar.gz’ had non-zero exit status

The above error message came up. I also tried many different rstan versions, and the same error message came up.

Any idea how I can address this problem? Thanks in advance!

Any hint on this issue?

looks like issues with BH (boost). Can you use a version of boost which was release around the time of the release of rstan 2.18? Maybe check which boost version cmdstan 2.18 included to get an idea on which version to install.

Thanks @wds15 for the suggestion. I have updated BH (boost) as you suggested. It seems the compatibility between BH versions and rstan versions was one of the problems.

But that was not all of the problems. R still could not load the intended gcc52 or g++52 with my previous command lines.

After a bit more googling, I ran the following lines in R:

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 -fPIC",
   file = M, sep = "\n", append = TRUE)

This gave me hope as it addressed the old problems, though new problems arose. To address the latter, I had to downgrade the rstan to v2.15.2 to make everything work fine, for some reason.

Thanks again.