CMake fails at finding working MPI when building with Kokkos+CUDA in Docker

Thank you Axel for the hints. I changed those two vars as you suggested, but it turned not to be the problem. I had to make the following changes to have an image building correctly.

First, the full set of correct env variables:

ENV CC=/usr/bin/gcc \
    CXX=/usr/bin/g++ \
    MPICC=/opt/hpcx/ompi/bin/mpicc \
    MPICXX=/opt/hpcx/ompi/bin/mpicxx \
    CUDA_HOME=/usr/local/cuda \
    CUDA_LIB_PATH=/usr/local/cuda-12.8/compat/lib.real \
    CMAKE_CUDA_COMPILER=/opt/lammps/lib/kokkos/bin/nvcc_wrapper

The last two were critical.

The second things is a fix that took me quite a while to find, but I still don’t fully understand why it’s needed. I have to apply the following patch to CMakeLists.txt:

--- cmake/CMakeLists.txt.orig	2025-06-16 11:02:36.977050977 +0200
+++ cmake/CMakeLists.txt	2025-06-16 11:02:45.398044421 +0200
@@ -130,9 +130,9 @@
 endif()
 
 # silence nvcc warnings
-if((PKG_KOKKOS) AND (Kokkos_ENABLE_CUDA) AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-Xcudafe --diag_suppress=unrecognized_pragma,--diag_suppress=128")
-endif()
+#if((PKG_KOKKOS) AND (Kokkos_ENABLE_CUDA) AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
+#  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-Xcudafe --diag_suppress=unrecognized_pragma,--diag_suppress=128")
+#endif()
 
 # we *require* C++11 without extensions but prefer C++17.
 # Kokkos requires at least C++17 (currently)

If those flags are added, the Could NOT find MPI_CXX (missing: MPI_CXX_WORKS) comes back. My guess it’s because those flags are not supported by the CXX compiler I’m using which fails the tests by CMake. In fact, I read that the supposedly correct way would be to set CMAKE_CXX_COMPILER to the nvcc_wrapper (which never worked for me). If you have any hint…

I still have to run & test the container, especially with MPI, but it’s already a good progress having built the image.

Thanks again!

1 Like