heyheytower

日々のメモです。誰かのお役に立てれば幸いです。

並列プログラミングのための、 linux クラスタ環境の構築。その4(Intel MKL 利用)

【目的】

インテル® マス・カーネル・ライブラリー(Intel MKL)数値解析ソフトウェアライブラリを並列環境で使う設定を行った。

(2013/12/18追記)本エントリは古い LTS に対しての記事のうえ、記載が不十分なところもあるためubuntu12.04.3 で intel compiler + openMPI + NFSv4 + sun grid engine (beowulf 方式) - heyheytowerを参照ください。



Fig. SunGridEngine の GUI 画面
   (4台起動し、mpirun が実行された後であることが分かります)

【経緯】

並列環境で、ベクトルや行列に関する線型代数操作を実行するライブラリAPIとして「BLAS」や「ATLAS」などがある。
また、上記を使った上位パッケージとして、「LINPACK」「LAPACK」などのソフトウェアライブラリが存在している。
PGI and BLAS, LAPACK, ScaLapack を参考。

Amazon Web Service(AWS)ではこれら HPC 環境を安易に利用でき、MIT STAR: Cluster - Homeでは「cluster-computing toolkit」を提供している。
これにより一般ユーザでは 8 CPU * 20 ノードをコマンドライン上から簡単に利用することができる

「cluster-computing toolkit」で利用できるノード情報は以下。

The AMIs include the following software:

OpenMPI - Library used for writing/running parallel applications
Hadoop - Framework for writing massively distributed map/reduce tasks
Open Grid Scheduler - Queueing system for scheduling jobs on the cluster and handling load balancing.
NFS - Network File System for sharing folders across the cluster.
ATLAS - Automatically Tuned Linear Algebra Subroutines (custom built for larger EC2 instance types)
Scipy - Scientific algorithms library for Python (compiled against custom Atlas)
Numpy - Fast array and numerical library for Python (compiled against custom Atlas)
IPython - An advanced interactive shell for Python.
and more...

こちらの利用は 続:Amazon Clusterインスタンスで計算: 週記 に詳しく、自分の環境 Ubuntu10.04 でも利用できることを確認している。

最終的には AWS を本番環境として、自分の環境をテスト環境として用いれるよう、同様の環境を構築する。


【導入方法】

LAPACK の実装確認とインストール
  1. LAPACK - Wikipedia にて LAPACK の実装を確認し、CPU 的に適合し、処理能力的にも実績のある「Intel MKL」を利用した。ダウンロードはhttp://software.intel.com/en-us/non-commercial-software-developmentから行った。
  1. 下記を参照し、インストールを行った。

 http://software.intel.com/en-us/articles/performance-tools-for-software-developers-building-open-mpi-with-the-intel-compilers
 http://bookers.seesaa.net/article/158575834.html

 ※ ubuntu10.04 では intel compiler c,c++ version11.1 がサポート対象で1番新しいバージョンだったので、これを利用した。

各ノードで以下を実行した。

cd /tmp
sudo apt-get update
sudo apt-get -y install gcc
sudo apt-get -y install gcc-multilib
sudo apt-get -y install g++
sudo apt-get -y install ia32-libs
sudo apt-get -y install openjdk-6-jre-headless
wget http://ftp.jp.debian.org/debian/pool/main/g/gcc-3.3/libstdc++5_3.3.6-20_amd64.deb
dpkg -i libstdc++5_3.3.6-20_amd64.deb
wget http://ftp.jp.debian.org/debian/pool/main/g/gcc-3.3/libstdc++5_3.3.6-20_i386.deb
dpkg --extract libstdc++5_3.3.6-20_i386.deb ./
cd usr/lib
#mkdir /usr/lib32
cp libstdc++.so.5.0.7 /usr/lib32/
cd /usr/lib32
ln -s libstdc++.so.5.0.7 libstdc++.so.5
cd /tmp
wget http://registrationcenter-download.intel.com/akdlm/irc_nas/2251/l_cproc_p_11.1.080_intel64.tgz
tar zxvf l_cproc_p_11.1.080_intel64.tgz
cd l_cproc_p_11.1.080_intel64
./install.sh

3. 各種ドキュメントを XLsoft エクセルソフト : インテル MKL からダウンロードした。

※ Math Kernel Libraray については Intel® MKL も参照した。


OpenMPI で Intel C/C++ Compiler を利用できるようにする

1. 管理者権限と、通常ユーザ両方で、下記を実行した。

echo "" >> ~/.bashrc
echo "# set MKL environment" >> ~/.bashrc
echo "/opt/intel/Compiler/11.1/080/mkl/tools/environment/mklvars64.sh" >> ~/.bashrc
echo "" >> ~/.bashrc
echo "#intel compiler" >> ~/.bashrc
echo "source /opt/intel/Compiler/11.1/080/bin/iccvars.sh intel64" >> ~/.bashrc
echo "source /opt/intel/Compiler/11.1/080/bin/ifortvars.sh intel64" >> ~/.bashrc
source ~/.bashrc

#intel compiler 動作確認
icc -v
icpc -v
cd /opt/intel/mkl/examples/cblas
make sointel64 function=cblas_dgemm
./_results/intel_lp64_parallel_intel64_so/cblas_dgemmx.out data/cblas_dgemmx.d
cd /opt/intel/mkl/examples/cblas
make sointel64 function=cblas_dgemm
./_results/intel_lp64_parallel_intel64_so/cblas_dgemmx.out data/cblas_dgemmx.d


C B L A S _ D G E M M EXAMPLE PROGRAM

INPUT DATA
M=2 N=5 K=4
ALPHA= 0.5 BETA= -1.2
TRANSA = CblasTrans TRANSB = CblasTrans
ORDER = CblasRowMajor
ARRAY A LDA=2
1.500 2.220
6.300 9.000
1.000 -4.000
0.200 7.500
ARRAY B LDB=4
1.000 2.000 3.000 4.000
1.000 2.000 3.000 4.000
1.000 2.000 3.000 4.000
1.000 2.000 3.000 4.000
1.000 2.000 3.000 4.000
ARRAY C LDC=5
0.000 0.000 1.000 1.000 1.000
0.000 0.000 1.000 1.000 1.000

OUTPUT DATA
ARRAY C LDC=5
8.950 8.950 7.750 7.750 7.750
19.110 19.110 17.910 17.910 17.910

※dgemm とは「行列-行列積」のことで下記など参照を。
 http://www.mlab.ice.uec.ac.jp/~ej-sib/numerical/numerical_blas.html



2. 並列プログラミングのための、 linux クラスタ環境の構築。その2(SGEの導入) - heyheytowerhttp://nitrogen14.blog51.fc2.com/blog-entry-33.html を参考に OpenMPI の再コンパイルのため各ノードにおいて、管理者権限で以下を実行した。

FAQ: Building Open MPI によると OpenMPI 1.2 から SGE に対応しており、ビルドオプションは OpenMPI 1.3 以降で対応している。

cd /opt/ompi/openmpi-1.6
./configure CC=icc CXX=icpc --prefix=/usr/local/openmpi6 --with-sge --enable-mpi-thread-multiple
make all install
sudo su -
source /opt/intel/Compiler/11.1/080/bin/iccvars.sh intel64
source /opt/intel/Compiler/11.1/080/bin/ifortvars.sh intel64
make all install


3. OpenMPI の動作確認を行った。

/usr/local/openmpi6/bin/mpicc
icc: command line error: ファイルが指定されていません; ヘルプを表示するには "icc -help" と入力してください。

/usr/local/openmpi6/bin/mpiCC
icpc: command line error: ファイルが指定されていません; ヘルプを表示するには "icpc -help" と入力してください。

/usr/local/openmpi6/bin/mpirun -np 10 -machinefile .mpi uname -a
Linux ito-ubuntu 2.6.32-43-generic #97-Ubuntu SMP Wed Sep 5 16:42:26 UTC 2012 x86_64 GNU/Linux
Linux ito-ubuntu 2.6.32-43-generic #97-Ubuntu SMP Wed Sep 5 16:42:26 UTC 2012 x86_64 GNU/Linux
Linux calc3 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Linux calc1 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Linux calc2 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Linux calc3 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Linux calc1 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Linux calc2 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Linux ito-ubuntu 2.6.32-43-generic #97-Ubuntu SMP Wed Sep 5 16:42:26 UTC 2012 x86_64 GNU/Linux
Linux ito-ubuntu 2.6.32-43-generic #97-Ubuntu SMP Wed Sep 5 16:42:26 UTC 2012 x86_64 GNU/Linux

4. intel compiler でコンパイルした OpenMPI で SGE を利用できるか確認した。


Sun Grid Engine (SGE) QuickStart — StarCluster v0.92rc2 documentation を参考に、テスト用シェルスクリプトを作成し、

vi test.sh
#!/bin/sh
## a simple openmpi example
## submit with:
## $ qsub ~/mpi_hello.sh
# Export all environment variables
#$ -V
# Your job name
#$ -N test
# Use current working directory
#$ -cwd
# Join stdout and stderr
#$ -j y
# PARALLEL ENVIRONMENT:
#$ -pe mpi 4
# Enable resource reservation
#$ -R y

# The max hard walltime for this job is 16 minutes (after this it will be killed)
##$ -l h_rt=00:16:00
# The max soft walltime for this job is 15 minute (after this SIGUSR2 will be sent)
##$ -l s_rt=00:15:00

# The following is for reporting only. It is not really needed
# to run the job. It will show up in your output file.
echo "Got $1 processors."
# The mpirun command.
/usr/local/openmpi6/bin/mpirun -np $1 hostname
#mpirun -np $1 ~/


適当過ぎますが下記を実行した。

qstat -f
queuename qtype resv/used/tot. load_avg arch states

                                                                                                                                                                • -

main.q@calc1 BIP 0/2/3 0.00 lx26-amd64
738 0.50000 mpirun root r 12/29/2012 00:54:42 2

                                                                                                                                                                • -

main.q@calc2 BIP 0/2/2 0.01 lx26-amd64
738 0.50000 mpirun root r 12/29/2012 00:54:42 2

                                                                                                                                                                • -

main.q@calc3 BIP 0/2/3 0.00 lx26-amd64
738 0.50000 mpirun root r 12/29/2012 00:54:42 2

                                                                                                                                                                • -

main.q@ito-ubuntu BIP 0/2/2 0.89 lx26-amd64
738 0.50000 mpirun root r 12/29/2012 00:54:42 2


qsub test.sh 4

qstat
qstat
qstat

cat test.o769
Warning: no access to tty (不正なファイル記述子です).
Thus no job control in this shell.
Got 4 processors.
calc1
ito-ubuntu
calc2
calc3

SGE へ OpenMPI ジョブの投入は大丈夫そうです。


所感

これでひとまず並列プログラミングを行う環境が整った。
こういった環境を作りたいと思った際にネットの情報を見ると、まず環境で beowulf 方式やら、マシン間通信でMARCH と OpenMPI があって 、ジョブ管理で SGE、計算ライブラリで LINPACK と LAPACK があって…と、なかなか敷居が高いなと思いましたし、日本語の情報が少なかったです。
このサイトでそういった点が少しでもクリアになればと思います。

※並列プログラミングの情報は大学の研究室の共有ページに多く、下記サイトも参考にしました。
 「九州大学 大学院システム情報科学研究院 金子 邦彦 研究室 Web ページhttp://www.kkaneko.com/rinkou/index.html



以上。