[英]How can I install openMP on my new MacBook Pro (with Mac OS Catalina)?
I installed Xcode (and also the command line tools) but terminal says (when I'm compiling):我安装了 Xcode (以及命令行工具)但终端说(当我编译时):
gcc -o task -fopenmp task.c
clang: error: unsupported option '-fopenmp'
I tried to install openmp via brew but people say that it's not available anymore on homebrew, they suggest to try我试图通过 brew 安装 openmp 但人们说它不再在 homebrew 上可用,他们建议尝试
brew instal llvm
But I get the same error.但我得到同样的错误。 I tried also in the boneyard
我也在墓地里试过
brew install homebrew/boneyard/clang-omp
but the repository doesn't exist anymore.但存储库不再存在。
Could you help me?你可以帮帮我吗? I just need to learn openMP, I don't think that is so difficult to install...
我只需要学习openMP,我不认为安装有那么难......
Thank you!谢谢!
Kind regards,亲切的问候,
Nico尼科
To build with OpenMP support, you need to make sure you're not invoking Apple's clang from Xcode.要使用 OpenMP 支持进行构建,您需要确保没有从 Xcode 调用 Apple 的 clang。 Even if you install
llvm
or gcc
via brew, you should try gcc -v
and clang -v
in your terminal session.即使你通过 brew 安装了
llvm
或gcc
,你也应该在你的终端 Z212E5440CFBE515024E 中尝试gcc -v
和clang -v
。 Both likely invoke Apple's version.两者都可能调用苹果的版本。
You can use GNU gcc or LLVM;您可以使用 GNU gcc 或 LLVM; both are available via brew.
两者都可以通过 brew 获得。 If you use LLVM, you'll also need to install
libomp
.如果你使用 LLVM,你还需要安装
libomp
。
brew install gcc
gcc-9 -o task -fopenmp task.c
Note that you invoke this version of gcc explicitly by suffixing gcc
with a -
and the major version number, eg: gcc-9
请注意,您可以通过在
gcc
后面加上-
和主要版本号来显式调用此版本的 gcc,例如: gcc-9
Brew installs LLVM as keg-only so that it doesn't conflict with Apple's version. Brew 将 LLVM 安装为仅桶装,这样它就不会与 Apple 的版本冲突。 You'll therefore need to make sure you invoke the right
clang
.因此,您需要确保调用正确的
clang
。 You'll also need to specify where the libomp
library is located.您还需要指定
libomp
库的位置。
brew install llvm libomp
`brew --prefix llvm`/bin/clang -L`brew --prefix`/lib -o task -fopenmp task.c
This https://iscinumpy.gitlab.io/post/omp-on-high-sierra/ suggest to do the following:此https://iscinumpy.gitlab.io/post/omp-on-high-sierra/建议执行以下操作:
brew install libomp
To install the OpenMP runtime components/libraries.安装 OpenMP 运行时组件/库。
Then, when compiling:然后,在编译时:
-Xpreprocessor -fopenmp
in place of -fopenmp
in the compile step ( -c
option)-Xpreprocessor -fopenmp
代替-fopenmp
( -c
选项)-lomp
to the linking step-lomp
添加到链接步骤Note that the above page also mention that CMake 3.12 or later will automatically find the right way of adding OpenMP on MacOS:注意上面的页面还提到了 CMake 3.12 或更高版本会自动找到在 MacOS 上添加 OpenMP 的正确方法:
cmake_minimum_required(VERSION 3.12)
project(openmptest CXX)
add_executable(sample sample.cpp)
find_package(OpenMP REQUIRED)
target_link_libraries(sample PRIVATE OpenMP::OpenMP_CXX)
Note: I didn't test any of this but it sounds relatively sane注意:我没有对此进行任何测试,但听起来相对健全
brew install gcc
then type gcc
in your terminal and hit the tab button twice.然后在您的终端中键入
gcc
并按两次选项卡按钮。
you should see multiple gcc versions eg gcc
gcc-10
您应该看到多个 gcc 版本,例如
gcc
gcc-10
then find out which one is from Homebrew eg type gcc-10 --version
in the terminal should output something like this:然后找出哪个来自 Homebrew,例如在终端中键入
gcc-10 --version
应该 output 是这样的:
gcc-10 (Homebrew GCC 10.2.0_3) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Finally use that compiler to compile your eg:最后使用该编译器来编译你的例如:
gcc-10 -o task -fopenmp task.c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.