2013年12月17日火曜日

Mac(OSX10.9)でOpenMPを使う

モンテカルロシミュレーションの並列処理の勉強をしたかったので少し勉強しました。
Xcodeデフォルトのgcc(clang?)ではomp.hが見つからず、コンパイルできませんでした。
#include 
#include 
int main(void)
{
#pragma omp parallel
  {
    printf("hello world from %d of %d\n",
    omp_get_thread_num(), omp_get_num_threads());
  }
  return 0;
}
gccはこんな感じです。
admin $ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

Google先生がなかなか答えを教えてくれなかったので、あきらめてgcc4.9をインストール。

admin $ brew install gcc49

これでコンパイルできるようになりました。

admin $ /usr/local/bin/gcc-4.9 -fopenmp hello.c
admin $ ./a.out 
hello world from 1 of 4
hello world from 3 of 4
hello world from 0 of 4
hello world from 2 of 4
4コアです。

0 件のコメント:

コメントを投稿