2

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..

Abhishek Thakur
  • 16,337
  • 15
  • 66
  • 97

2 Answers2

4

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.

  • 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
  • 1
    I 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
1

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 :

  1. In the Build Settings, I changed "Compilers for C/C++/Objective-C" to "LLVM GCC 4.2"
  2. Then, under the "LLVM GCC 4.2 - Language" settings you will have the option to enable OpenMP.
  3. In "Headers Search Paths", add the location of "omp.h" file.
  4. 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.

Tanmoy Mondal
  • 449
  • 1
  • 6
  • 12