LoginSignup
8
7

More than 1 year has passed since last update.

ジョブスケジューラーslurmをUbuntu20.04@wsl2にインストールして、テストする。

Last updated at Posted at 2021-02-07

slurmをUbuntu20.04@wsl2に入れてみたがうまくいかない

ジョブスケジューラーslurmを導入したい計算機があり、いきなりやって環境が汚れるのは嫌だったのでテストのためにUbuntu20.04@wsl2にslurmをインストールした。
ちょっとすんなりいかなかったので共有します。
なお、クラスターではなく1台の計算機のケースです。
wslではなく、通常のUbuntu20.04にも入れてみましたが、"Systemdを有効にする"と"事前準備: makeとgccのインストール"行わずにやればインストールできました。

お役に立てたら、LGTMよろしくお願いします。

参考にしたサイト
公式 : https://slurm.schedmd.com/quickstart_admin.html
参考1 : https://qiita.com/inv_Koyama/items/313ba7bdd5a9c49ab8b9
参考2:https://qiita.com/JeJeNeNo/items/c545e72373d4d1deb36a

環境
インストールしたてのUbuntu20.04@wls2にインストールする

Systemdを有効にする

wslのLinuxは、systemdがそのままだと使えないので、有効にする。
下記にまとめてあります。
Ubuntu20.04@wsl2でsystemd(systemctl)を使用する

事前準備: makeとgccのインストール

wslだと基本的なコマンドも入っていないので、入れます。

$ sudo apt update
$ sudo apt install make
$ sudo apt install gcc

事前準備:MUNGEをインストール

MUNGE(公式)はHPCクラスター用の認証システム。
参考1によるとaptでインストールできるとのこと。
ここでwslだとdpkgが入ってエラーがでることもあるのでdpkgも合わせてインストールしておく。

$ sudo apt update
$ sudo apt install dpkg
$ sudo apt install libmunge-dev
$ sudo apt install libmunge2
$ sudo apt install munge
## ちなみに、dpkgとlibmunge2はインストール済みとの表示される場合もあるが気にしない。

systemdで動いているか確認

$ sudo systemctl status munge
# 実行結果
● munge.service - MUNGE authentication service
     Loaded: loaded (/lib/systemd/system/munge.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-01-01 10:10:12 JST; 2min 5s ago

slurmをインストールする。

最新版をWindowsのブラウザでダウンロードします。
https://slurm.schedmd.com/download.html
今回は、slurm-20.11.3.tar.bz2 をダウンロードしました。
(なお、Ubuntu用(slurm-wlm)も用意されている模様。)

Windowsでダウンロードしたファイルを、wls2のUbuntuのhomeディレクトリにコピーします。
WindowsのDownloadsフォルダに上記のファイルがある場合、Ubuntuで下記のコマンドを実行。

$ cp /mnt/c/Users/XXXX/Downloads/slurm-20.11.3.tar.bz2 ~/.
# WindowsのフォルダはUbuntuで、/mnt/cとしてマウントされています。
# XXXXは適宜変更してください。

ファイルを解凍します。

$ tar -jxvf slurm-20.11.3.tar.bz2

解凍されたフォルダの中に移動して下記を実行。
下記のコマンドを実行。1つ実行するたびにしばらく待ちます。

$ ./configure
$ make
$ sudo make install

デフォルトのインストール先は/usr/localのようで、findすると下記のフォルダにファイルが加わっている模様。

$ find /usr/local -name "slurm"
# 実行結果
/usr/local/include/slurm
/usr/local/lib/slurm

設定ファイル

slurmの設定ファイルを作ります。下記にアクセス。
https://slurm.schedmd.com/configurator.easy.html
(Ubuntuで解凍したslurmフォルダのdoc/html/configurator.easy.htmlをブラウザで開くでもOK)
設定は参考2を参考にした。
私の環境は、1物理CPUの中に6コア入ったCPUを使ってます。

  • SlurmctldHost → $ hostname で返ってくる値。
  • NodeName → 上に同じ
  • CPUs:6 → 物理CPU数ではなく、コア数の模様
  • Sockets:1
  • CoresPerScoket:6
  • ThreadsPerCore:1
  • SlurmUser → 搭載しているメモリの量(free -m コマンドで表示される)
  • Resource Selection
  • SelectType: Cons_res に変更。
  • SelectTypeParameters=CR_CPU この行は設定ファイルに直接書き込みます。

でSubmitボタンを押す。buntu上で、slurm.confという名前でファイルを作って出てきたテキストをコピペ。
さらに、下記の行を手動で書き換える。
#SelectTypeParameters=
→ SelectTypeParameters=CR_CPU

私の場合は、エラーが出たので下記としてます。人によってはcgroupのままでいいかも。
ProctrackType=proctrack/cgroup
→ ProctrackType=proctrack/linuxproc
X11使ってるとそうなるっぽい。

/usr/local/etc/slurm.conf
# slurm.conf file generated by configurator easy.html.
# Put this file on all nodes of your cluster.
# See the slurm.conf man page for more information.
#
SlurmctldHost=PC-wsl
#
#MailProg=/bin/mail
MpiDefault=none
#MpiParams=ports=#-#
#ProctrackType=proctrack/cgroup
ProctrackType=proctrack/linuxproc
ReturnToService=1
SlurmctldPidFile=/var/run/slurmctld.pid
#SlurmctldPort=6817
SlurmdPidFile=/var/run/slurmd.pid
#SlurmdPort=6818
SlurmdSpoolDir=/var/spool/slurmd
SlurmUser=root
#SlurmdUser=root
StateSaveLocation=/var/spool
SwitchType=switch/none
TaskPlugin=task/affinity
#
#
# TIMERS
#KillWait=30
#MinJobAge=300
#SlurmctldTimeout=120
#SlurmdTimeout=300
#
#
# SCHEDULING
SchedulerType=sched/backfill
SelectType=select/cons_res
SelectTypeParameters=CR_CPU
#
#
# LOGGING AND ACCOUNTING
AccountingStorageType=accounting_storage/none
ClusterName=cluster
#JobAcctGatherFrequency=30
JobAcctGatherType=jobacct_gather/none
#SlurmctldDebug=info
#SlurmctldLogFile=
#SlurmdDebug=info
#SlurmdLogFile=
#
#
# COMPUTE NODES
NodeName=PC-wsl CPUs=6 RealMemory=7000 Sockets=1 CoresPerSocket=6 ThreadsPerCore=1 State=UNKNOWN
PartitionName=debug Nodes=PC-wsl Default=YES MaxTime=INFINITE State=UP

作ったファイルを/usr/local/etc/にコピー

$ sudo cp slurm.conf /usr/local/etc/

slurmをsystemdで起動する

コピーして、有効にして、開始します。

$ sudo cp etc/slurmctld.service /etc/systemd/system
$ sudo cp etc/slurmd.service /etc/systemd/system
$ sudo systemctl enable slurmctld.service
$ sudo systemctl enable slurmd.service
$ sudo systemctl start  slurmctld.service
$ sudo systemctl start  slurmd.service

実行されているか確認する。

$ systemctl status slurmctld.service
# 実行結果
● slurmctld.service - Slurm controller daemon
     Loaded: loaded (/etc/systemd/system/slurmctld.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-01-01 16:01:01 JST; 2h 0min ago

$systemctl status slurmd.service
# 実行結果
● slurmd.service - Slurm node daemon
     Loaded: loaded (/etc/systemd/system/slurmd.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-01-01 16:01:01 JST; 2h 0min ago

どちらもactive(running)になっていればOK。
ちなみに、エラーが出ているときの対処法を、簡単に記載しております。
systemdでslurmがエラーになる場合の対処方法

キューにジョブを投げて、うまく動くか確認してみる。

まず、ジョブチェック用のシェルスクリプト 1.sh を作ります。

1.sh
#!/bin/bash

#SBATCH -J 1Core
#SBATCH -o output_%j.txt
#SBATCH -e errors_%j.txt
#SBATCH -p debug
#SBATCH -n 1

echo Lets sleep
sleep 30

以下、解説

  • #SBATCH -J 1Core     #Job名
  • #SBATCH -o output_%j.txt #標準出力
  • #SBATCH -e errors_%j.txt  #エラー出力
  • #SBATCH -p debug    #キューの名前。デフォルトキューはdebug
  • #SBATCH -n 1       #Slurm上で要求するCPUコア数

投げて、確認してみる。コマンドは$ sbatch。続けてシェルスクリプトの名前を打つ。

$ sbatch 1.sh

投入したジョブの状態を確認する。$ squeueコマンドで確認できます。

$ squeue
#実行結果
 JOBID PARTITION     NAME     USER  ST   TIME   NODES NODELIST(REASON)
   1     debug     1Core      XXX  R    0:02      1 PC-wsl

ST(State)がR(Run)になっていてジョブが走っているのがわかる。

1.shの#SBATCH -n の値を2と4と変更したファイルを、それぞれ2.sh 4.shと名前をつつけて適当に流してみる。

$ squeue
# 実行結果
  JOBID PARTITION     NAME     USER ST       TIME  NODES NODELIST(REASON)
     38     debug    4Core      XXX PD       0:00      1 (Resources)
     39     debug    1Core      XXX PD       0:00      1 (Priority)
     40     debug    4Core      XXX PD       0:00      1 (Priority)
     41     debug    2Core      XXX PD       0:00      1 (Priority)
     34     debug    1Core      XXX  R       0:29      1 PC-wsl
     35     debug    1Core      XXX  R       0:18      1 PC-wsl
     36     debug    2Core      XXX  R       0:15      1 PC-wsl
     37     debug    2Core      XXX  R       0:14      1 PC-wsl

このマシンは全部で6Coreとして設定しましたが、いい感じCPUに応じてジョブを割り振って(JOBID:34~37のST=R)、
残りは待機状態(JOBID=38~41のSTがPD)になってくれています。

8
7
0

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
8
7