MPI Library File Link Error

Symptom

When the mpirun command is executed, the error message "error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory" is displayed, as shown below.

# mpirun -n 8 ./all_reduce_test -b 1m -e 100m -p 8
./all_reduce_test: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory
./all_reduce_test: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory
./all_reduce_test: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory
./all_reduce_test: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory
./all_reduce_test: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory
./all_reduce_test: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory
./all_reduce_test: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory

Solution

Add the MPI library to the environment variable LD_LIBRARY_PATH. For example:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpich/lib