GROMACS is an optimised molecular dynamics code, primarily used for simulating the behaviour of proteins. To compile GROMACS you need, well, some compilers. I install gcc using MacPorts. Note that this requires you to first install Xcode. Then it is easy to install gcc
version 4.9 by
sudo port install gcc49
(and yes, I know about Homebrew, but I still find MacPorts has more of the things I want than brew). So, once you’ve done a bit of preparation, compiling vanilla GROMACS from source on a Mac is easy. Once you’ve downloaded the source code tar ball.
tar xvf gromacs-5.0.2.tar.gz
cd gromacs-5.0.2
mkdir build
cmake .. -DGMX_BUILD_OWN_FFTW=ON -DCMAKE_INSTALL_PREFIX='/usr/local/gromacs/5.0.2/‘
make
sudo make install
Note that this will install it in /usr/local/gromacs/5.0.2
so you can keep multiple versions on the same machine and swap between them in a sane way by sourcing the GMRXC
file, for example
source /usr/local/gromacs/4.6.7/bin/GMXRC
Adding MPI support on a Mac is trickier. This appears mainly to be because the gcc
compilers from MacPorts (or clang from Xcode) don’t appear to support OpenMPI. You will know because when you run the cmake
command you get a load of failures starting about ten lines down, such as
-- Performing Test OpenMP_FLAG_DETECTED - Failure
I managed to get a working version using the following approach; it is likely there are better (if you know, please leave a comment), but it has the virtue of working. First we need to install OpenMPI.
sudo port install openmpi
Now we need a compiler that supports OpenMPI. If you dig around in the MacPorts tree you can find some.
sudo port install openmpi-devel-gcc49
Finally, we can follow the steps above (I just mkdir build-mpi
subfolder in the above source folder and then cd
to it), but now we need a (slightly) complex cmake instruction
cmake .. -DGMX_BUILD_OWN_FFTW=ON
-DGMX_BUILD_MDRUN_ONLY=on
-DCMAKE_INSTALL_PREFIX=/usr/local/gromacs/5.0.2
-DGMX_MPI=ON -DCMAKE_C_COMPILER=mpicc-openmpi-devel-gcc49
-DCMAKE_CXX_COMPILER=mpicxx-openmpi-devel-gcc49
-DGMX_SIMD=SSE4.1
This is only going to build an MPI version of mdrun
(which makes sense) and will install mdrun_mpi
alongside the regular compiled binaries we did first. We have to tell cmake what all the new fancy compilers are called and, unfortunately, these don’t support AVX SIMD instructions so we have to fall back to SSE4.1. Experience suggests this doesn’t impact performance as much as you might think. Now you can run things like Hamiltonian replica exchange on your workstation!
4 replies on “Installing GROMACS with MPI support on a Mac”
Hi Philip!
Thanks for your help!
I was trying to install GMX on Mac OS X 10.10.5 and found your website by google. However, it worked until cmake, because although I installed gcc49, it did not find cmake. And then I found a shortcut – so I did not invest much time looking into the problem!
Actually, MacPorts provides GMX 5.1.2 – and this was exactly the version I wanted to install! Of course, it will not support MPI, but I think it is enough for my purposes on Mac Book Pro 2015 (without extra graphics).
Cheers,
Bjorn
Hi Philip!
Thanks for your help!
I was trying to install GMX on Mac OS X 10.10.5 and found your website by google. However, it worked until cmake, because although I installed gcc49, it did not find cmake. And then I found a shortcut – so I did not invest much time looking into the problem!
Actually, MacPorts provides GMX 5.1.2 – and this was exactly the version I wanted to install! Of course, it will not support MPI, but I think it is enough for my purposes on Mac Book Pro 2015 (without extra graphics).
Cheers,
Bjorn
I used for non-mpi:
cmake .. -DGMX_BUILD_OWN_FFTW=ON -DREGRESSIONTEST_DOWNLOAD=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DGMX_GPU=off -DCMAKE_PREFIX_PATH=/opt/local -DGMX_SIMD=SSE4.1
reason I forced the gcc and g++ compiler was that on OSX the cmake would find the clang compiler even though gcc and g++ for GNU were set using mac ports.
in addition, install FTTW-3, HWLOC, etc.. from Mac ports.