並列計算:OpenMP

並列計算を行う必要がありそうなので、OpenMPを勉強することにした。自分に必要なリンクなどをまとめる。

 

[1]教材

C言語によるOpenMP入門(当面はこれ)

http://www.cc.u-tokyo.ac.jp/support/press/news/VOL9/special/9.pdf

Vol.9 特集号(2008年2月) [東京大学情報基盤センタースーパーコンピューティング部門]

・2013年度 計算科学技術特論A 第3回 OpenMPの基礎

http://www.cms-initiative.jp/ja/events/20130425katagiri.pdf

・筑波大の資料。

http://www.hpcs.cs.tsukuba.ac.jp/~taisuke/EXPERIMENT/openmp-txt.pdf

・神戸大の資料。fortran

http://exp.cs.kobe-u.ac.jp/wiki/comp_practice/index.php?plugin=attach&refer=4.OpenMP%A4%F2%CD%D1%A4%A4%A4%BF%CA%C2%CE%F3%B7%D7%BB%BB&openfile=openmp1_yaguchi_2012.pdf

 

 

[2] Macbook Air (OSX 10.7.5) の gcc を切り替える

Macports で gcc 4.7 (GNUコンパイラ) を入手する。

# これなら OpenMP の threadprivate が使えるらしい。

# http://openmp.org/forum/viewtopic.php?f=3&t=698#p2784

 

$ gcc -version
i686-apple-darwin11-llvm-gcc-4.2: no input files

$ gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)


(1) Macports のupdate

$ sudo port selfupdate
$ sudo port sync

(2) 入手可能なgccのリストアップ

$ port search gcc

...

gcc46 @4.6.4_7 (lang)
The GNU compiler collection

gcc47 @4.7.4_3 (lang)
The GNU compiler collection

gcc48 @4.8.3_4 (lang)
The GNU compiler collection

gcc49 @4.9.2_1 (lang)
The GNU compiler collection
...

といろいろ出てくる。

$ port select --list gcc
Warning: Unable to get active selected version: The specified group 'gcc' does not exist.
Error: The 'list' command failed: The specified group 'gcc' does not exist.

↑他のサイトを参考に打ち込んでみたが、なんか怒られた。以下には影響しない。

(3) 新しいgccのインストール

$ sudo port install gcc47

ここまでではgccは切り替わっていない。

$ gcc -version
i686-apple-darwin11-llvm-gcc-4.2: no input files

$ gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)


(4) 新しい gcc への切り替え

まずは、gccのどれが入っているか調べる。

$ sudo port select --list gcc
Password:
Available versions for gcc:
gcc42
llvm-gcc42
mp-gcc47
none (active)

mp-gcc47をgccとして選ぶ。

$ sudo port select gcc mp-gcc47
Selecting 'mp-gcc47' for 'gcc' succeeded. 'mp-gcc47' is now active.

以下のように怒られ、一瞬焦る。

$ gcc -v
gcc-mp-4.7: error trying to exec '/opt/local/bin/i686-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory

$ gcc -version
gcc-mp-4.7: error trying to exec '/opt/local/bin/i686-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory

新たなterminal window を開くと、解決する:

$ gcc -version
gcc: error: unrecognized command line option '-version'
gcc: fatal error: no input files
compilation terminated.

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin11/4.7.4/lto-wrapper
Target: x86_64-apple-darwin11
Configured with: /opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/gcc-4.7.4/configure --prefix=/opt/local --build=x86_64-apple-darwin11 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc47 --includedir=/opt/local/include/gcc47 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.7 --with-libiconv-prefix=/opt/local --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.7 --with-gxx-include-dir=/opt/local/include/gcc47/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --disable-ppl-version-check --with-pkgversion='MacPorts gcc47 4.7.4_3'
Thread model: posix
gcc version 4.7.4 (MacPorts gcc47 4.7.4_3)

なお、新たに入れたgccだと、「-version」は使えないようである:

$ gcc -version
gcc: error: unrecognized command line option '-version'
gcc: fatal error: no input files
compilation terminated.

 

 参考

MacPortsでgcc 4.7を。 - udon's blog

mac port で gcc4.8を入れたった - Bye Bye Moore

MacPortsを使ったgfortranインストール方法 : てふこの部屋

OpenMP® Forum • Information