ph-rast / bmgarch

Bayesian Multivariate GARCH
16 stars 10 forks source link

Installing bmgarch on Linux - fatal swap file error #18

Closed sreedta8 closed 2 years ago

sreedta8 commented 2 years ago

Hello @ph-rast

Wanted to share the issues I ran into when trying to install bmgarch on a Lubuntu (21.10) Linux laptop. I did not have these problems when installing on a Windows 10 laptop. I'm a beginner/intermediate user with Linux. Thank you for your lovely package! I'm hoping my notes below will help another introductory level user such as myself.

I went through a few iterations and these are the steps I found worked for me to initiate/prepare for the installation

Steps 1 & 2 are done at the bash prompt; Step 3 and 4 involves launching R and installing packages within the R space

  1. Install libv8-dev using sudo apt install libv8-dev
  2. Install libnode-dev using sudo apt install libnode-dev
  3. Launch R and at the prompt run ```install.packages("V8")
  4. Next run ```install.packages("bmgarch")

Not all users may run into the fatal error I run into after the compilation goes on for some time. The error is described below:

C++: fatal error: Killed signal terminated program cc1plus

If you encounter this error it means that the current swap file setup on your Linux machine is not large enough and hence running out of swap memory. Please follow the steps below in the exact sequence (You need admin/root level rights/access for all commands). I found the precise solution from here. All the steps shown below I ran from the main bash prompt in the terminal.

  1. Create the partition path sudo mkdir -p /var/cache/swap/

  2. Set the size of the partition bs=64M is the block size, count=64 is the number of blocks, so the swap space size is bs x count=4096MB=4GB sudo dd if=/dev/zero of=/var/cache/swap/swap0 bs=64M count=64

  3. Set permissions for this directory sudo chmod 0600 /var/cache/swap/swap0

  4. Create the SWAP file sudo mkswap /var/cache/swap/swap0

  5. Activate the SWAP file sudo swapon /var/cache/swap/swap0

  6. Check if SWAP information is correct sudo swapon -s

Once the swap file partition is complete, then go to the R terminal/prompt and rerun the install.packages("bmgarch"). This process will take some time. However, for me this came out well and my fata error went away and the library was installed.

Note - You may see other errors, different from mine since we are working with open-source tools and there are many rough edges.

ph-rast commented 2 years ago

Thank you @sreedta8 for letting me know! Indeed, it looks like during compilation you ran out of memory. Modern Linux distros will vary with how large the swap is but I think most will be at least 4GB (as in your description). Also, some will use swap files and others swap partitions: Ubuntu will use a swap file.

A workaround might be to use the c2d4u repository that gives you access to all CRAN packages via sudo apt install r-cran-bmgarch. I don't know if this works for Lubuntu - but you could give it a try (see https://cran.r-project.org/bin/linux/ubuntu/#get-5000-cran-packages).

sreedta8 commented 2 years ago

Thanks for getting back @ph-rast and thanks again for your package. I was using your package the past couple of days and I absolutely love it. I will definitely test the c2d4u repository and let you know how it goes.

ph-rast commented 2 years ago

My intuition is that if you go with c2d4u you want to avoid installing packages from within R -- mixing package management systems in Linux never bodes well...