Search code examples
rstanrstan

Floating Point Exception after installing rstan/brms


I am currently trying to get rstan and brms running on my Fedora34 machine, and failing to do so since a couple of hours. Crucially, testing the example models or others always gives me a "Floating Point Exception". When I run the code in RStudio, it simply crashes and aborts everything, while running from the terminal does basically the same but gives me the hint of the floating point exception, as can be seen below. The error message is sadly limited to the info of "Floating Point exception".

The make command is:

  make -f '/usr/lib64/R/etc/Makeconf' -f '/usr/share/R/make/shlib.mk' \
  -f '/root/.R/Makevars' CXX='$(CXX14) $(CXX14STD)' \
   CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' \
SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' \
SHLIB='filef8256c0e3305.so' OBJECTS='filef8256c0e3305.o'

make would use:

g++ -std=gnu++14 -I"/usr/include/R" -DNDEBUG   -I"/usr/local/lib/R/library \
/Rcpp/include/"  -I"/usr/local/lib/R/library/RcppEigen/include/" \
 -I"/usr/local/lib/R/library/RcppEigen/include/unsupported"  \
-I"/usr/local/lib/R/library/BH/include" \
-I"/usr/local/lib/R/library/StanHeaders/include/src/" \
 -I"/usr/local/lib/R/library/StanHeaders/include/"  \
-I"/usr/local/lib/R/library/RcppParallel/include/"  -I"/usr/local/lib/R/library/rstan/include" \
-DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  \
-DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  \
-include '/usr/local/lib/R/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' \
 -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fpic  \
-O3 -march=native -mtune=native -fPIC \
-c filef8256c0e3305.cpp -o filef8256c0e3305.o
if test  "zfilef8256c0e3305.o" != "z"; then \
  echo g++ -std=gnu++14 -shared -L"/usr/lib64/R/lib" -Wl,-z,relro \
-Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  \
-o filef8256c0e3305.so filef8256c0e3305.o  '/usr/local/lib/R/library/rstan/lib//libStanServices.a' \
-L'/usr/local/lib/R/library/StanHeaders/lib/' -lStanHeaders \
-L'/usr/local/lib/R/library/RcppParallel/lib/' -ltbb  \
-L"/usr/lib64/R/lib" -lR; \
  g++ -std=gnu++14 -shared -L"/usr/lib64/R/lib" -Wl,-z,relro \
-Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  -o filef8256c0e3305.so filef8256c0e3305.o \
 '/usr/local/lib/R/library/rstan/lib//libStanServices.a' \
 -L'/usr/local/lib/R/library/StanHeaders/lib/' -lStanHeaders \
-L'/usr/local/lib/R/library/RcppParallel/lib/' -ltbb  \
-L"/usr/lib64/R/lib" -lR; \
fi
Floating point exception

This seems weird to me, as there should be no such errors because I am not trying to do anything fancy, just running the sample models. I tried reinstalling R completely, reinstalling rstan from source, but none of it worked. Also, cmdstanr gives me the info that all my c++ chains and paths are set correctly. The MCMC of cmdstanr also run correctly, so the problem seems to be specifically with brms and rstan.

Some package information: OS: x86_64 (Fedora 34), linux-gnu; rstan: 2.21.2; Rcpp: 1.0.6; inline: 0.3.17, R 4.0.4


Solution

  • Don't know what the actual problem is, but given that cmdstanr works, you can work around it your problem via

    brms(..., backend="cmdstanr")
    

    See here for a little bit of discussion of the differences between rstan and cmdstanr: among them

    Running Stan via external processes results in fewer unexpected crashes, especially in RStudio.