並列計算用 C/C++ & Fortran コンパイラーのインストールと設定
以下では, 数値計算サーバやスパコンでよく利用されている PGI コンパイラと Intel コンパイラのインストール・設定方法について述べる.
注) 以下を仮想マシンで行う場合はディスク容量が足りなりない & CPU 数が足りない. 教員に資源増加を申請を行うこと.
ディスクを増設する場合には以下のようにする.
vm$ sudo -s vm# cfdisk /dev/sdb /dev/sdb1 を作成する. vm# mkfs.ext4 /dev/sdb1 (ファイルシステムの作成) vm# mkdir /opt vm# mount /dev/sdb1 /opt /dev/sdb1 を永続的に /opt にマウントする場合は, /etc/fstab に設定を記述する.
また, 本来はコンパイラーとセットとしてジョブスケジューラをインストールすべきである. しかし, PBS 系の PBS pro はオープンソース化されたばかりでうまくインストールできず, また torque (PBS pro のクローン) は本家の PBS pro がオープンソース化されたためか 開発が止まってしまい Debian パッケージから無くなってしまった. 現在は slurm を使うべきかもしれないが, まだ未調査である.
PGI コンパイラのインストール
科学技術並びにエンジニアリング分野においてよく利用される C/C++ & Fortran コンパイラである PGI コンパイラ を用いる. PGI コンパイラにはいくつかのエディションがあるが, PGI CommunityEdition は, ライセンスを毎年更新すれば, 無償で永続的に利用することができる. 以下では CommunityEdition をセットアップする方法を述べる.
インストール
1) 米国 PGIの「PGI Community Edition」サイト より, "Linux x86-64" をクリックすると Linunx 版が手元の PC にダウンロードされる.

2) ダウンロードしたファイル (例えば pgilinux-2018-1810-x86-64.tar.gz のような名前になっている) を自分の仮想マシンへコピーする. Windows PC にインストールされているFileZilla などのファイル転送ツールを使うと良い.
3) 必要なパッケージを仮想マシンにインストール
vm$ sudo -s vm# apt-get update vm# apt-get upgrade vm# apt-get install gcc-multilib g++-multilib gfortran gfortran-multilib lsb-compat
4) PGI コンパイラのインストール
vm$ mkdir pgilinux-2018-1810-x86-64 vm$ cd pgilinux-2018-1810-x86-64 vm$ mv ~/pgilinux-2018-1810-x86-64.tar.gz . (ソースファイルを移動. パスは適宜修正すること) vm$ tar zxvf pgilinux-2018-1810-x86-64.tar.gz vm$ sudo -s vm# export LANG=C vm# export LC_ALL=C vm# ./install Welcome to the PGI Linux installer! You are installing PGI 2018 version 18.10 for Linux. Please note that all Trademarks and Marks are the properties of their respective owners. Press enter to continue... (エンター打鍵) ...(略, ライセンスの表示, エンターで進める)... Do you accept these terms? (accept,decline) accept (打鍵) A network installation will save disk space by having only one copy of the compilers and most of the libraries for all compilers on the network, and the main installation needs to be done once for all systems on the network. 1 Single system install 2 Network install Please choose install option: 1 (1 を入力) Please specify the directory path under which the software will be installed. The default directory is /opt/pgi, but you may install anywhere you wish, assuming you have permission to do so. Installation directory? [/opt/pgi] (変更しないので, そのままエンターを打鍵) ************************************************************************ JRE ************************************************************************ ...(略)... ...(略, ライセンスの表示, エンターで進める)... Do you accept these terms? (accept,decline) accept (打鍵) ############################################################# If you use the 2018 directory in your path, you may choose to update the links in that directory to point to the 18.10 directory. Do you wish to update/create links in the 2018 directory? (y/n) y (y を入力) ...(略)... ************************************************************************ MPI ************************************************************************ This release contains version 2.1.2 of the Open MPI library. Press enter to continue... (エンターを打鍵) Do you want to install Open MPI onto your system? (y/n) y (y を入力) Do you want to enable NVIDIA GPU support in Open MPI? (y/n) y ...(略)... ************************************************************************ License Key Management ************************************************************************ ...(略)... Do you wish to obtain permanent license key or configure license service? (y/n) n ...(略)... Do you want the files in the install directory to be read-only? (y/n) n vm# cd vm# rm -r pgilinux-2018-1810* (削除しないとディスク容量が不足する)
5) 環境変数の設定
vm$ vi ~/.bashrc #PGI fortran export PGI=/opt/pgi export PATH=$PGI/linux86-64/2018/bin:$PATH export PATH=$PGI/linux86-64/2018/mpi/openmpi/bin:$PATH export MANPATH=$MANPATH:$PGI/linux86-64/2018/man:/opt/pgi/linux86-64/2018/mpi/openmpi/share/man export LM_LICENSE_FILE=$PGI/license.dat vm$ source ~/.bashrc
テスト
簡単な C, Fortran プログラムを書き, コンパイルと実行ができるかテストする.
C コンパイラは pgcc, C++ コンパイラは pgc++ である.
vm$ vi hello.c #include<stdio.h> int main(){ printf("Hello World\n"); } vm$ pgcc hello.c vm$ ./a.out Hello World
Fortran77 コンパイラは pgf77, Fortran90 コンパイラは pgf90 である.
vm$ vi hello.f90 program main write(*,*) "Hello World" end program main vm$ pgf90 hello.f90 vm$ ./a.out Hello World
MPI 並列のテストは, 理研が公開している有名な姫野ベンチマークを用いて行うと良い. Fortran コンパイラ + MPI の場合は以下のようにする.
vm$ wget http://i.riken.jp/wp-content/uploads/2015/07/f90_xp_mpi.zip vm$ unzip f90_xp_mpi.zip vm$ sudo apt-get install lhasa vm$ lha -x f90_xp_mpi.lzh vm$ mpif90 himenoBMTxpr.f90 vm$ mpiexec -n 2 ./a.out (もしくは $ mpirun -np 2 ./a.out ) Grid-size = XS DDM pattern = 1 1 2 ...(中略)... messages Loop executed for 778 times Gosa : 8.4892433E-04 MFLOPS: 1722.963182862446 time(s): 61.90950385300016 Score based on Pentium III 600MHz : 20.79869
C コンパイラ + MPI の場合は以下のようにする.
vm$ wget http://i.riken.jp/wp-content/uploads/2015/07/cc_himenobmtxp_mpi.zip vm$ unzip cc_himenobmtxp_mpi.zip vm$ lha -x cc_himenobmtxp_mpi.lzh vm$ sh paramset.sh M 1 1 2 vm$ mpicc himenoBMTxps.c vm$ mpiexec -n 2 ./a.out ...(中略)... messages cpu : 59.403678 sec. Loop executed for 2468 times Gosa : 4.015469e-04 MFLOPS measured : 5696.204169 Score based on Pentium III 600MHz : 68.761518
より詳しく知りたい場合には
日本代理店の公式 Web ページを参照すること.
Intel コンパイラのインストール
科学技術並びにエンジニアリング分野においてよく利用される C/C++ & Fortran コンパイラである Intel コンパイラ を用いる. PGI コンパイラにはいくつかのエディションがあるが, Student 向けのエディションが存在するので, まずはそれを使ってみると良い. 利用には制約がかけられているので, それをよく理解してから使うこと.
Intel のページ からユーザ登録するとダウンロードすることができる. 残念ながら教員は学生用は使えないので, ダウンロードから先は試すことができない. <URL:https://qiita.com/minwinmin/items/afbb0404533fd4b07e72> などを参考に作業をしてもらいたい.







