FindMPI: Choosing an MPI release outside the PATH

MPI is a standard with multiple implementations, some academic and others commercial. MPI implementations typically wrap the compiler, so to use it you would normally build your code with mpicc (which adds MPI’s include and library folder paths).

The problem is that many RPM-based Linux distributions seem to install MPI releases outside the PATH. For example, Fedora puts OpenMPI in /usr/lib64/openmpi/bin/ and MPICH in /usr/lib64/mpich/bin. I suggested a Merge request which looks for MPI’s installed outside path, but it has a problem: it introduces preference in the order which MPI releases are chosen.

@brad.king suggested I put it here for discussion (makes sense), so here I am.
What do you think?

To clarify, currently if you install any MPI on most RPM-based Linux distributions and try FindMPI.cmake it fails to find it. Other distributions do place MPI in their path, so it’s not like FindMPI is broken…

FWIW, my usual usage is to add /usr/lib64/mpich to CMAKE_PREFIX_PATH when using MPI on Fedora. This is because it’s not just MPI that is there. HDF5 and NetCDF also exist there in their MPI-enabled variants, so I think that just searching for MPI impls is not suitable in general.

Fedora does provide module load mpi/mpich-x86_64 to do this (same for other MPI impls). Debian apparently uses alternatives which is just as suitable in most situations.

Fedora does provide module load mpi/mpich-x86_64 to do this

According to Fedora documentation on MPI, that is the correct way to use MPI. For example:

$ sudo dnf install openmpi-devel environment-modules
(restart shell if necessary to get `module` function)
$ module avail mpi
...
mpi/openmpi-x86_64
...
$ module load mpi/openmpi-x86_64
$ type mpicc
mpicc is /usr/lib64/openmpi/bin/mpicc
$ type mpirun
mpirun is /usr/lib64/openmpi/bin/mpirun