12

OpenMPI strongly recommends using their wrapper compilers. Behind the scenes, their wrapper compiler mpiCC calls gcc (by default?) and adds the necessary flags for MPI code to compile. However, other compilers give more descriptive error messages than gcc (e.g. clang which is also GCC-compatible). So, I'd like to be able to use clang with Open MPI.

I tried:

1) finding an mpiCC option for specifying the compiler, but

mpiCC --help

just spits out the g++ help page.

2) using the --showme:compile option

mpiCC --showme:compile ./test-boost.cc -lboost_mpi -lboost_serialization -o test-boost

which, instead of calling gcc, prints the flags needed for compiling the MPI code. I can then use those with clang (since it's GCC-compatible). This should work, but I'm looking for an easier solution.

Ammar
  • 573
  • 1
  • 4
  • 14

2 Answers2

16

Open MPI FAQ says which environmental variables can be set to override the default choice of the compiler called by the wrapper.

http://www.open-mpi.org/faq/?category=mpi-apps#override-wrappers-after-v1.0

Depending on the version of OpenMPI you should set OMPI_CXX=clang++ or OMPI_MPICC=clang. For OpenMPI v.1.1 and later use OMPI_CXX and then call the wrapper compiler. The wrapper would call clang++ in turn.

Rufflewind
  • 8,545
  • 2
  • 35
  • 55
Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76
  • 1
    Unfortunately, this does not seem to work if you need to use multiple "wrapper" compilers, e.g. `nvcc` + `mpicc`. E.g. `OMPI_CXX=clang++ nvcc -ccbin mpicc` ultimately uses `g++` as the host compiler, so `OMPI_CXX` seems to be lost somewhere along the way... – Jakub Klinkovský Aug 04 '19 at 14:31
2

Setting OMPI_CC=clang or OMPI_CXX=clang++ as environment variables in .bashrc, as described in the official FAQ of OpenMPI, is NOT working for me. I have to attach them ahead whenever I use mpicc, e.g.

OMPI_CC=clang mpicc --showme:command

So in Makefile, I set CC=OMPI_CC=clang mpicc, which works well for me.

oracleyue
  • 394
  • 2
  • 9
  • 2
    Did you `export` the variables? – Rufflewind May 02 '16 at 08:06
  • @Rufflewind Yes, but it doesn't work on my mac (OS X 10.10). BTW, I use `.profile` to configure bash, instead of `.bashrc` (for certain reasons, I have forgotten). Maybe this is the reason. – oracleyue May 25 '16 at 14:33
  • 1
    Bash does not read `~/.profile` if `~/.bash_profile` or `~/.bash_login` are already present. – Rufflewind May 25 '16 at 22:48
  • @Rufflewind Thanks! I don't have any other configuration files of bash, like `.bashrc`, `.bash_profile`, `.bash_login`. Well, maybe mine is a special case, it could a conflict against other configurations/settings somewhere I don't know. – oracleyue May 27 '16 at 09:12