Compiling rstan with the Intel compilers

I manage a HPC cluster and when we installed R we chose to use the Intel compiler and Math Kernel Library. For the most part, this has worked well, but I occasionally run into issues building some packages which is probably not surprising.

I’m attempting to install rstan_2.18.2.tar.gz against R-3.5.3 which I built using Intel 17.0.6. rstan first complained about CXX14 not being set, so I figured out how to set that to the Intel C++ compiler:

[root@login02 R_Packages]# cat ~/.R/Makevars
CXXFLAGS += -wd308
CXXFLAGS += -wd809

temporary for Rstan

CXX14=icpc

I’ve tried various iterations of other flags, and I’ve also tried reinstalling Rcpp with the same flags (something I came across while searching these forums), but the error remains pretty consistent. It starts to build the package:

[root@login02 R_Packages]# R CMD INSTALL rstan_2.18.2.tar.gz

icpc -I"/export/R-3.5.3-intel/lib64/R/include" -DNDEBUG -I"…/inst/include" -I""/export/R-3.5.3-intel/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/export/R-3.5.3-intel/lib64/R/library/Rcpp/include" -I"/export/R-3.5.3-intel/lib64/R/library/RcppEigen/include" -I"/export/R-3.5.3-intel/lib64/R/library/BH/include" -I"/export/R-3.5.3-intel/lib64/R/library/StanHeaders/include" -I/usr/local/include -c chains.cpp -o chains.o

I see several warnings/error messages of the form:

/export/R-3.5.3-intel/lib64/R/library/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures_def.hpp(101): note: this candidate was rejected because mismatch in count of arguments
void function_signatures::add(const std::string& name,
^
/export/R-3.5.3-intel/lib64/R/library/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures_def.hpp(93): note: this candidate was rejected because mismatch in count of arguments
void function_signatures::add(const std::string& name,
^
/export/R-3.5.3-intel/lib64/R/library/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures_def.hpp(87): note: this candidate was rejected because mismatch in count of arguments
void function_signatures::add(const std::string& name,

and it finally errors out with:

In file included from /export/R-3.5.3-intel/lib64/R/library/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures_def.hpp(486),
from /export/R-3.5.3-intel/lib64/R/library/StanHeaders/include/src/stan/lang/ast_def.cpp(119),
from lang__ast_def.cpp(18):
/export/R-3.5.3-intel/lib64/R/library/StanHeaders/include/src/stan/lang/function_signatures.h(406): error #303: explicit type is missing (“int” assumed)
for (const auto& t : all_vector_types) {
^

compilation aborted for lang__ast_def.cpp (code 4)

Any suggestions on things to try would be greatly appreciated.

Cheers,
Malcolm

It looks like the C++14 stuff is not getting passed. Try with CXX14 = icpc -std=c++1y or something in the Makevars file.

Ben,

Thanks for the response, I think the argument’s getting passed through:

[root@login02 R_Packages]# cat ~/.R/Makevars
CXXFLAGS += -wd308
CXXFLAGS += -wd809

temporary for Rstan

CXX14=icpc
CXX14FLAGS=-std=c++14

[root@login02 R_Packages]# R CMD INSTALL rstan_2.18.2.tar.gz

icpc -I"/export/R-3.5.3-intel/lib64/R/include" -DNDEBUG -I"…/inst/include" -I""/export/R-3.5.3-intel/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/export/R-3.5.3-intel/lib64/R/library/Rcpp/include" -I"/export/R-3.5.3-intel/lib64/R/library/RcppEigen/include" -I"/export/R-3.5.3-intel/lib64/R/library/BH/include" -I"/export/R-3.5.3-intel/lib64/R/library/StanHeaders/include" -I/usr/local/include -std=c++14 -c chains.cpp -o chains.o

And the binding error is still

/lang/function_signatures.h(406): error #303: explicit type is missing (“int” assumed)
for (const auto& t : all_vector_types)

even with C++14 passed through?

Ben,

Sorry, I’ve tried multiple things so am likely getting things confused. When the -std=c++14 is passed through the error is:

icpc -I"/export/R-3.5.3-intel/lib64/R/include" -DNDEBUG -I"…/inst/include" -I"
"/export/R-3.5.3-intel/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('incl ude', 'src', package = 'StanHeaders'))"" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENI
X_NO_VARIADIC_EXPRESSION -I"/export/R-3.5.3-intel/lib64/R/library/Rcpp/include"
-I"/export/R-3.5.3-intel/lib64/R/library/RcppEigen/include" -I"/export/R-3.5.3-i
ntel/lib64/R/library/BH/include" -I"/export/R-3.5.3-intel/lib64/R/library/StanHe
aders/include" -I/usr/local/include -std=c++14 -c chains.cpp -o chains.o
In file included from /export/R-3.5.3-intel/lib64/R/library/BH/include/boost/uti
lity.hpp(22),
from /export/R-3.5.3-intel/lib64/R/library/BH/include/boost/range/size.hpp(25),
from /export/R-3.5.3-intel/lib64/R/library/BH/include/boost/range/functions.hpp(20),
from /export/R-3.5.3-intel/lib64/R/library/BH/include/boost/range/iterator_range_core.hpp(38),
from /export/R-3.5.3-intel/lib64/R/library/BH/include/boost/lexical_cast.hpp(30),
from chains.cpp(28):
/export/R-3.5.3-intel/lib64/R/library/BH/include/boost/core/noncopyable.hpp(42): error: defaulted default constructor cannot be constexpr because the corresponding implicitly declared default constructor would not be constexpr
BOOST_CONSTEXPR noncopyable() = default;
^

/export/R-3.5.3-intel/lib64/R/library/BH/include/boost/pending/integer_log2.hpp(7): note: This header is deprecated. Use <boost/integer/integer_log2.hpp> instead.
compilation aborted for chains.cpp (code 2)
make: *** [chains.o] Error 2
ERROR: compilation failed for package ‘rstan’

  • removing ‘/export/R-3.5.3-intel/lib64/R/library/rstan’

Cheers,
Malcolm

Can you compile this example from the Boost documentation under icpc with C++14?

#include <boost/noncopyable.hpp>
#include <string>
#include <utility>
#include <iostream>

struct animal : boost::noncopyable
{
  std::string name;
  int legs;

  animal(std::string n, int l) : name{std::move(n)}, legs{l} {}
};

void print(const animal &a)
{
  std::cout << a.name << '\n';
  std::cout << a.legs << '\n';
}

int main()
{
  animal a{"cat", 4};
  print(a);
}

You may need something like -I/export/R-3.5.3-intel/lib64/R/library/BH/include/.

Nope, same error:

[root@login02 R_Packages]# icpc -std=c++14 -I/export/R-3.5.3-intel/lib64/R/library/BH/include/ /tmp/boost.c
In file included from /export/R-3.5.3-intel/lib64/R/library/BH/include/boost/noncopyable.hpp(15),
from /tmp/boost.c(1):
/export/R-3.5.3-intel/lib64/R/library/BH/include/boost/core/noncopyable.hpp(42): error: defaulted default constructor cannot be constexpr because the corresponding implicitly declared default constructor would not be constexpr
BOOST_CONSTEXPR noncopyable() = default;
^

compilation aborted for /tmp/boost.c (code 2)

OK. Unfortunately, this seems to be an issue with icpc and / or Boost rather than a Stan issue per se. You might try editing line 42 of noncopyable.hpp to take away the BOOST_CONSTEXPR.

Hacking the source didn’t work, and neither did the half-dozen or so other wacky ideas I tried.

I finally started from a clean slate with R-3.6.0. That didn’t get me much further so I finally backed of the Intel compilers and used GNU compilers to build rstan.

I’m not claiming all of these are entirely necessary, but here’s the Makevars I finally used on the off-chance it helps anyone in the future:

[root@login02 R_Packages]# cat ~/.R/Makevars
CXXFLAGS += -wd308
CXXFLAGS += -wd809

for digest

CXX11=icpc
CXX11FLAGS=-fPIC -std=c++11

temporary for Rstan

#CXX14=icpc
CXX14=g++
CXX14FLAGS=-std=c++14
CXX14FLAGS += -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION

Thanks for your help.

Cheers,
Malcolm

1 Like