I’ve been taking the course Parallel Computing this semester, and I’m also participating in some student cluster competitions. Therefore, I wanted to configure OpenMP and MPI on my Mac to run some OpenMP and MPI programs. This post describes how I successfully configured OpenMP and MPI with Homebrew.
Make sure you have Homebrew installed on your Mac. Homebrew is a package manager for macOS. It is in some way similar to package managers in Linux distributions, such as
yum. It’s very easy to install, just go to their website and follow the steps.
Remember to run
brew update before you continue.
One thing you should know is that OpenMP is not really a package that you install on your computer. Instead, it’s part of the compiler. Therefore, what we need to do is to compile a compiler with OpenMP support. We’ll use Homebrew to build the GNU Compiler Collection (GCC) on our Mac from source, with OpenMP support. To do that, type in the following command
$ brew install gcc --without-multilib
If you have installed
gcc before on your Mac using Homebrew, then reinstall it with the following command
$ brew reinstall gcc --without-multilib
According to my experience, it takes about half an hour to one hour to build
gcc since it’s quite a large piece of program. Just be patient. After you installed it, you should be able to compile programs with OpenMP support with
MPI is only an interface. Therefore, there are several MPI implementations, such as MPICH, OpenMPI, and Intel MPI. In this post, we’ll install OpenMPI. Here we also want to build it from source because then our MPI compiler is using the
gcc we built just now with OpenMP support. If you installed the binary distribution, it’s compiled with
clang without any OpenMP support. To build OpenMPI, type in the following command
$ brew install openmpi --build-from-source --cc=gcc-6
This command forces Homebrew to build OpenMPI from source with the
gcc-6 compiler. (On Mac, the brewed
gcc has the name
gcc-6 to avoid name clash with the system link
gcc that is in your Mac)
Now you should have OpenMPI installed on your Mac, with OpenMP support! To compile any MPI programs, just type
$ mpicc <your <span class="hljs-built_in">source</span> code>