こちらは、cfnclusterを使う前に鍵を作っておく必要があります。
以下のURLへアクセスして「キーペアを作成」というボタンを押します。
https://ap-northeast-1.console.aws.amazon.com/ec2/v2/home?region=ap-northeast-1#KeyPairs:sort=keyFingerprint
名前を付けると、あとは自動的にpemファイルのダウンロードが始まるので、保存しておきます。
続いて、cfnclusterから設定を作成します。cfncluster configureと入力すると、CLI上でウィザードが始まるので、質問に答えていきます。
>cfncluster configure
Cluster Template [default]:
AWS Access Key ID []: QWERTYUIOP{}
AWS Secret Access Key ID []: ASDFGHJKL:"
Acceptable Values for AWS Region ID:
us-east-1
cn-north-1
ap-northeast-1
ap-southeast-2
sa-east-1
ap-southeast-1
ap-northeast-2
us-west-2
us-gov-west-1
us-west-1
eu-central-1
eu-west-1
AWS Region ID []:ap-northeast-1
VPC Name [public]:
Acceptable Values for Key Name:
CfnClusterTest
Key Name []: CfnClusterTest
Acceptable Values for VPC ID:
vpc-123n456
VPC ID []: vpc-123n456
Acceptable Values for Master Subnet ID:
subnet-987f6543
subnet-12345678
Master Subnet ID []:subnet-987f654
リージョン、鍵ペア、VPC、サブネットIDなどを指定するんですが、それぞれ設定可能な値が選択肢として表示されるので、ここからコピペすればOKです。また、1回選択した内容は保存されているようなので、再度cfncluster configureを実行すると、デフォルトの値として前回使った値が表示されます。
これで、$HOME/.cfncluster/config以下に設定ファイルが作成されるんですが、starclusterと違って上記で入力した値しか書かれていません。
後は、ここのドキュメントを見ながら必要な設定を追記していきます。
Configuration — CfnCluster 1.2.1
今回追記したのは全て[cluster default]セクションの中で、以下の5項目です。
この設定で、4ノード構成のクラスタが立ち上がり、用が無くなったら勝手に落としてくれるはず。
schedulerはデフォルトでは、starclusterと同じくSGEですが、openlava, torque, slurmも使えるとのことなので、慣れてるslurmで試してみることにします。
compute_instance_type = c3.large
master_instance_type = c3.large
initial_queue_size = 4
max_queue_size = 4
scheduler = slurm
もし、まったくジョブが流れてなくても何ノードかは常に立ち上げておきたいという時は、initial_queue_sizeに必要なノード数を設定し、
maintain_initial_size = true
という設定を追加します。これで、Autoscalingの設定が変わって、最小ノード数以下まで下げることは無くなるとのこと。
続けてクラスタを起動します。
> cfncluster create mycluster
驚くほど遅いので、一服しながら待ちましょう。今回の構成だと、だいたい15分くらいかかりました。
$HOME/.cfncluster/cfncluster-cli.logにログが吐かれてますが、何か特別時間がかかる処理があるわけではなく、満遍無く遅いようです・・・。
起動が完了したら、次のようにMasterノードのIPアドレスとGangliaのURLが表示されます。
Output:"MasterPrivateIP"="172.31.13.62"
Output:"MasterPublicIP"="52.196.251.236"
Output:"GangliaPrivateURL"="http://172.31.13.62/ganglia/"
Output:"GangliaPublicURL"="http://52.196.251.236/ganglia/"
最初に作ったkeypairを使ってログインしてみましょう。
> ssh ec2-user@52.196.251.236 -i CfnClusterTest.pem
とりあえず、何が入っているのか分からんので適当に試してみたところ、こんな感じでした。
>$ gcc --version
gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ mpirun --version
-bash: mpirun: command not found
$ sbatch --version
-bash: sbatch: command not found
$ which qsub
/opt/sge/bin/lx-amd64/qsub
わざわざスケジューラにslurmを指定したのに、そもそも全部入ってたようです・・・
$ /opt/slurm/bin/sinfo
sinfo: error: s_p_parse_file: unable to status file /opt/slurm/etc/slurm.conf: No such file or directory, retrying in 1sec up to 60sec
$ qconf -sel
ip-172-31-15-101.ap-northeast-1.compute.internal
ip-172-31-15-102.ap-northeast-1.compute.internal
ip-172-31-15-103.ap-northeast-1.compute.internal
ip-172-31-15-104.ap-northeast-1.compute.internal
そして、sinfo(slurmの情報表示コマンド)は使えないのに、qconf(SGEの設定コマンド)は正常に動作するという・・・
MPIの方はどうかというと
$ yum list installed |grep -i mpi
mpich.x86_64 3.0.4-4.5.amzn1 @amzn-main
mpich-devel.x86_64 3.0.4-4.5.amzn1 @amzn-main
openmpi.x86_64 1.6.4-5.29.amzn1 @amzn-main
openmpi-devel.x86_64 1.6.4-5.29.amzn1 @amzn-main
インストール済なんだけどPATHは通ってないようです。
$ rpm -ql openmpi.x86_64
/etc/openmpi-x86_64
/etc/openmpi-x86_64/openmpi-default-hostfile
/etc/openmpi-x86_64/openmpi-mca-params.conf
/etc/openmpi-x86_64/openmpi-totalview.tcl
/etc/profile.d/openmpi.sh
/usr/lib64/gfortran/modules/openmpi-x86_64
/usr/lib64/openmpi
/usr/lib64/openmpi/bin
/usr/lib64/openmpi/bin/mpiexec
/usr/lib64/openmpi/bin/mpirun
/usr/lib64/openmpi/bin/ompi-clean
・
・
・
$ cat /etc/profile.d/openmpi.sh
function set_openmpi {
MPI_HOME=/usr/lib64/openmpi
MPI_BIN=$MPI_HOME/bin
MPI_LIB=$MPI_HOME/lib
MPI_MAN=/usr/share/man/openmpi-x86_64
MPI_INCLUDE=/usr/include/openmpi-x86_64
MPI_SYSCONFIG=/etc/openmpi-x86_64
MPI_COMPILER=openmpi-x86_64
MPI_SUFFIX=_openmpi
MPI_PYTHON_SITEARCH=/usr/lib64/python2.6/dist-packages/openmpi
MPI_FORTRAN_MOD_DIR=/usr/lib64/gfortran/modules/openmpi-x86_64
}
function load_openmpi {
set_openmpi
export PATH=$MPI_BIN:$PATH
export LD_LIBRARY_PATH=$MPI_LIB:$LD_LIBRARY_PATH
export MANPATH=$MPI_MAN:$MANPATH
export MPI_HOME MPI_BIN MPI_LIB MPI_MAN MPI_INCLUDE MPI_SYSCONFIG
export MPI_COMPILER MPI_SUFFIX MPI_PYTHON_SITEARCH MPI_FORTRAN_MOD_DIR
}
function unload_openmpi {
set_openmpi
export PATH=$(echo $PATH | tr : '\n' | egrep -v "^$MPI_BIN$" | tr '\n' :)
export LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | tr : '\n' | egrep -v "^$MPI_LIB$" | tr '\n' :)
export MANPATH=$(echo $MANPATH | tr : '\n' | egrep -v "^$MPI_MAN$" | tr '\n' :)
unset MPI_HOME MPI_BIN MPI_LIB MPI_MAN MPI_INCLUDE MPI_SYSCONFIG
unset MPI_COMPILER MPI_SUFFIX MPI_PYTHON_SITEARCH MPI_FORTRAN_MOD_DIR
}
えーっと・・・これmodule経由で使うものなんでは。
というわけで、.bashrcの末尾に以下の一行を追記します。
load_openmpi
でもって、再度ログインすると
$ mpirun --version
mpirun (Open MPI) 1.6.4
Report bugs to http://www.open-mpi.org/community/help/
正常にmpi関連のコマンドが動くようになりました。
一応こっちも一応HPLを流してみましょう。
staclusterの時の残念な結果があるので、まずはBLASの確認
$ yum list installed |grep blas
blas.x86_64 3.5.0-8.6.amzn1 @amzn-main
blas-devel.x86_64 3.5.0-8.6.amzn1 @amzn-main
$ rpm -qi blas.x86_64
Name : blas
Version : 3.5.0
Release : 8.6.amzn1
Architecture: x86_64
Install Date: Wed 23 Mar 2016 11:50:31 PM UTC
Group : System Environment/Libraries
Size : 782395
License : BSD
Signature : RSA/SHA256, Thu 18 Sep 2014 01:36:21 AM UTC, Key ID bcb4a85b21c0f39f
Source RPM : lapack-3.5.0-8.6.amzn1.src.rpm
Build Date : Wed 17 Sep 2014 09:15:24 PM UTC
Build Host : build-64001.build
Relocations : (not relocatable)
Packager : Amazon.com, Inc. <http://aws.amazon.com>
Vendor : Amazon.com
URL : http://www.netlib.org/lapack/
Summary : The Basic Linear Algebra Subprograms library
Description :
BLAS (Basic Linear Algebra Subprograms) is a standard library which
provides a number of basic algorithms for numerical algebra.
えーっと・・・Netlib版のBLASなのか・・・
これはさすがにありえんので、OpenBLASをインストールします。
$ sudo yum install openblas -y
Loaded plugins: priorities, update-motd, upgrade-helper
956 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package openblas.x86_64 0:0.2.16-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================================
Installing:
openblas x86_64 0.2.16-3.el6 epel 5.5 M
Transaction Summary
=============================================================================================================================================================================
Install 1 Package
Total download size: 5.5 M
Installed size: 32 M
Downloading packages:
warning: /var/cache/yum/x86_64/2016.03/epel/packages/openblas-0.2.16-3.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Public key for openblas-0.2.16-3.el6.x86_64.rpm is not installed
openblas-0.2.16-3.el6.x86_64.rpm | 5.5 MB 00:00
Retrieving key from http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
Userid : "EPEL (6) <epel@fedoraproject.org>"
Fingerprint: 8c3b e96a f230 9184 da5c 0dae 3b49 df2a 0608 b895
From : http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : openblas-0.2.16-3.el6.x86_64 1/1
Verifying : openblas-0.2.16-3.el6.x86_64 1/1
Installed:
openblas.x86_64 0:0.2.16-3.el6
Complete!
[ec2-user@ip-172-31-13-62 ~]$ sudo yum install openblas-devel -y
Loaded plugins: priorities, update-motd, upgrade-helper
956 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package openblas-devel.x86_64 0:0.2.16-3.el6 will be installed
--> Processing Dependency: openblas-threads(x86-64) = 0.2.16-3.el6 for package: openblas-devel-0.2.16-3.el6.x86_64
--> Processing Dependency: openblas-openmp(x86-64) = 0.2.16-3.el6 for package: openblas-devel-0.2.16-3.el6.x86_64
--> Processing Dependency: libopenblasp.so.0()(64bit) for package: openblas-devel-0.2.16-3.el6.x86_64
--> Processing Dependency: libopenblaso.so.0()(64bit) for package: openblas-devel-0.2.16-3.el6.x86_64
--> Running transaction check
---> Package openblas-openmp.x86_64 0:0.2.16-3.el6 will be installed
---> Package openblas-threads.x86_64 0:0.2.16-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================================
Installing:
openblas-devel x86_64 0.2.16-3.el6 epel 88 k
Installing for dependencies:
openblas-openmp x86_64 0.2.16-3.el6 epel 5.6 M
openblas-threads x86_64 0.2.16-3.el6 epel 5.6 M
Transaction Summary
=============================================================================================================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 11 M
Installed size: 68 M
Downloading packages:
(1/3): openblas-devel-0.2.16-3.el6.x86_64.rpm | 88 kB 00:00
(2/3): openblas-openmp-0.2.16-3.el6.x86_64.rpm | 5.6 MB 00:00
(3/3): openblas-threads-0.2.16-3.el6.x86_64.rpm | 5.6 MB 00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 15 MB/s | 11 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : openblas-threads-0.2.16-3.el6.x86_64 1/3
Installing : openblas-openmp-0.2.16-3.el6.x86_64 2/3
Installing : openblas-devel-0.2.16-3.el6.x86_64 3/3
Verifying : openblas-devel-0.2.16-3.el6.x86_64 1/3
Verifying : openblas-openmp-0.2.16-3.el6.x86_64 2/3
Verifying : openblas-threads-0.2.16-3.el6.x86_64 3/3
Installed:
openblas-devel.x86_64 0:0.2.16-3.el6
Dependency Installed:
openblas-openmp.x86_64 0:0.2.16-3.el6 openblas-threads.x86_64 0:0.2.16-3.el6
Complete!
あとは、staclusterの時と同じようにHPLのソースをダウンロードしてきて、ビルド&実行します。
$ wget http://www.netlib.org/benchmark/hpl/hpl-2.2.tar.gz
--2016-05-31 14:13:01-- http://www.netlib.org/benchmark/hpl/hpl-2.2.tar.gz
Resolving www.netlib.org (www.netlib.org)... 160.36.131.221
Connecting to www.netlib.org (www.netlib.org)|160.36.131.221|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 539979 (527K) [application/x-gzip]
Saving to: ‘hpl-2.2.tar.gz’
hpl-2.2.tar.gz 100%[========================================================================================>] 527.32K 598KB/s in 0.9s
2016-05-31 14:13:03 (598 KB/s) - ‘hpl-2.2.tar.gz’ saved [539979/539979]
$ tar xfz hpl-2.2.tar.gz
$ cd hpl-2.2
$ cp setup/Make.Linux_PII_FBLAS ./
staclusterの時と同じくMake.Linux_PII_FBLASを編集します。(LAdir, LAlibの設定はちょっと変わっています。)
TOPdir = $(HOME)/hpl-2.2
MPdir, MPinc, MPlib ->コメントアウト
LAdir=/usr/lib64
LAlib= -L$(LAdir) -lopenblas
CC=mpicc
LINKER=mpicc
そして、makeします。
$ make arch=Linux_PII_FBLAS 2>&1 |tee makelog
HPL.datをstarclusterの時と同様に編集したらジョブ投入
> qsub -cwd -pe mpi 8 -b y mpirun ./xhpl
ところが、こんなエラーを吐いて終了します。
$ cat mpirun.e2
-sh: mpirun: command not found
エラーメッセージから察するに、bashじゃなくてsh経由でジョブを投げようとしているようなので、シェルスクリプトを作ってこっち経由で投げます。
$ cat run.sh
#!/bin/bash
mpirun ./xhpl
$ qsub -cwd -pe mpi 8 run.sh
Unable to run job: warning: ec2-user's job is not allowed to run in any queue
あれ・・・?
$ qconf -sel
no execution host defined
あ、アイドル状態が長すぎて計算ノードが落とされてますね・・・
EC2のマネジメントコンソールを見ると、確かに"Compute"と書かれたインスタンスがterminatedになっています。時間的にも起動して1時間くらい経過していたので、きちんと機能していますね!最大の問題は、この状態から計算ノードを起動する方法が分からんあたり・・・
仕方が無いので、一旦削除してもう一度作り直してみます。
ついでにopenblasのインストールは計算ノード側でもやらないと駄目だったことにも気付いたので改めて作業内容をまとめておきます。
>cfncluster create mycluster
Starting: mycluster
Status: cfncluster-mycluster - CREATE_COMPLETE Output:"MasterPrivateIP"="172.31.6.163"
Output:"MasterPublicIP"="52.192.191.47"
Output:"GangliaPrivateURL"="http://172.31.6.163/ganglia/"
Output:"GangliaPublicURL"="http://52.192.191.47/ganglia/"
>ssh ec2-user@52.192.191.47 -i CfnClusterTest.pem
$ for i in `qconf -sel`;do ssh $i "sudo yum install openblas openblas-devel -y"
$ wget http://www.netlib.org/benchmark/hpl/hpl-2.2.tar.gz
$ tar xfz hpl-2.2.tar.gz
$ cd hpl-2.2
$ cp setup/Make.Linux_PII_FBLAS ./
$ make CC=mpicc LINKER=mpicc TOPdir=`pwd` MPdir="" MPinc="" MPlib="" LAlib="-L/usr/lib64 -lopenblas" arch=Linux_PII_FBLAS 2>&1 |tee makelog
でもって、さっきと同じようにHPL.datを編集したらジョブを投げます。ただし、load_openmpiはrun.shの中で実行するように変更しました。
$ cat run.sh
#!/bin/bash
load_openmpi
mpirun ./xhpl
$ qsub -cwd -pe mpi 8 run.sh
Your job 1 ("run.sh") has been submitted
ジョブが完走したら、run.sh.o2に結果が出力されます。
$ cat run.sh.o2
================================================================================
HPLinpack 2.2 -- High-Performance Linpack benchmark -- February 24, 2016
Written by A. Petitet and R. Clint Whaley, Innovative Computing Laboratory, UTK
Modified by Piotr Luszczek, Innovative Computing Laboratory, UTK
Modified by Julien Langou, University of Colorado Denver
================================================================================
An explanation of the input/output parameters follows:
T/V : Wall time / encoded variant.
N : The order of the coefficient matrix A.
NB : The partitioning blocking factor.
P : The number of process rows.
Q : The number of process columns.
Time : Time in seconds to solve the linear system.
Gflops : Rate of execution for solving the linear system.
The following parameter values will be used:
N : 40000
NB : 64
PMAP : Row-major process mapping
P : 4
Q : 2
PFACT : Left
NBMIN : 2
NDIV : 2
RFACT : Left
BCAST : 1ring
DEPTH : 0
SWAP : Mix (threshold = 64)
L1 : transposed form
U : transposed form
EQUIL : yes
ALIGN : 8 double precision words
--------------------------------------------------------------------------------
- The matrix A is randomly generated for each test.
- The following scaled residual check will be computed:
||Ax-b||_oo / ( eps * ( || x ||_oo * || A ||_oo + || b ||_oo ) * N )
- The relative machine precision (eps) is taken to be 1.110223e-16
- Computational tests pass if scaled residuals are less than 16.0
================================================================================
T/V N NB P Q Time Gflops
--------------------------------------------------------------------------------
WR00L2L2 40000 64 4 2 542.05 7.872e+01
HPL_pdgesv() start time Tue May 31 15:30:31 2016
HPL_pdgesv() end time Tue May 31 15:39:33 2016
--------------------------------------------------------------------------------
||Ax-b||_oo/(eps*(||A||_oo*||x||_oo+||b||_oo)*N)= 0.0043542 ...... PASSED
================================================================================
Finished 1 tests with the following results:
1 tests completed and passed residual checks,
0 tests completed and failed residual checks,
0 tests skipped because of illegal input values.
--------------------------------------------------------------------------------
End of Tests.
================================================================================
78.72Gflopsなので、実行効率にして45.5%ですね。starclusterの時と比べると約3倍になってますが、ちょっともの足りない数字です。
まだサイズを増やせば性能が上がる可能性もありますが、c3.largeだとメモリの制約が厳しいので、これより大きいサイズで測定するのは厳しそうです。
あと、OpenBLASの方がAtlasよりは性能が高いとは思いますが、DGEMM単体での性能を測定したわけではないので、まだBLASの性能が不足しているという可能性もありそうです。この辺はそのうち再検証してみましょう。
では、最後にクラスタを削除します。
>cfncluster delete mycluster