How to build openmpi with homebrew and gcc-4.9?

10,859

Finally it was solved as follows:

1) Add environment variables for homebrew (you can also add these lines to your ~\.bashrc):

export HOMEBREW_CC=gcc-4.9
export HOMEBREW_CXX=g++-4.9

2) Rebuild and reinstall openmpi and its dependencies from source

brew reinstall openmpi --build-from-source

3) In the end you will get a message like:

==> Reinstalling open-mpi
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.
==> Downloading http://www.open-mpi.org/software/ompi/v1.8/downloads/openmpi-1.8.
Already downloaded: /Library/Caches/Homebrew/open-mpi-1.8.4.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/open-mpi/1.8.4 --disable-silent-rules 
==> make all
==> make check
==> make install
Warning: open-mpi dependency gcc was built with a different C++ standard
library (libstdc++ from clang). This may cause problems at runtime.
🍺  /usr/local/Cellar/open-mpi/1.8.4: 785 files, 23M, built in 41.2 minutes

$mpicc --showme 
gcc-4.9 -I/usr/local/Cellar/open-mpi/1.8.4/include -L/usr/local/opt/libevent/lib -L/usr/local/Cellar/open-mpi/1.8.4/lib -lmpi

On my MacBook I had some conflicts with XCode 6.2, which were solved following this instructions

However, I decided to stay with the clang version to avoid issues with gfortran.

Share:
10,859
ilciavo
Author by

ilciavo

Updated on June 27, 2022

Comments

  • ilciavo
    ilciavo almost 2 years

    By default brew install openmpi uses clang to create its wrapper.

    I need to specify gcc-4.9(Homebrew installed) for the wrapper.

    I have tried

    $export CC=gcc-4.9
    $brew install openmpi
    
    $brew install --cc=gcc-4.9 openmpi
    
    $brew install --with-gcc49 openmpi
    
    $brew install -CC=gcc-4.9 -CXX=g++-4.9 -FC=gfortran -F77=gfortran openmpi
    
    $brew install openmpi --cc=gcc-4.9 
    
    $brew install openmpi --CC=gcc-4.9 --CXX=g++-4.9 --FC=gfortran --F77=gfortran
    

    Finally, I've modified the openmpi formula adding:

     args = %W[
      CC=gcc-4.9 
      CXX=g++-4.9 
      FC=gfortran 
      F77=gfortran
    

    I still get

    $mpicc --showme
    clang -I/usr/local/Cellar/open-mpi/1.8.4/include -L/usr/local/opt/libevent/lib -L/usr/local/Cellar/open-mpi/1.8.4/lib -lmpi
    
  • Chiel
    Chiel almost 8 years
    Why did you decide to stay with clang to avoid issues with gfortran? I do not get this statement.
  • ilciavo
    ilciavo almost 8 years
    @Chiel I used to had issues when building with openmpi and gfortran, thus building openmpi with clang inhibitted gfortran
  • Bart
    Bart over 7 years
    Worked perfectly for me, without any issues! And our MPI application runs a lot faster (~30%) when using openMPI compiled with GCC instead of openMPI with clang.
  • ilciavo
    ilciavo over 7 years
    @bart which versions of GCC and openMPI are you using?
  • Bart
    Bart over 7 years
    @ilciavo GCC 6.1 with openMPI 1.10.2
  • ilciavo
    ilciavo over 7 years
    @Bart you're right the issue disappeared with GCC 6.1 but it is still present if you want to build with gcc-4.9
  • blkpingu
    blkpingu over 2 years
    can you update this answer to current versions?