電子計算記

個人的な検証を

7. MPIクラスターを作ろう! - rsyncで実行バイナリをノード間コピー

前回からのつづきです。
6. MPIクラスターを作ろう! - 複数ノードへスケールアウト - 電子計算記

もうひとつ別のプログラムをコンパイルして実行してみましょう。(そのままだとうまく動かないので。)

Wikipdediaにあるサプログラム例がMPIの勉強はじめるにはまとまっていてわかりやすくてよいのでこれを使います。

Message Passing Interface - Wikipedia

これをビルドし実行してみます。

mpiuser@compute-1:~$ mkdir wikipedia_hello
mpiuser@compute-1:~$ cd wikipedia_hello/
mpiuser@compute-1:~/wikipedia_hello$ vi hello_w.c
mpiuser@compute-1:~/wikipedia_hello$ mpicc hello_w.c
mpiuser@compute-1:~/wikipedia_hello$ mpirun -np 4 --host compute-1,compute-2,compute-3,compute-4 ./a.out 
--------------------------------------------------------------------------
mpirun was unable to launch the specified application as it could not access
or execute an executable:

Executable: ./a.out
Node: compute-3

while attempting to start process rank 2.
--------------------------------------------------------------------------
3 total processes failed to start
mpiuser@compute-1:~/wikipedia_hello$ 

はいエラーになりました。今ビルドしたバイナリがcompute-1上にしかなく、他のノード上にないため実行できないのです。
MPIはSPMD(Single Program, Multiple Data streams)として動きますが、他ノードに実行バイナリを展開する機能はありませんので、実行前に自分で各ノードへ展開する必要が有ります。
毎回展開が面倒だったり、出力結果をまとめるのが面倒だったりするので、共有ストレージを使う方が一般的です。後の方のコマで、NFSを使ってMPIクラスター環境を構築しましょう。


ではここでは、手っ取り早くrsyncで実行バイナリをコピーしましょう。ホストで指定する全ノードへコピーします。

mpiuser@compute-1:~/wikipedia_hello$ rsync -a ~/wikipedia_hello compute-2:~/
mpiuser@compute-1:~/wikipedia_hello$ rsync -a ~/wikipedia_hello compute-3:~/
mpiuser@compute-1:~/wikipedia_hello$ rsync -a ~/wikipedia_hello compute-4:~/

あとは同じように実行するのみです。

mpiuser@compute-1:~/wikipedia_hello$ mpirun -np 4 --host compute-1,compute-2,compute-3,compute-4 ./a.out 
0: We have 4 processors
0: Hello 1! Processor 1 reporting for duty
0: Hello 2! Processor 2 reporting for duty
0: Hello 3! Processor 3 reporting for duty

無事動きました。

毎回--hostでホストを指定するのは面倒ですよね。ノード数が多くなればなおさらです。
次回はもっと便利な方法--hostfileを紹介します。

fujish.hateblo.jp