Im currently using the latest version of XCode
i.e. 4.6
and have troubles enabling OpenMP. I dont see any such option as "Enable OpenMP Support
" in the build settings. I'm using Apple LLVM Compiler 4.2
and libc++ LLVM C++
standard library with C++11 support. Any help would be appreciated..

- 16,337
- 15
- 66
- 97
-
1I'm not sure that the situation has changed since this Q&A: http://stackoverflow.com/questions/13720234/xcode-4-5-and-openmp-with-clang-apple-llvm-uses-only-one-core – High Performance Mark Feb 15 '13 at 15:46
-
That means if the situation hasnt changed, I wont be able to use OpenMP? – Abhishek Thakur Feb 15 '13 at 16:21
-
That's right, not with the Apple supplied LLVM compiler. Other compilers are available and some of them do support OpenMP on Mac OS X. – High Performance Mark Feb 15 '13 at 16:29
-
GCC 4.7.x builds without problems on OS X 10.8 and it supports OpenMP 3.1 as well as many C++11 features. I have compiled GCC 4.7.1 on my OS X 10.8 and it works like charm. – Hristo Iliev Feb 15 '13 at 19:59
-
@HristoIliev so will i be able to use it with XCode4.6 then? – Abhishek Thakur Feb 15 '13 at 21:27
-
As far as I know one can add compiler profiles to XCode, but honestly, I have no idea how it is done. – Hristo Iliev Feb 15 '13 at 21:35
2 Answers
In the Build Settings, I changed "Compilers for C/C++/Objective-C" to "LLVM GCC 4.2"
Then, under the "LLVM GCC 4.2 - Language" settings you will have the option to enable OpenMP. I have not yet tested compiling real code, but at least "#include " now works.

- 56
- 3
-
Update: I'm getting the SIGABRT error discussed here: [link](https://discussions.apple.com/thread/3786045). They claim that it is a bug with LLVM GCC 4.2, but it is also possible that I am corrupting memory somehow. – Bo Brinkman Mar 17 '13 at 00:39
-
1I tried building my code using g++-mp-4.7 from the command line, and I no longer have the SIGABRT issues. While I'm still not 100% certain my code is correct, it seems to add weight to the idea that OpenMP is not going to work in XCode, at least for now. LLVM GCC 4.2 will let you compile it, but you will get frequent crashes. – Bo Brinkman Mar 18 '13 at 01:18
The earlier user has said everything right but he missed one thing and that is the reason he could not include "omp.h" you have to mention the path of the library in the "library search path" option. Otherwise the compiler cannot locate it automatically. So the steps are following :
- In the Build Settings, I changed "Compilers for C/C++/Objective-C" to "LLVM GCC 4.2"
- Then, under the "LLVM GCC 4.2 - Language" settings you will have the option to enable OpenMP.
- In "Headers Search Paths", add the location of "omp.h" file.
- Now you are done
copy the following code and enjoy:
int main(int argc, char **argv) {
omp_set_num_threads(8);
int iter;
int NCOUNT = 100000000;
#pragma omp parallel for
for(iter = 0; iter < NCOUNT; iter++)
{
printf("OMP: Hello World, %d times\n", iter);
}
return 0;
}
N.B: For my MAC computer, I found the "omp.h" file in "/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include", may be it would be different for your case but I am sure that it has to be in "/usr/.." so just use "find" operation to locate the particular file. PLease note that "/usr" is a hidden folder in your MAC system so you have to activate your system to show up hidden files and folders.

- 449
- 1
- 6
- 12