Gromacs 2021.2 with MPI on WSL

GROMACS version: 2021.2
GROMACS modification: No

I am trying to compile gromacs 2021.2 with MPI on the Windows Subsystem for Linux.

My cmake options are:

cmake … -DGMX_BUILD_OWN_FFTW=OFF -DREGRESSIONTEST_DOWNLOAD=OFF -DREGRESSIONTEST_PATH=/home/mmxni/regressiontests-2021.2 -DMPI_C_COMPILER=mpicc -DGMX_MPI=on -DGMX_DOUBLE=on

The errors occur during make check:

[ 71%] Linking CXX executable …/…/…/…/…/bin/workflow-details-test
/usr/bin/ld: …/…/…/…/…/lib/libgmxapi_mpi_d.so.0.2.0: undefined reference to ompi_mpi_cxx_op_intercept' /usr/bin/ld: ../../../../../lib/libgmxapi_mpi_d.so.0.2.0: undefined reference to MPI::Datatype::Free()’
/usr/bin/ld: …/…/…/…/…/lib/libgmxapi_mpi_d.so.0.2.0: undefined reference to MPI::Comm::Comm()' /usr/bin/ld: ../../../../../lib/libgmxapi_mpi_d.so.0.2.0: undefined reference to MPI::Win::Free()’
collect2: error: ld returned 1 exit status
make[3]: *** [src/api/cpp/workflow/tests/CMakeFiles/workflow-details-test.dir/build.make:114: bin/workflow-details-test] Error 1
make[2]: *** [CMakeFiles/Makefile2:7266: src/api/cpp/workflow/tests/CMakeFiles/workflow-details-test.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:251: CMakeFiles/check.dir/rule] Error 2
make: *** [Makefile:249: check] Error 2

I have previously tried compiling an earlier version of gromacs without MPI on WSL as well and it installed successfully. Searching for ‘undefined reference to MPI’ errors suggested that I add the -DMPI_C_COMPILER=mpicc to cmake, but after adding that I still get the same errors. I have the latest versions of gcc, cmake, and mpich.

Any help would be much appreciated.

You do not need to specify MPI wrapper as your c compiler at the installation step. Read this: Installation guide — GROMACS 2021.2 documentation

Correct way to install MPI support is:

tar -xf .. gromacs..
cd gromacs-...
mkdir build
cd build
cmake .. -DCMAKE_C_COMPILER=(name of your serial c compiler, e.g. gcc) \
-DCMAKE_CXX_COMPILER=(name of c++ serial compiler, e.g. g++) \
-DGMX_MPI=on -DCMAKE_PREFIX_PATH=/path/to/required/mpilibrarydir1:\
 /path/to/required/mpilibrarydir2:
make
make check
make install

Configure script will then automatically detect the compiler wrappers.
The CMAKE_PREFIX_PATH is to make sure that configure script finds all the libraries. You can skip that if all of the required library paths are given in the LD_LIBRARY_PATH environment variable or if the libraries are detected by the system through ldconfig utility.

Hope this helps.

Here’s a method which I used to install GROMACS:
Step 1: Install MPI implementation

wget link-to-mpi-installation-archive.gz
tar-xf your-mpi-implementation
mkdir build1
cd build1
../configure --prefix=/opt/mpi
make install

Step 2: make mpi executable files and libraries are detectable globally. (This step assumes Debian like OS)

sudo ln -s /opt/mpi/bin/m* /usr/local/bin
sudo nano /etc/ld.so.conf.d/customlibs.conf 
(add a line - /opt/mpi/lib save and close)
sudo ldconfig -v
(check the output to make sure all required libs are detected)

Step 3: GROMACS installation like in the previous post without the CMAKE_PREFIX_PATH option to cmake.

If you installed mpich using apt (or some other package manager) then you need to make sure that you have all the libraries installed as well

sudo apt install build-essential libmpich12 libmpich-dev ...(and any other dependencies or required packages)

Note that there is no benefit of building with real MPI (over the built-in TMPI) unless you plan to run on more than one node.