简体   繁体   English

如何在我的新 MacBook Pro(使用 Mac OS Catalina)上安装 openMP?

[英]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 安装了llvmgcc ,你也应该在你的终端 Z212E5440CFBE515024E 中尝试gcc -vclang -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

GNU gcc (currently at version 9) GNU gcc(当前版本 9)

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

LLVM LLVM

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:然后,在编译时:

  • use -Xpreprocessor -fopenmp in place of -fopenmp in the compile step ( -c option)在编译步骤中使用-Xpreprocessor -fopenmp代替-fopenmp-c选项)
  • add -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.

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