简体   繁体   English

在XCode 4.6中启用OpenMP支持

[英]Enable OpenMP Support in XCode 4.6

Im currently using the latest version of XCode ie 4.6 and have troubles enabling OpenMP. 我目前正在使用最新版本的XCode4.6并且在启用OpenMP时遇到了麻烦。 I dont see any such option as " Enable OpenMP Support " in the build settings. 我在构建设置中没有看到任何诸如“ Enable OpenMP Support ”这样的选项。 I'm using Apple LLVM Compiler 4.2 and libc++ LLVM C++ standard library with C++11 support. 我正在使用具有C ++ 11支持的Apple LLVM Compiler 4.2libc++ LLVM C++标准库。 Any help would be appreciated.. 任何帮助,将不胜感激..

In the Build Settings, I changed "Compilers for C/C++/Objective-C" to "LLVM GCC 4.2" 在“构建设置”中,我将“ C / C ++ / Objective-C编译器”更改为“ LLVM GCC 4.2”

Then, under the "LLVM GCC 4.2 - Language" settings you will have the option to enable OpenMP. 然后,在“ LLVM GCC 4.2-语言”设置下,您可以选择启用OpenMP。 I have not yet tested compiling real code, but at least "#include " now works. 我尚未测试过编译实际代码,但至少现在可以使用“ #include”了。

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. 较早的用户说的没事,但是他错过了一件事,这就是为什么他不能包含“ omp.h”的原因,因此您必须在“库搜索路径”选项中提及库的路径。 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" 在“构建设置”中,我将“ C / C ++ / Objective-C编译器”更改为“ LLVM GCC 4.2”
  2. Then, under the "LLVM GCC 4.2 - Language" settings you will have the option to enable OpenMP. 然后,在“ LLVM GCC 4.2-语言”设置下,您可以选择启用OpenMP。
  3. In "Headers Search Paths", add the location of "omp.h" file. 在“标题搜索路径”中,添加“ omp.h”文件的位置。
  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;
}

NB: 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. 注意:对于我的MAC计算机,我在“ /usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include”中找到了“ omp.h”文件,可能有所不同对于您的情况,但我确定它必须位于“ / usr / ..”中,因此只需使用“ find”操作来查找特定文件。 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. 请注意,“ / usr”是MAC系统中的隐藏文件夹,因此您必须激活系统才能显示隐藏文件和文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM