Problem: MacOS 10.9 exclusively uses clang for compiling C or C++ source code. Even if you type "g++" or "gcc" you get clang. Clang supports Open MPI but does not support OpenMP.
One solution: Install GCC and Open MPI, redirect "mpic++" wrapper compiler from Open MPI to use g++ instead of clang.
Steps:
1. brew install open-mpi
MPI code should now compile fine using mpic++, but OpenMP library will not be found by clang, raising the error: "fatal error: 'omp.h' file not found".
2. brew install homebrew/versions/gcc49
Install gcc. After you do this, typing "g++ --version" will still give you information about clang, not g++. The symlink remains. This means that, if you type "mpic++" to compile, the wrapper compiler will still activate clang, and the "'omp.h' file not found" error will still occur.
3. open /usr/local/Cellar/open-mpi/1.7.4/share/openmpi/mpic++-wrapper-data.txt
Modify file "mpic++-wrapper-data.txt" to redirect MPI wrapper compiler to use g++ instead of clang++ (exact location above depends on the version you get from brew).
The default setting is "compiler=clang++". Change this line to "compiler=g++-4.9". It is somewhat handy that when you install gcc using brew, the file name has the version appended, "-4.9" for example. This way you don't have to break Mavericks symlinks between gcc, g++ and clang.
4. Open new terminal window. Compiling with "mpic++" should now work.
No comments:
Post a Comment