cmake Could NOT find MPI_CXX (missing: MPI_CXX_WORKS)

Rocky Linux 9 x86_64 system. The default GCC version is 11.4.

GCC-Toolset-13 is installed in /opt/rh/gcc-toolset-13/root/usr/bin , and the GCC compiler version is 13.3. The environment is set up using the /opt/rh/gcc-toolset-13/enable script.

I compiled OpenMPI 5.0.9 using GCC 11.4, and compiled OpenMPI 5.0.9 with Cuda 12.9 support using GCC 13.3.

First, I successfully compiled the CPU version of GROMACS 2025 using the openmpi/5.0_gcc11 combination, and successfully compiled the CUDA version of GROMACS 2025 using the openmpi/5.0_cuda12.9_gcc13 combination.

Next, while compiling LAMMPS July 2025, I created a build folder in the LAMMPS source code directory, entered the build directory, and ran the command:

cmake -C …/cmake/presets/gcc.cmake …/cmake -D BUILD_MPI=yes -D BUILD_OMP=yes

When using the openmpi/5.0_gcc11 combination, the configuration and compilation process for the LAMMPS CPU version succeeded smoothly.

However, when using the openmpi/5.0_cuda12.9_gcc13 combination, the configuration process immediately failed with the following error:

-- Running check for auto-generated files from make-based build system
-- Could NOT find MPI_CXX (missing: MPI_CXX_WORKS)
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find MPI (missing: MPI_CXX_FOUND CXX)
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindMPI.cmake:1837 (find_package_handle_standard_args)
  CMakeLists.txt:393 (find_package)
-- Configuring incomplete, errors occurred!

It didn’t even get to adding the LAMMPS CUDA options; just -D BUILD_MPI=yes triggered the error. I’m not sure what is causing this issue. How can it be resolved? Thank you.

CMake is telling you what is wrong: you don’t have a functional MPI C++ compiler wrapper in your path.

You can learn more about how to augment CMake’s MPI detection in the CMake documentation: FindMPI — CMake 3.20.6 Documentation

But I can build Gromacs successfully by using the same openmpi/5.0_cuda12.9_gcc13 compiler combination. PATH or any other ENVs are all the same. Cmake of Gromacs said:

– MPI is not compatible with thread-MPI. Disabling thread-MPI.
– Found MPI_CXX: /opt/openmpi/5.0.9_cuda12.9_gcc13/bin/mpicxx (found version “3.1”)
– Found MPI: TRUE (found version “3.1”) found components: CXX
– GROMACS library will use OpenMPI 5.0.9

I also read this post. And try to set a lot of cmake-variables just like CMAKE_CXX_COMPILER CMAKE_CUDA_COMPILER and so on, but nothing help.

Finally, as the post said, I comment the silence nvcc warnings in cmake/CMakeLists.txt. Building of lammps successed. I did’t know why set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xcudafe --diag_suppress=unrecognized_pragma,--diag_suppress=128") can cause a Could NOT find MPI_CXX (missing: MPI_CXX_WORKS) error. Anyway, it’s worked.