Method-2: Installing GROMACS on Ubuntu 20.04 with CUDA GPU Support

/
9 mins read
Installing GROMACS on Ubuntu 20.04 with CUDA GPU Support

We have provided a tutorial on installing GROMACS [1] on Ubuntu with CUDA GPU support. The methods may vary depending upon the requirements of your system. Therefore, in this article, we provide another method to configure GROMACS with CUDA.

If you want to install GROMACS without GPU acceleration, read our previous article. Here, you will find some additional steps for GPU acceleration.

Getting Started

It is good practice to update your repository information and software packages before installing new programs. Open a terminal by pressing Ctrl+Alt+T and type:

$ sudo apt-get update

$ sudo apt-get upgrade

Removing existing drivers

It might be possible that some NVIDIA drivers have already been installed on your system. Therefore, it is better to remove them first otherwise it will give errors during the installation of the toolkit and drivers. You can check for the existing drivers using the following command:

$ nvidia-smi

It will list all NVIDIA drivers existing in your system.

Now, let’s remove them using the following commands:

$ sudo apt-get purge nvidia*

$ sudo apt-get autoremove

$ sudo apt-get autoclean

Now, rerun the $ nvidia-smi command to check whether you have completely removed the drivers. If not, then run the following commands as well. Remember to note the CUDA version (here, Cuda-9.2).

$ sudo apt-get autoremove --purge nvidia* cuda-drivers libcuda* cuda-runtime* cuda-9-2 cuda-demo*

$ sudo apt-get remove --purge nvidia* cuda-drivers libcuda1-396 cuda-runtime-9-2 cuda-9.2 cuda-demo-suite-9-2 cuda

$ sudo apt-get autoremove

$ sudo apt-get autoclean

Now, check again using $ nvidia-smi. All NVIDIA drivers must have been cleared.

Downloading CUDA toolkit

Now select the latest version of the CUDA toolkit according to your system from here. In our last tutorial, we installed the toolkit using a local run file that did not work on some systems. Therefore, in this tutorial, we will install using a local deb file.

At first, we will download the CUDA repository. Now, change to the directory where you want to download the files.

$ cd Downloads/

$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin

Now move the downloaded file to the repository using the following command.

$ sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600

Now, download the deb file of the toolkit using the following command.

$ wget https://developer.download.nvidia.com/compute/cuda/11.2.2/local_installers/cuda-repo-ubuntu2004-11-2-local_11.2.2-460.32.03-1_amd64.deb

Installing CUDA toolkit

Extract the downloaded file and then install using the following commands.

$ sudo dpkg -i cuda-repo-ubuntu2004-11-2-local_11.2.2-460.32.03-1_amd64.deb

$ sudo apt-key add /var/cuda-repo-ubuntu2004-11-2-local/7fa2af80.pub

$ sudo apt-get update

$ sudo apt-get -y install cuda

The CUDA toolkit must be installed successfully on your system. If it still doesn’t, then use the following command:

$ sudo apt-get -y install nvidia-cuda-toolkit

Installing NVIDIA drivers

Remember CUDA 11.2 is compatible with >= 450.80.02 NVIDIA driver version. We will install NVIDIA 460 and then update the version.

$ sudo apt-get install nvidia-driver-460

$ sudo ubuntu-drivers autoinstall

$ sudo apt-get update

Now, check for the NVIDIA drivers using the following command, it should display the version.

$ nvcc --version

and run $ nvidia-smi. It should display NVIDIA drivers and CUDA version along with other information.

Installing prerequisites for GROMACS

  • Install openmpi from the repository using the following command. If you have already installed GROMACS, then skip to the next step.

$ sudo apt-get install libopenmpi-dev

$ sudo apt-get install openmpi-bin

$ sudo apt-get install -y python3-mpi4py

  • Get cmake before installing GROMACS. In the terminal, type:

$ sudo apt-get install -y cmake

After the installation finishes up, you can check the version of cmake by the following command:

$ cmake --version

If it displays the version, then it means everything is fine. Move on to the next step.

  • The next requirement is build-essential. To install this, type the following command in the terminal:

$ sudo apt-get install -y build-essential

  • Now, you need the FFTW3 library. Install it using the following command:

$ sudo apt-get install -y libfftw3-dev

  • Now, install Doxygen

$ sudo apt-get install -y doxygen

Downloading Regressiontests

Download the latest release of regressiontests from here or use the following command. Change to the directory where you want to download the GROMACS software and paste the following commands.

$ cd Downloads/

$ wget https://ftp.gromacs.org/regressiontests/regressiontests-2020.6.tar.gz

Now, extract the downloaded file,

$ tar xvzf regressiontests-2020.6.tar.gz

Downloading GROMACS

Download the latest release of GROMACS from here or use the following command.

$ wget https://ftp.gromacs.org/gromacs/gromacs-2020.6.tar.gz

Installing GROMACS

First, get your pwd path using the following command.

$ pwd

Note down the displayed path, we will need it in later steps.

  • Extract the downloaded archive file. Move into the directory where you have downloaded the package. (We are still in the Downloads directory).

$ tar xvzf gromacs-2020.6.tar.gz

  • Now move inside the gromacs folder.

$ cd gromacs-2020.6/

  • Create a directory called “build-gpu” where we will keep our compiled binaries.

$ mkdir build-gpu

  • Move inside the build-gpu directory.

$ cd build-gpu/

  • Now, make gromacs using cmake.

$ sudo cmake .. -DGMX_BUILD_OWN_FFTW=OFF -DREGRESSIONTEST_DOWNLOAD=OFF -DMAKE_C_COMPILER=gcc -DGMX_GPU=CUDA -DGMX_MPI=OFF -DREGRESSIONTEST_PATH=/your/pwd/path/here/Downloads/regressiontests-2020.6

NOTE

You may get an error during the compilation stating that the NVCC/C++ version is not compatible or some error similar to that. For that, you need to downgrade the GCC version. For now, it would be the latest version (9.2) installed on your system. Now you have to install version 8, follow the steps given below.

$ sudo apt-get -y install gcc-8 g++-8

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8

$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 8

$ sudo update-alternatives --config gcc

$ sudo update-alternatives --config g++

Now check,

$ gcc --version

$ g++ --version

Now, you can continue with the cmake command:

$ sudo cmake .. -DGMX_BUILD_OWN_FFTW=OFF -DREGRESSIONTEST_DOWNLOAD=OFF -DMAKE_C_COMPILER=gcc -DGMX_GPU=CUDA -DGMX_MPI=OFF -DREGRESSIONTEST_PATH=/your/pwd/path/here/Downloads/regressiontests-2020.6

If everything goes well, the message in your terminal will say “Generating Done. Build files written… “. If not, make sure you have replaced the pwd path in command with the path of your home directory.

  • Now, let’s check and make.

$ sudo make check

$ sudo make install

  • Move inside the unpacked regressiontests directory and execute the following command:

$ cd regressiontests-2020.6/

$ source /usr/local/gromacs/bin/GMXRC

After that, you can check for the successful installation of GROMACS with the following command:

$ gmx pdb2gmx --version

It will display the GPU version as well.

Enjoy the speedy simulation!


References

  1. Abraham, M. J., Murtola, T., Schulz, R., Páll, S., Smith, J. C., Hess, B., & Lindahl, E. (2015). GROMACS: High performance molecular simulations through multi-level parallelism from laptops to supercomputers. SoftwareX1, 19-25.

Further Reading

Method-1: Installing GROMACS on Ubuntu with CUDA GPU Support

Installing Gromacs on Ubuntu for MD Simulation

Tutorial: Molecular dynamics (MD) simulation using Gromacs

Muniba is a Bioinformatician based in the South China University of Technology. She has cutting edge knowledge of bioinformatics tools, algorithms, and drug designing. When she is not reading she is found enjoying with the family. Know more about Muniba
Tariq is founder of Bioinformatics Review and a professional Software Developer at IQL Technologies. His areas of expertise include algorithm design, phylogenetics, MicroArray, Plant Systematics, and genome data analysis. If you have questions, reach out to him via his homepage.

Leave a Reply

The Business in Publishing!?
Previous Story

The Business in Scientific Publishing!?

alvis
Next Story

Alvis- A New Tool for Alignment & Visualization of Contigs & Reads and Chimera Detection

Latest from Software

0 $0.00