我在我的macos中安装了 OpenMP 和 xcode-select 。
$ clang-omp --version
clang version 3.5.0
Target: x86_64-apple-darwin15.4.0
Thread model: posix
$ xcode-select --version
xcode-select version 2343.
运行以下非常简单的代码
1 #include <omp.h>
2 #include <stdio.h>
3
4 #define n 20
5
6 int main(){
7
8 int i;
9 int tid;
10
11 omp_set_num_threads(3);
12 #pragma omp parallel for private(tid) schedule(static,1)
13
14 for (i=0; i<n; i++) {
15 tid = omp_get_thread_num();
16 printf("Thread %d executing iteration %d\n", tid, i);
17 }
18 }
我收到错误
$ clang-omp -openmp parallel.c -v
clang version 3.5.0
Target: x86_64-apple-darwin15.4.0
Thread model: posix
"/usr/local/Cellar/clang-omp/2015-04-01/libexec/bin/clang-3.5" -cc1 -triple x86_64-apple-macosx10.11.0 -emit-obj -mrelax-all -disable-free -main-file-name parallel.c -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -v -dwarf-column-info -resource-dir /usr/local/Cellar/clang-omp/2015-04-01/libexec/bin/../lib/clang/3.5.0 -fdebug-compilation-dir /Users/prayagupd/prayag.data/workspace.programming/parallel-programming/openMP -ferror-limit 19 -fmessage-length 178 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/63/jvvb4wy16gx6w76mkgsvn52m0000gn/T/parallel-32b98e.o -x c parallel.c
clang -cc1 version 3.5.0 based upon LLVM 3.5.0svn default target x86_64-apple-darwin15.4.0
ignoring nonexistent directory "/usr/local/Cellar/clang-omp/2015-04-01/libexec/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/local/Cellar/clang-omp/2015-04-01/libexec/bin/../lib/clang/3.5.0/include
/usr/local/opt/libiomp/include/libiomp
/usr/local/Cellar/clang-omp/2015-04-01/libexec/include/c++/v1
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o penmp /var/folders/63/jvvb4wy16gx6w76mkgsvn52m0000gn/T/parallel-32b98e.o -lSystem
Undefined symbols for architecture x86_64:
"_omp_get_thread_num", referenced from:
_main in parallel-32b98e.o
"_omp_set_num_threads", referenced from:
_main in parallel-32b98e.o
ld: symbol(s) not found for architecture x86_64
clang-3.5: error: linker command failed with exit code 1 (use -v to see invocation)
gcc
甚至找不到omp.h
。
$ gcc parallel.c -fopenmp -o parallel
parallel.c:1:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
1 error generated.
gcc版本是
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
答案 0 :(得分:0)
对于您的GroupSidebar
问题,您是否导出了库路径?翼
clang-omp
也许您没有从英特尔安装OpenMP库?现代clang(&gt; 3.7),不是与OS X一起打包的,现在支持开箱即用的OpenMP。
对于您的export DYLD_LIBRARY_PATH=(OMPLIB PATH):$DYLD_LIBRARY_PATH
问题,OS X实际上并没有提供gcc,它只是将其链接到vanilla clang。所以你试图用一个不支持OpenMP的编译器来编译它。如果你想要gcc,那么通过ports或homebrew安装它。