在Mac OS上使用OpenMP与C ++ 11 [英] Using OpenMP with C++11 on Mac OS
问题描述
我想在我的C ++ 11代码中使用一些OpenMP多线程功能,如:
I am trying to use some OpenMP multithreading features in my C++11 code like:
#pragma omp parallel for
当我尝试编译时:
clang++ -std=c++11 -stdlib=libc++ -fopenmp main.cpp -o main.o
我得到以下错误:
clang: error: unsupported option '-fopenmp'
我另外尝试使用以下命令编译:
I alternatively tried compiling using:
g++ -fopenmp main.cpp -o main.o
但是这给出了完全相同的错误。
But this gives the exact same error.
非常感谢,如果你可以建议如何编译在Mac OS 10.12具有OpenMP功能的C ++ 11代码。其他问题在这里和其他地方的解释编译C代码的OpenMP,但是,我找不到任何C ++ 11。
Would appreciate very much if you could advise how can I compile C++11 code that has OpenMP features on Mac OS 10.12. The other questions on posts here and elsewhere explain compiling C code for OpenMP, however, I couldn't find anything for C++11.
我得到一个错误,当我尝试安装libiomp,我会收到错误:
I get an error when I try to install libiomp, I get errors:
$ brew install libiomp
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
ansible-cmdb djview4 khard oysttyer shyaml yazpp
asciinema2gif doctl macvim pazpar2 vala you-get
avro-c elixir mailhog python vdirsyncer youtube-dl
bash-git-prompt file-roller meson python3 vim
commandbox glib metaproxy rtv x265
consul-backinator gtkextra offlineimap s-search xonsh
Error: Could not link:
/usr/local/share/doc/homebrew
Please delete these paths and run `brew update`.
Error: Could not link:
/usr/local/share/man/man1/brew.1
Please delete these paths and run `brew update`.
Error: No available formula with the name "libiomp"
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
Error: No formulae found in taps.
如果我使用g ++ -6运行,基于Mark Setchell的下面的文章,然而,我得到以下警告,将感谢任何建议如何避免这些:
If I run using g++-6, based on Mark Setchell's post below, it works fine, thanks, I however get the below warnings, would appreciate any suggestions on how to avoid these:
$ /usr/local/bin/g++-6 -std=c++11 -fopenmp main.cpp -o main.o
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:4:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:4:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:89:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:89:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:551:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:551:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:1432:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:1432:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:1799:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:1799:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:1995:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:1995:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2033:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2033:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2425:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2425:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2559:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2559:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2597:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2597:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2672:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2672:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2837:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2837:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2962:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:2962:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:3139:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:3139:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:3442:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:3442:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:3588:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:3588:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:3630:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:3630:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:5253:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:5253:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:5452:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/jr/30r6h4cj4tl48q_cg9bt5f5h0000gn/T//ccq73Zfg.s:5452:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
推荐答案
如果你想在OSX上编译C ++ 11 OpenMP代码,最简单的方法是使用 gcc
您可以通过
homebrew
安装。
If you want to compile C++11 OpenMP code on OSX, the easiest way is to use gcc
which you can install via homebrew
.
首先,检查可用的选项:
First, check the available options:
brew options gcc
示例输出
--with-all-languages
Enable all compilers and languages, except Ada
--with-java
Build the gcj compiler
--with-jit
Build the jit compiler
--with-nls
Build with native language support (localization)
--without-fortran
Build without the gfortran compiler
--without-multilib
Build without multilib support
--HEAD
Install HEAD version
所以,我怀疑你想要:
brew install gcc --without-multilib --without-fortran
一旦你安装了它,你需要确保你使用 homebrew
版本,而不是一个苹果供应。你需要知道 homebrew
安装 / usr / local / bin
中的一切,C ++编译器 g ++ - 6
。所以,你需要编译:
Once you have got it installed, you need to make sure you are using the homebrew
version rather than the one Apple supplies. You need to know that homebrew
installs everything in /usr/local/bin
and that the C++ compiler is g++-6
. So, you either need to compile with:
/usr/local/bin/g++-6 -std=c++11 -fopenmp main.cpp -o main
或者,在登录配置文件中设置PATH: p>
or, set up your PATH in your login profile:
export PATH=/usr/local/bin:$PATH
那么你可以这样做:
g++-6 -std=c++11 -fopenmp ...
注意,如果选择上面的第二个选项code> export PATH = ... 选项),您还需要在当前会话中键入 export
命令一次激活它或注销并重新登录,因为您的配置文件命令只在登录时执行。
Note that if you choose the second option above (i.e. the export PATH=...
option), you will either need to also type the export
command in your current session once to activate it, or log out and log back in since your profile commands are only executed on login.
AFAIK,没有必要显式安装 libiomp
- 不知道为什么你这样做。
AFAIK, there is no need to explicitly install libiomp
- not sure why you did that.
这篇关于在Mac OS上使用OpenMP与C ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!