'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). The code runs perfectly fine on a typical Intel x86 architecture. Also, for completion sake, the Mac OS is Monterey. Additionally, I do not compile/run via an IDE (e.g. XCode), I do so via a Makefile, directly from the terminal.

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 :)

So far, I understood that the installed Clang compiler that comes with Xcode does not support OpenMP (-fopenmp) or recognizes MPI (mpirun). So, I installed "brew" and the "llvm" version which should support the multi-threading instructions via OpenMP. As for the MPI library, I installed the "libomp" library through "brew". These all should run natively on Apple Silicon.

However, now the environment is all over the place, since the system has 2 Clang compilers:

  • one preinstalled with Xcode (the default)
  • one installed via brew, situated in: /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.

I would (and many others) be very thankful if you could help, in case someone has prior experience with something like this before.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source