在 XCode 4.6 中启用 OpenMP 支持
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14898003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Enable OpenMP Support in XCode 4.6
提问by Abhishek Thakur
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..
我目前使用的是最新版本的XCode
ie,4.6
并且在启用 OpenMP 时遇到了麻烦。我Enable OpenMP Support
在构建设置中没有看到任何诸如“ ”之类的选项。我使用Apple LLVM Compiler 4.2
和libc++ LLVM C++
用C ++ 11的支持标准库。任何帮助,将不胜感激..
回答by Bo Brinkman
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. I have not yet tested compiling real code, but at least "#include " now works.
然后,在“LLVM GCC 4.2 - 语言”设置下,您将可以选择启用 OpenMP。我还没有测试编译真正的代码,但至少“#include”现在可以工作了。
回答by Spandan
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 :
较早的用户说得对,但他错过了一件事,这就是他不能包含“omp.h”的原因,您必须在“图书馆搜索路径”选项中提及图书馆的路径。否则编译器无法自动定位它。所以步骤如下:
- 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
- 在构建设置中,我将“C/C++/Objective-C 编译器”更改为“LLVM GCC 4.2”
- 然后,在“LLVM GCC 4.2 - 语言”设置下,您将可以选择启用 OpenMP。
- 在“Headers Search Paths”中,添加“omp.h”文件的位置。
- 现在你完成了
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.
注意:对于我的 MAC 计算机,我在“/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include”中找到了“omp.h”文件,可能会有所不同对于您的情况,但我确定它必须在“/usr/..”中,因此只需使用“查找”操作来定位特定文件。请注意,“/usr”是您 MAC 系统中的隐藏文件夹,因此您必须激活系统才能显示隐藏文件和文件夹。