LoginSignup
22
16

Gromacs 2023をインストール

Last updated at Posted at 2017-12-17

Gromacs 2023をインストールする方法。

環境

macOSの場合:HomebrewでGromacsのインストール(おすすめ)

2023年8月現在、最新版の2023がHomebrew上で配信されているので、macOSの方はソースからのインストール作業をする必要がありません(ちなみに2019.3版は私が作成しました!)。
https://github.com/Homebrew/homebrew-core/blob/master/Formula/gromacs.rb

brew install gromacs

これで一発で/usr/local/Cellar/gromacs/以下(M1 Macの方は/opt/homebrew/Cellar/gromacs)にインストールされるはずです。一度ターミナルを再起動して、gmx --versionでバージョン情報が表示されるかどうか確かめましょう。

Linux OSの場合:NVIDIAのGPUを利用するインストール

Ubuntuの場合は apt で、CentOSやRedHatの場合はyumまたはdnf でfftw、cmake(またはcmake3)をインストールしておきます。以下ではCUDA 11.8以降とGNU compiler 11.3.0(/usr/bin/gcc)の使用を想定しています。

Ubuntu 22.04でのインストール準備

aptを使ってCMakeとfftw3をインストールしておきます。

sudo apt -y install cmake libfftw3-dev

Rhel系Linux (Redhat, Fedora, CentOS, Rocky Linux, Almalinuxなど)でのインストール準備

dnfを使ってCMakeとfftw3をインストールしておきます。

dnf -y install cmake3 fftw-devel

CUDAドライバのインストール (Linux OS)

CUDAドライバもインストールしておきます。こちらに一例を載せておきますが、時間が経つに連れやり方が変化するので、NVIDIA CUDA公式ウェブサイトで正式なインストール方法を調べておきそれに従う方が良いです。

あとCUDAインストールは場合によってはうまくできなかったり最悪カーネルパニックになって起動しなくなることもあるのでその辺は祈るしかない……

Ubuntu 22.04の場合

sudo apt-get install linux-headers-$(uname -r)
distribution=$(. /etc/os-release;echo $ID$VERSION_ID | sed -e 's/\.//g')
wget https://developer.download.nvidia.com/compute/cuda/repos/$distribution/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda cuda-drivers
# このあと一度再起動したほうが良さそう

Rhel 8系の場合

dnf install -y kernel-devel-$(uname -r) kernel-headers-$(uname -r) dkms
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo
dnf --enablerepo=epel -y install cuda-11-8 cuda-12-1
dnf module -y install nvidia-driver:latest-dkms

# 起動を確認
nvidia-smi
nvidia-modprobe && nvidia-modprobe -u

# このあと一度再起動したほうが良さそう

Gromacsのcmake設定

CUDAとGPUを使いたい場合はcmake時に必ずフラグ-DGMX_GPUを入れる必要があります。NVIDIA GPUのときは-DGMX_GPU=CUDAを指定します。

以下ではインストール先を${HOME}/apps/gromacs/2023.2とすることにしています。ここは各自好きな場所を指定してください。

# ソースコードのダウンロードと解凍
curl https://ftp.gromacs.org/gromacs/gromacs-2023.2.tar.gz -o gromacs-2023.2.tar.gz
tar zxvf gromacs-2023.2.tar.gz
cd gromacs-2023.2
mkdir build
cd build
# インストールの前準備のcmakeコマンド
# インストール先を-DCMAKE_INSTALL_PREFIXで指定することに注意。
cmake .. -DCMAKE_INSTALL_PREFIX=${HOME}/apps/gromacs/2023.2 \
-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DGMX_MPI=OFF \
-DGMX_DOUBLE=OFF -DGMX_OPENMP=ON -DGMX_GPU=CUDA

cmake処理が終わった後、エラーなくconfiguring done, Generating doneと表示されることを確認します。

-- Check if the system is big endian
-- Searching 16 bit integer
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Configuring done
-- Generating done
-- Build files have been written to: /root/temp/build/gromacs-2023.2/build

終わったら、makeコマンドでインストールを実行します。だいたい2〜5分くらいで終わります。

make -j8 install

また、MPI版のインストールも必要ならばしておきます。これはノード間MPIであり、複数台の計算機を繋いで処理を高速化するためのものです。1台のみの使用であれば必要ありません。

cd gromacs-2023.2
mkdir build
cd build
# ここまで非MPI版と同じ。以下で-DGMX_MPI=ONを追加するのがポイント
rm -rf *

cmake .. -DCMAKE_INSTALL_PREFIX=/home/apps/gromacs/2023.2 \
-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DGMX_MPI=ON \
-DGMX_DOUBLE=OFF -DGMX_OPENMP=ON -DGMX_GPU=CUDA

make -j8 install
22
16
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
16