This is an old revision of the document!
$ sudo apt install openmpi-bin libopenmpi-dev
事前に各ノードのCPUのコア数(物理コア数)とスレッド数(論理コア数)を確認してください
$ cat /proc/cpuinfo | grep "physical id"
$ cat /proc/cpuinfo | grep "cpu cores"
$ cat /proc/cpuinfo | grep "processor"
管理ノードと計算ノードの間の通信はSSHで行います。
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/sugimoto/.ssh/id_rsa): Created directory '/home/sugimoto/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/sugimoto/.ssh/id_rsa. Your public key has been saved in /home/sugimoto/.ssh/id_rsa.pub. The key fingerprint is: SHA256:ZLnV/uJ8+lml7EdU+j8sjGJdxqF6F+tyg8FrD2hP3hI sugimoto@kanri The key's randomart image is: +---[RSA 2048]----+ | | | . . .| | + . . ..| | o o . .. .| | S . + .o.| | .E B .+| | ooo@ B.o| | .++%oX.=o| | . +o@B*..| +----[SHA256]-----+
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ echo "StrictHostKeyChecking no" >> ~/.ssh/config
$ chmod 600 ~/.ssh/id_rsa $ chmod 600 ~/.ssh/authorized_keys $ chmod 700 ~/.ssh/
$ ssh keisan11
作業は全て管理ノードで行います
次のコードを使って説明します
#include <stdio.h> #include "mpi.h" int main( int argc, char *argv[] ) { int rank, size, len; char name[MPI_MAX_PROCESSOR_NAME]; MPI_Init( &argc, &argv ); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); MPI_Comm_size( MPI_COMM_WORLD, &size ); MPI_Get_processor_name( name, &len ); name[len] = '\0'; printf( "Hello World! I am %d of %d from %s.\n", rank, size, name ); MPI_Finalize(); return 0; }
$ mpicc -o hello hello.c $ mpiicc -o hello hello.c # Intel MPIを使用する場合
$ mpirun -n 4 hello Hello World! I am 0 of 4 from kanri. Hello World! I am 1 of 4 from kanri. Hello World! I am 2 of 4 from kanri. Hello World! I am 3 of 4 from kanri.
指定した計算ノードにジョブを投げてみます。
$ mpirun -n 24 hello keisan11 Hello World! I am 0 of 24 from keisan11. Hello World! I am 1 of 24 from keisan11. Hello World! I am 2 of 24 from keisan11. Hello World! I am 3 of 24 from keisan11. (以下略)