Openmpi linked to gcc

How do I install openmpi such that it is linked to gcc-9 in mac osx mojave?

First, I installed gcc-9 in macosx using the following command:

brew install gcc

Then, I installed openmpi using:

brew install openmpi

However, this openmpi is now linked to clang, which I don’t want to use at all.
I tried exporting HOMEBREW_CC=gcc-9 and HOMEBREW_CXX=g+±9, but this did not quite work since the ompi_info, shows:
C compiler: clang
C++ compiler: clang++

Please help!

You could make a copy of the openmpi formula in your own tap where you make it depend on gcc. See docs.brew.sh for more information on that.

I did the following:

brew edit open-mpi

There, I saw that the formula already says

head do

url " https://github.com/open-mpi/ompi.git "

depends_on “autoconf” => :build

depends_on “automake” => :build

depends_on “libtool” => :build

end

depends_on “gcc”

depends_on “hwloc”

depends_on “libevent”

I then closed the file and ran:

brew install open-mpi

However, it is still linked to clang!

openmpi can be used by gcc just by specifing these environemental variables:

export OMPI_CXX=g++-9
export OMPI_CC=gcc-9
export OMPI_FC=gfortran-9

Why would you like to recompile it?

I tried exporting those variables you suggested, but when I type ompi_info on the terminal, I see that openmpi is linked to clang compiler. However, I would like to use gcc compiler that was installed (since it is a dependency of openmpi) when I tried installing openmpi.

ompi_info returns the following output:

C compiler: clang
C compiler absolute: /Users/amritpoudel/Desktop/HPC_LIB/HOMEBREW/Library/Homebrew/shims/mac/super/clang
C compiler family name: GNU
C compiler version: 4.2.1
C++ compiler: clang++
C++ compiler absolute: /Users/amritpoudel/Desktop/HPC_LIB/HOMEBREW/Library/Homebrew/shims/mac/super/clang++
Fort compiler: gfortran
Fort compiler abs: /Users/amritpoudel/Desktop/HPC_LIB/HOMEBREW/opt/gcc/bin/gfortran

Any suggestions?

Those are the compilers that built openmpi. But why do you need to change those?

Usually people just want to use a mpi to compile stuff, since mpicc mpicxx etc… are just wrappers, you can use another compiler:

> mpicc
clang: error: no input files
> export OMPI_CC=gcc-9
> mpicc
gcc-9: fatal error: no input files

Understood. Thanks a lot for clarifying!

@ SMillerDevSean Molenaar, please check out @ ltommi response above. He offers a solution without referring me to a link !

Yes, he gives you the answer you would have gotten if you asked a question to the people who build the software, not the people who package it.

Just for information, I tried the export OMPI_FC=gfortran-9 approach on CentOS 7. Then I got a warning in the linking stage:

/home/linuxbrew/.linuxbrew/bin/ld: warning: libgfortran.so.3, needed by /home/linuxbrew/.linuxbrew/Cellar/open-mpi/4.0.2/lib/libmpi_usempif08.so, may conflict with libgfortran.so.5

though the compiled executable seems to be working for now.