I think an alias
would work perfectly for your situation. You can add the following to your .profile
or .bash_profile
:
alias mympicc='/usr/local/MPICH/bin/mpicc'
A more permanent (but still reversible) solution is to add the MPICH
location to your path BEFORE the OPENMPI
location. Easily done by adding the following your .profile
or .bash_profile
:
export PATH="/usr/local/MPICH/bin:$PATH"
When you type a command like mpicc
, if it's not in your current directory, your shell will search the PATH
for it, in order, so it is important which position you put it to set precedence.
If you want to have some sort of a switch that you can use to easily "flip" between the two, you could make some sort of function and add it to your .bashrc
(or .profile
/.bash_profile
?):
use_mpicc () {
shopt -s nocasematch
case "$1" in
mpich) export PATH="...:/usr/local/MPICH/bin:/usr/local/OPENMPI/bin:..." ;;
openmpi) export PATH="...:/usr/local/OPENMPI/bin:/usr/local/MPICH/bin:..." ;;
*) return 1 ;;
esac
shopt -u nocasematch
}
In this example I have used ellipsis in place of your actual path. I recommend actually specifying the full path in this function (if used) rather than using the: PATH="Stuff_I_Need_added:$PATH"
method as that will just keep adding to your PATH
every time you call the function, potentially causing it to become obnoxiously long.
You would call this like:
$ use_mpicc mpich
$ # OR
$ use_mpicc openmpi
More reading on setting your path
modules
that allow you to change the enviroment for certain libraries/compilers. For examplemodule load mpich
/module swap open-mpi
. – alfC Mar 18 '20 at 01:45