This is an old revision of the document!
事前にmake, build-essential, gfortranのインストールが必要です。 入っていない場合は以下のようにして入手します。
$ sudo apt install make build-essential gfortran
ダウンロードしたファイルはホーム・ディレクトリにおいてください。 これを展開します。
$ tar xzvf openmpi-4.0.2.tar.gz $ cd openmpi-4.0.2
インストール前に、インストール先とコンパイラを指定します。 (注意!下にも書きましたが、2017年以降のIntel C/C++コンパイラではうまくコンパイルできません)
$ ./configure --prefix=/usr/local/openmpi CC=gcc CXX=g++ FC=gfortran
管理者権限を持っていない場合はprefix=/home/username/openmpiなどとすればよいでしょう。 そしてコンパイルします。
$ make all $ sudo su # source /home/username/.bashrc # make install
~/.bashrcを開いて、ファイルの最後に次の文を付け加えます。
MPIROOT=/usr/local/openmpi PATH=$MPIROOT/bin:$PATH LD_LIBRARY_PATH=$MPIROOT/lib:$LD_LIBRARY_PATH MANPATH=$MPIROOT/share/man:$MANPATH export MPIROOT PATH LD_LIBRARY_PATH MANPATH
できたら、コンピュータを再起動するか
$ source ~/.bashrc
で再度読み込みます。
$ mpif90 -v $ mpicc -v
などで、インストールが成功したか確認できます。
コンパイルは、
$ mpif90 -o test test.f90
$ mpicc -o test test.cc
でできます。 コンパイルオプションの付け方はgfortranやgcc, g++のときと同じです。 MPIで実行する場合は
$ mpirun -n 2 test
ここで-nで指定してるのはプロセスの数(並列数)です。
hostfile でホスト名とコア数を列挙したファイル。
$ echo "localhost slots=$(grep processor /proc/cpuinfo | wc -l)" > hostfile
などで作成する。 ユーザ全体に同じホストを利用させたい場合は $MPIROOT/etc/openmpi-default-hostfile を編集する.
実行時は
$ mpirun --hostfile /path/to/hostfile -n 2 test
Ubuntu18.04でIntel C/C++コンパイラを使うと、configureで次のようなエラーが出てしまいます。
$ ./configure --prefix=/usr/local/openmpi CC=icc CXX=icpc F77=ifort FC=ifort (中略) ============================================================================ == Compiler and preprocessor tests ============================================================================ *** C compiler and preprocessor checking for gcc... (cached) icc checking whether we are using the GNU C compiler... (cached) yes checking whether icc accepts -g... (cached) yes checking for icc option to accept ISO C89... (cached) none needed checking whether icc understands -c and -o together... (cached) yes checking for icc option to accept ISO C99... unsupported configure: WARNING: Open MPI requires a C99 compiler configure: error: Aborting.