简体   繁体   English

Apple Silicon M1 Pro 上的 MPI 和 OpenMP

[英]MPI and OpenMP on Apple Silicon M1 Pro

So, someone has to initiate such a question regarding apple silicon.所以,有人不得不提出这样一个关于苹果硅的问题。 Long story short, I need to compile and run a C++ code that runs hybrid with both MPI and OpenMP on a MBP M1 pro (which uses arm-based architecture).长话短说,我需要编译和运行C++代码,该代码在 MBP M1 pro(使用基于 arm 的架构)上与 MPI 和 OpenMP 混合运行。 The code runs perfectly fine on a typical Intel x86 architecture.该代码在典型的英特尔 x86 架构上运行良好。 Also, for completion sake, the Mac OS is Monterey.另外,为了完整起见,Mac OS 是 Monterey。 Additionally, I do not compile/run via an IDE (eg XCode), I do so via a Makefile, directly from the terminal.此外,我不通过 IDE(例如 XCode)编译/运行,而是通过 Makefile 直接从终端编译/运行。

I haven't found a clear answer to such a question.对于这样的问题,我还没有找到明确的答案。 I tried setting things up myself, but this is way above my comfort zone.我尝试自己进行设置,但这远远超出了我的舒适区。 Moreover, I trust answering such a question would help future developers that are using these Macs for work:)此外,我相信回答这样的问题将有助于未来使用这些 Mac 工作的开发人员:)

So far, I understood that the installed Clang compiler that comes with Xcode does not support OpenMP ( -fopenmp ) or recognizes MPI ( mpirun ).到目前为止,我了解到 Xcode 附带的安装的 Clang 编译器不支持 OpenMP ( -fopenmp ) 或识别 MPI ( mpirun )。 So, I installed "brew" and the " llvm " version which should support the multi-threading instructions via OpenMP.所以,我安装了“brew”和“ llvm ”版本,它们应该通过 OpenMP 支持多线程指令。 As for the MPI library, I installed the " libomp " library through " brew ".至于 MPI 库,我通过“ brew ”安装了“ libomp ”库。 These all should run natively on Apple Silicon.这些都应该在 Apple Silicon 上本地运行。

However, now the environment is all over the place, since the system has 2 Clang compilers:但是,现在环境到处都是,因为系统有 2 个 Clang 编译器:

  • one preinstalled with Xcode (the default)一个预装了 Xcode(默认)
  • one installed via brew, situated in: /opt/homebrew/opt/llvm一个通过 brew 安装,位于: /opt/homebrew/opt/llvm

I do not know how to proceed.我不知道该怎么做。 The simple solution might be to change the path of the compiler to that in the /opt/homebrew/ directory, however I suspect that might mess a lot of things in the system.简单的解决方案可能是将编译器的路径更改为/opt/homebrew/目录中的路径,但是我怀疑这可能会弄乱系统中的很多东西。

I would (and many others) be very thankful if you could help, in case someone has prior experience with something like this before.如果您能提供帮助,我将(和许多其他人)非常感谢,以防有人以前有过类似的经验。

To use Homebrew's Clang you will need set up your PATH and compiler flags accordingly.要使用 Homebrew 的 Clang,您需要相应地设置 PATH 和编译器标志。

Actually, Homebrew gives you the respective advice and hints already once you install llvm (or try brew info llvm ):实际上,一旦您安装了 llvm(或尝试brew info llvm ),Homebrew 已经为您提供了相应的建议和提示:

To use the bundled libc++ please add the following LDFLAGS:
  LDFLAGS="-L/opt/homebrew/opt/llvm/lib -Wl,-rpath,/opt/homebrew/opt/llvm/lib"

llvm is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have llvm first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc

For compilers to find llvm you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"

You will need to forward those flags into your build setup, ie, if you have build files from CMake/Make/whatsoever you will need to make sure that the respective flags are used or forwarded.您需要将这些标志转发到您的构建设置中,即,如果您有来自 CMake/Make/whatever 的构建文件,您将需要确保使用或转发相应的标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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