Segfault in the Bernoulli example

Hello

I am trying to complete the installation of cmdstanpy on an EC2 instance, running a RedHat like OS.

I have first tried to install from python, with a fresh virtual environment, but this result in the following error:

>>> import cmdstanpy
>>> cmdstanpy.install_cmdstan()
Installing CmdStan version: 2.27.0
Install directory: /home/e0490134/.cmdstan
Downloading CmdStan version 2.27.0
Download successful, file: /tmp/tmpnf3lo679
Unpacked download as cmdstan-2.27.0
Building version cmdstan-2.27.0
Test model compilation
Failed to compile example model bernoulli.stan
g++: internal compiler error: Segmentation fault (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [examples/bernoulli/bernoulli] Error 4
deleting tmpfiles dir: /tmp/tmpc3sf_ftz
done

WARNING:cmdstanpy:CmdStan installation failed.
False
>>> 

I have then tried to install cmdstan by following the instructions in the documentation.

I can properly run make build, but when reaching the testing step of the installation, I get a similar error.

$ make examples/bernoulli/bernoulli 

[...]
--- Compiling pre-compiled header. This might take a few seconds. ---
g++ -std=c++1y -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include   -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.75.0 -I stan/lib/stan_math/lib/sundials_5.7.0/include    -DBOOST_DISABLE_ASSERTS         -c stan/src/stan/model/model_header.hpp -o stan/src/stan/model/model_header.hpp.gch

--- Translating Stan model to C++ code ---
bin/stanc  --o=examples/bernoulli/bernoulli.hpp examples/bernoulli/bernoulli.stan

--- Compiling, linking C++ code ---
g++ -std=c++1y -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include   -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.75.0 -I stan/lib/stan_math/lib/sundials_5.7.0/include    -DBOOST_DISABLE_ASSERTS         -c -Wno-ignored-attributes   -x c++ -o examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp

g++: internal compiler error: Segmentation fault (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [examples/bernoulli/bernoulli] Error 4

It seems that the versions of g++ and make are meeting the requirements:

$ g++ --version
g++ (GCC) 7.3.1 20180712 (Red Hat 7.3.1-12)
make --version
GNU Make 3.82
Built for x86_64-koji-linux-gnu

Does any one have input on things I could try to make this work?

Many thanks!

For anyone stumbling upon this thread, it looks like this issue was caused by a lack of memory on the machine.

After increasing the available RAM, the problem went away. I find it a bit odd that a lack of memory would trigger a segfault, though.

I would say additionally, be sure to clear the ~/.cmdstan directory whenever attempting a new install.

2 Likes

Thanks for following up @lpo!

C++ compilers do often throw segmentation errors when they run out of RAM, which mostly only happens on cloud instances. Make sure to have an instance with enough RAM or at least a big enough swap if possible.