don't execute any mpi_info/mpiname in the path
authorSzilard Pall <pszilard@cbr.su.se>
Fri, 2 Nov 2012 02:27:52 +0000 (03:27 +0100)
committerSzilard Pall <pszilard@cbr.su.se>
Fri, 2 Nov 2012 11:51:45 +0000 (12:51 +0100)
During MPI setup, the gmxManageMPI.cmake script uses mpi_info/mpiname to
check for and warn about potentially problematic versions. However,
executing these binatries without any path can lead to false positive
warnings e.g. in case if the MPI installation in used does not provide
mpi_info, but another MPI installation's mpi_info is in the path
(which is the case with MacPorts OpenMPI + Xcode's MPI).

To avoid these false positives we don't execute any other
mpi_info/mpiname but the ones found at the same path where the MPI
compiler wrapper resides (if any).

Change-Id: Icd2091dd952f4a140b92045f95a8d0187c1a354f

cmake/gmxManageMPI.cmake

index 5a8558176447a0c276e0e0158a0d1571db21414a..49868cb4672d24e29bec5993d41f6c039d77ddaa 100644 (file)
@@ -36,45 +36,78 @@ if(GMX_MPI)
       gmx_test_mpi_in_place(MPI_IN_PLACE_EXISTS)
     endif()
 
+    # Find path of the mpi compilers
+    if (${${MPI_PREFIX}_FOUND})
+        get_filename_component(_mpi_c_compiler_path "${MPI_C_COMPILER}" PATH)
+        get_filename_component(_mpiexec_path "${MPIEXEC}" PATH)
+    else()
+        get_filename_component(_cmake_c_compiler_path "${CMAKE_C_COMPILER}" PATH)
+        get_filename_component(_cmake_cxx_compiler_path "${CMAKE_CXX_COMPILER}" PATH)
+    endif()
+
     # Test for and warn about unsuitable MPI versions
-    exec_program(ompi_info
-      ARGS -v ompi full
-      OUTPUT_VARIABLE OPENMPI_TYPE
-      RETURN_VALUE OPENMPI_EXEC_RETURN)
-    if(OPENMPI_EXEC_RETURN EQUAL 0)
-      string(REGEX REPLACE ".*Open MPI: \([0-9]+\\.[0-9]*\\.?[0-9]*\).*" "\\1" OPENMPI_VERSION ${OPENMPI_TYPE})
-      if(OPENMPI_VERSION VERSION_LESS "1.4.1")
-        MESSAGE(WARNING
+    #
+    # Execute the ompi_info binary with the full path of the compiler wrapper
+    # found, otherwise we run the risk of false positives.
+    find_file(MPI_INFO_BIN ompi_info
+              HINTS ${_mpi_c_compiler_path} ${_mpiexec_path}
+                    ${_cmake_c_compiler_path} ${_cmake_cxx_compiler_path}
+              NO_DEFAULT_PATH
+              NO_SYSTEM_ENVIRONMENT_PATH
+              NO_CMAKE_SYSTEM_PATH)
+    if (MPI_INFO_BIN)
+      exec_program(${MPI_INFO_BIN}
+        ARGS -v ompi full
+        OUTPUT_VARIABLE OPENMPI_TYPE
+        RETURN_VALUE OPENMPI_EXEC_RETURN)
+      if(OPENMPI_EXEC_RETURN EQUAL 0)
+        string(REGEX REPLACE ".*Open MPI: \([0-9]+\\.[0-9]*\\.?[0-9]*\).*" "\\1" OPENMPI_VERSION ${OPENMPI_TYPE})
+        if(OPENMPI_VERSION VERSION_LESS "1.4.1")
+          MESSAGE(WARNING
              "CMake found OpenMPI version ${OPENMPI_VERSION} on your system. "
              "There are known problems with GROMACS and OpenMPI version < 1.4.1. "
              "Please consider updating your OpenMPI if your MPI wrapper compilers "
              "are using the above OpenMPI version.")
+        endif()
+        unset(OPENMPI_VERSION)
+        unset(OPENMPI_TYPE)
+        unset(OPENMPI_EXEC_RETURN)
       endif()
-      unset(OPENMPI_VERSION)
-      unset(OPENMPI_TYPE)
-      unset(OPENMPI_EXEC_RETURN)
     endif()
-    exec_program(mpiname
-      ARGS -n -v
-      OUTPUT_VARIABLE MVAPICH2_TYPE
-      RETURN_VALUE MVAPICH2_EXEC_RETURN)
-    if(MVAPICH2_EXEC_RETURN EQUAL 0)
-      string(REGEX MATCH "MVAPICH2" MVAPICH2_NAME ${MVAPICH2_TYPE})
-      # Want to check for MVAPICH2 in case some other library supplies mpiname
-      string(REGEX REPLACE "MVAPICH2 \([0-9]+\\.[0-9]*[a-z]?\\.?[0-9]*\)" "\\1" MVAPICH2_VERSION ${MVAPICH2_TYPE})
-      if(${MVAPICH2_NAME} STREQUAL "MVAPICH2" AND MVAPICH2_VERSION VERSION_LESS "1.5")
-        # This test works correctly even with 1.5a1
-        MESSAGE(WARNING
+    unset(MPI_INFO_BIN)
+
+    # Execute the mpiname binary with the full path of the compiler wrapper
+    # found, otherwise we run the risk of false positives.
+    find_file(MPINAME_BIN mpiname
+              HINTS ${_mpi_c_compiler_path}
+                    ${_cmake_c_compiler_path} ${_cmake_cxx_compiler_path}
+              NO_DEFAULT_PATH
+              NO_SYSTEM_ENVIRONMENT_PATH
+              NO_CMAKE_SYSTEM_PATH)
+    if (MPINAME_BIN)
+      exec_program(${MPINAME_BIN}
+        ARGS -n -v
+        OUTPUT_VARIABLE MVAPICH2_TYPE
+        RETURN_VALUE MVAPICH2_EXEC_RETURN)
+      if(MVAPICH2_EXEC_RETURN EQUAL 0)
+        string(REGEX MATCH "MVAPICH2" MVAPICH2_NAME ${MVAPICH2_TYPE})
+        # Want to check for MVAPICH2 in case some other library supplies mpiname
+        string(REGEX REPLACE "MVAPICH2 \([0-9]+\\.[0-9]*[a-z]?\\.?[0-9]*\)" "\\1" MVAPICH2_VERSION ${MVAPICH2_TYPE})
+        if(${MVAPICH2_NAME} STREQUAL "MVAPICH2" AND MVAPICH2_VERSION VERSION_LESS "1.5")
+          # This test works correctly even with 1.5a1
+          MESSAGE(WARNING
              "CMake found MVAPICH2 version ${MVAPICH2_VERSION} on your system. "
              "There are known problems with GROMACS and MVAPICH2 version < 1.5. "
              "Please consider updating your MVAPICH2 if your MPI wrapper compilers "
              "are using the above MVAPICH2 version.")
+       endif()
+       unset(MVAPICH2_VERSION)
+       unset(MVAPICH2_NAME)
+       unset(MVAPICH2_TYPE)
+       unset(MVAPICH2_EXEC_RETURN)
       endif()
-      unset(MVAPICH2_VERSION)
-      unset(MVAPICH2_NAME)
-      unset(MVAPICH2_TYPE)
-      unset(MVAPICH2_EXEC_RETURN)
     endif()
+    unset(MPINAME_BIN)
 
   else(MPI_FOUND)
     if (CMAKE_VERSION VERSION_LESS "2.8.5")