機械学習メモ

化学を機械学習で何か

WSL2上でUbuntuにamberをコンパイルする

WSL上のubuntuにamber23をインストールした時のメモ

ある段階でcudatoolkitのバージョンが最新すぎると、コンパイルが通らない問題がある。
それを回避するために、gcc-10, g++-10, gfortran-10を導入し、cutatoolkit-11.1を導入した。
homedir直下にlocalフォルダを作成して、そこにインストールすることを想定しているので
適宜変えてください。

導入方法
sudo apt -y update
sudo apt -y install tcsh make \
gcc gfortran g++ \
flex bison patch bc wget \
xorg-dev libz-dev libbz2-dev

sudo apt-get -y install gcc-10 g++-10 gfortran-10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11

sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

Selection Path Priority Status

                                                                                                                      • -

0 /usr/bin/gcc-11 11 auto mode
1 /usr/bin/gcc-10 10 manual mode
2 /usr/bin/gcc-11 11 manual mode
1を選んでおく

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/g++-10 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/g++-11 11
sudo update-alternatives --config g++

これも同じく

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gfortran-10 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gfortran-11 11
sudo update-alternatives --config gfortran

これも同じく

次に、nvidiaのサイトでcudatoolkit-11.1をダウンロードする
developer.nvidia.com

これは、サイトの指示に従って導入する。


.bashrcに下記を追加する(/usr/local/cuda-11.1を指定してもOK)
export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"

設定した環境変数を読み込む
sourrce ~/.bashrc

minicondaを導入し、環境を構築する
conda create -n amber23 python=3.8
codna activate amber23
conda install -y mpi4py numpy pandas

amber23.tar.bzとambertools22.tar.bzを展開し、build内のrun_cmakeを書き換える
#!/bin/bash

# This file gives some sample cmake invocations. You may wish to
# edit some options that are chosen here.

# For information on how to get cmake, visit this page:
# https://ambermd.org/pmwiki/pmwiki.php/Main/CMake-Quick-Start

# For information on common options for cmake, visit this page:
# http://ambermd.org/pmwiki/pmwiki.php/Main/CMake-Common-Options

# (Note that you can change the value of CMAKE_INSTALL_PREFIX from what
# is suggested below, but it cannot coincide with the amber22_src
# folder.)

#AMBER_PREFIX=$(dirname $(dirname `pwd`))

AMBER_PREFIX="/home/hoge/local/"
if [ `uname -s|awk '{print $1}'` = "Darwin" ]; then

# For macOS:

if [ -x /Applications/CMake.app/Contents/bin/cmake ]; then
cmake=/Applications/CMake.app/Contents/bin/cmake
else
cmake=cmake
fi

$cmake $AMBER_PREFIX/amber22_src \
-DCMAKE_INSTALL_PREFIX=$AMBER_PREFIX/amber22 \
-DCOMPILER=CLANG -DBLA_VENDOR=Apple \
-DMPI=FALSE -DCUDA=FALSE -DINSTALL_TESTS=TRUE \
-DDOWNLOAD_MINICONDA=TRUE \
2>&1 | tee cmake.log

else

# Assume this is Linux:

cmake /home/hoge/src/amber22_src/ \
-DCMAKE_INSTALL_PREFIX=$AMBER_PREFIX/amber23 \
-DCOMPILER=GNU \
-DMPI=FALSE -DCUDA=FALSE -DINSTALL_TESTS=TRUE \
-DDOWNLOAD_MINICONDA=FALSE \
-DPYTHON_EXECUTABLE=/home/hoge/miniconda3/envs/amber23/bin/python \
2>&1 | tee cmake.log

fi

if [ ! -s cmake.log ]; then
echo ""
echo "Error: No cmake.log file created: you may need to edit run_cmake"
exit 1
fi

echo ""
echo "If errors are reported, search for 'CMake Error' in the cmake.log file."
echo ""
echo "If the cmake build report looks OK, you should now do the following:"
echo ""
echo " make install"
echo " source $AMBER_PREFIX/amber22/amber.sh"
echo ""
echo "Consider adding the last line to your login startup script, e.g. ~/.bashrc"
echo ""

コンパイルする
./run_cmake
make
make install
source ~/local/amber23/amber.sh

その後に、Ambertools/src内にmpichi-4.1.2.tar.gzを展開し、
cd ../AmberTools/src/
configure_mpich gnu

でmpi用のコンパイラを作成

cd ../../build
make clean
./run_cmake # DMPI=TRUEにする
make
make install
./run_cmake #さらに DCUDA=TRUEにする
make
make install