title: Switch from MPICH to OpenMPI
body: <p>I have both mpich and openmpi in my Ubuntu 20.04.</p>
  <pre><code>$ dpkg -l | grep mpi | grep lib
  ...
  ii  libmpich-dev:amd64                            3.3.2-2build1                         amd64        Development files for MPICH
  ii  libmpich12:amd64                              3.3.2-2build1                         amd64        Shared libraries for MPICH
  ...
  ii  libopenmpi-dev:amd64                          4.0.3-0ubuntu1                        amd64        high performance message passing library -- header files
  ii  libopenmpi3:amd64                             4.0.3-0ubuntu1                        amd64        high performance message passing library -- shared library
  ...
  ii  openmpi-bin                                   4.0.3-0ubuntu1                        amd64        high performance message passing library -- binaries
  ii  openmpi-common                                4.0.3-0ubuntu1                        all          high performance message passing library -- common files
  ..
  $ dpkg -l | grep mpich
  ...
  ii  mpich                                         3.3.2-2build1                         amd64        Implementation of the MPI Message Passing Interface standard
  </code></pre>
  <p>The default (probably because it was installed later) appears to be mpich.</p>
  <p><strong>How would I change to openmpi?</strong></p>
  <p>I want to make sure that everything that needs to be changed actually is.
  So far, I am thinking about headers, executable, libraries.
  I do not know which are all directories, links, etc., that have to change.</p>
  <p>For instance, <a href="https://stackoverflow.com/questions/52016418/cmake-selecting-mpich-over-openmpi#comment91012586_52016418">here</a> it is suggested <code>cmake -DMPI_CC_COMPILER=/.../mpicc</code>.
  And it was mentioned in comments that it worked. But:</p>
  <ol>
  <li><p>I am not sure it actually fixes all headers, etc.</p>
  </li>
  <li><p>I need a method that:</p>
  <p>2.1. Works for all users in the system</p>
  <p>2.2. Does not require those macros</p>
  <p>2.3. Works also for other compilation methods other than <code>cmake</code></p>
  </li>
  </ol>
  <p>As for 2.3, I tried now to configure petsc</p>
  <pre><code>$ ./configure --with-cc=mpicc --with-fc=mpif90 -with-cxx=mpicxx --with- make-np=10 --with-shared-libraries --download-f2cblaslapack --download-mumps --download-scalapack --with-debugging=0 COPTFLAGS=&quot;-O -O3 -march=native -mtune=native&quot; FOPTF LAGS=&quot;-O -O3 -march=native -mtune=native&quot; CXXOPTFLAGS=&quot;-O -O3 -march=native -mtune=native&quot;
  </code></pre>
  <p>and I got</p>
  <pre><code>Your libraries are from MPICH but it appears your mpiexec is from OpenMPI
  </code></pre>
  <hr>
  <p><strong>Can this be fixed with <code>update-alternatives</code>?</strong></p>
  <p>I found this, which makes me think it can, but in my system it is not correctly configured:</p>
  <pre><code>$ type mpiexec
  mpiexec is hashed (/usr/bin/mpiexec)
  $ ll /usr/bin/mpiexec
  lrwxrwxrwx 1 root root 25 Jan 21 11:11 /usr/bin/mpiexec -&gt; /etc/alternatives/mpiexec
  $ ll /etc/alternatives/mpiexec
  lrwxrwxrwx 1 root root 24 Jan 21 11:11 /etc/alternatives/mpiexec -&gt; /usr/bin/mpiexec.openmpi
  $ ll /usr/bin/mpiexec.openmpi
  lrwxrwxrwx 1 root root 7 Apr 15  2020 /usr/bin/mpiexec.openmpi -&gt; orterun
  
  $ type mpirun
  mpirun is /usr/bin/mpirun
  $ ll /usr/bin/mpirun
  lrwxrwxrwx 1 root root 24 Jan 21 11:11 /usr/bin/mpirun -&gt; /etc/alternatives/mpirun
  $ ll /etc/alternatives/mpirun
  lrwxrwxrwx 1 root root 23 Jan 21 11:11 /etc/alternatives/mpirun -&gt; /usr/bin/mpirun.openmpi
  $ ll /usr/bin/mpirun.openmpi
  lrwxrwxrwx 1 root root 7 Apr 15  2020 /usr/bin/mpirun.openmpi -&gt; orterun
  
  $ type mpicc
  mpicc is hashed (/usr/bin/mpicc)
  $ ll /usr/bin/mpicc
  lrwxrwxrwx 1 root root 21 Feb 25 18:54 /usr/bin/mpicc -&gt; /etc/alternatives/mpi
  $ ll /etc/alternatives/mpi
  lrwxrwxrwx 1 root root 20 Feb 25 18:54 /etc/alternatives/mpi -&gt; /usr/bin/mpicc.mpich
  </code></pre>
  <hr>
  <p><strong>Related</strong></p>
  <ol>
  <li><a href="https://stackoverflow.com/questions/32568197/replace-mpich-installation-by-openmpi">Replace MPICH Installation by OpenMPI</a></li>
  <li><a href="https://stackoverflow.com/questions/52016418/cmake-selecting-mpich-over-openmpi">CMake : Selecting mpich over openmpi</a></li>
  <li><a href="https://unix.stackexchange.com/questions/413099/flip-between-openmpi-and-mpich-as-default-using-linux-terminal">https://unix.stackexchange.com/questions/413099/flip-between-openmpi-and-mpich-as-default-using-linux-terminal</a></li>
  <li><a href="https://stackoverflow.com/questions/29369208/difference-between-mpi-and-mpich2-folder">Difference between mpi and mpich2 folder?</a></li>
  <li><a href="https://stackoverflow.com/questions/52016418/cmake-selecting-mpich-over-openmpi">CMake : Selecting mpich over openmpi</a></li>
  <li><a href="https://stackoverflow.com/questions/66535019/switch-from-mpich-to-openmpi">Switch from MPICH to OpenMPI</a></li>
  <li>This? <a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=896189" rel="nofollow noreferrer">https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=896189</a></li>
  <li>This? <a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=912437" rel="nofollow noreferrer">https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=912437</a></li>
  <li><a href="https://unix.stackexchange.com/questions/81992/better-way-to-add-alternative-using-update-alternatives">https://unix.stackexchange.com/questions/81992/better-way-to-add-alternative-using-update-alternatives</a></li>
  <li><a href="https://askubuntu.com/questions/964600/how-to-add-slave-to-existing-update-alternatives-link-group">https://askubuntu.com/questions/964600/how-to-add-slave-to-existing-update-alternatives-link-group</a></li>
  </ol>