Add Homebrew-based installation instructions for macOS
Is your feature request related to a problem? Please describe. We currently have instructions for installing the prerequisites using macports, but many people use homebrew instead.
Describe the solution you'd like Add installation instructions for the prerequisites using homebrew.
Got this working last week, so I'll write these up soon. May need testing from a clean installation.
Key is to set HOMEBREW_CC, HOMEBREW_CXX and HOMEBREW_FC to the desired values before installing openmpi/mpich.
For me, the following has worked (as feedback and check on this item):
brew install gcc
brew install hdf5
brew install netcdf
brew install cmake
(Installing gcc also installs g++, gfortran, gmp and mpfr.)
Building Homebrew-MPICH from source, with the --cc flag to tell Homebrew which C compiler to pick up (this does not require HOMEBREW_* variables):
brew install mpich --build-from-source --cc=gcc-8
(gcc-8 or the gcc version variant Homebrew installed for you.)
To verify:
$ mpicc -show
gcc-8 -Wl,-flat_namespace -Wl,-commons,use_dylibs -I/usr/local/Cellar/mpich/3.2.1_2/include -L/usr/local/Cellar/mpich/3.2.1_2/lib -lmpi -lpmpi
$ mpicxx -show
g++-8 -Wl,-flat_namespace -Wl,-commons,use_dylibs -I/usr/local/Cellar/mpich/3.2.1_2/include -L/usr/local/Cellar/mpich/3.2.1_2/lib -lmpicxx -lmpi -lpmpi
$ mpif90 -show
gfortran -Wl,-flat_namespace -Wl,-commons,use_dylibs -I/usr/local/Cellar/mpich/3.2.1_2/include -I/usr/local/Cellar/mpich/3.2.1_2/include -L/usr/local/Cellar/mpich/3.2.1_2/lib -lmpifort -lmpi -lpmpi
$ mpif77 -show
gfortran -Wl,-flat_namespace -Wl,-commons,use_dylibs -I/usr/local/Cellar/mpich/3.2.1_2/include -I/usr/local/Cellar/mpich/3.2.1_2/include -L/usr/local/Cellar/mpich/3.2.1_2/lib -lmpifort -lmpi -lpmpi
For added bonus, I've used Homebrew's Python(3):
brew install python3
Followed by (I've been rather explicit with the path for Python 3, even if Apple doesn't provide a Python 3 that may clash with Homebrew's one):
/usr/local/bin/python2/3 -m pip install h5py nose numpy mpi4py docutils matplotlib
PYTHON=/usr/local/bin/python3 ./configure
PYTHON=/usr/local/bin/python3 CC=/usr/local/bin/gcc-8 CXX=/usr/local/bin/g++-8 make build3 -j2
/usr/local/bin/python3.6 setup.py install
(The second command could probably be skipped, and the build done with just setup.py install.)
Great! I'd like to test this on a clean macOS installation to see if any problems remain, but looks like this would be the way to do it. I also want to check if we can do without installing gcc, using gfortran for fortran codes and the Xcode clang for c/c++ codes.
@rieder that (Xcode clang) is the approach taken in the Conda setup, and it works there, so it should be possible with Homebrew as well.
Great!
Unfortunately not:
$ brew install gfortran
Error: No available formula with the name "gfortran"
GNU Fortran is now provided as part of GCC, and can be installed with:
brew install gcc
I guess it could work, but if we already need to install gcc to get gfortran, it seems more practical and consistent to use gcc/g++ and not clang.
Correct, as noted in my comment; this is why I used gcc. You could try gfortran from http://hpc.sourceforge.net/ ; in the past, that has caused me problems, but that was for quite a different OSX version. There was also an openMPI issue with clang, if I recall correctly. Might have been fixed in another issue though.
On my "almost" clean installation, I still run into some problems unfortunately, some codes refusing to build. I'll try this on a fully clean installation next week.
Should be fixed by the time #373 is closed.
brew install pkg-config is important to find packages in the right place