2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
5 # Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
6 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 # and including many others, as listed in the AUTHORS file in the
8 # top-level source directory and at http://www.gromacs.org.
10 # GROMACS is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public License
12 # as published by the Free Software Foundation; either version 2.1
13 # of the License, or (at your option) any later version.
15 # GROMACS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with GROMACS; if not, see
22 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 # If you want to redistribute modifications to GROMACS, please
26 # consider that scientific software is very special. Version
27 # control is crucial - bugs must be traceable. We will be happy to
28 # consider code for inclusion in the official distribution, but
29 # derived work must not be called official GROMACS. Details are found
30 # in the README & COPYING files - if they are missing, get the
31 # official version at http://www.gromacs.org.
33 # To help us fund GROMACS development, we humbly ask that you cite
34 # the research papers on the package. Check out http://www.gromacs.org.
38 message(STATUS "MPI is not compatible with thread-MPI. Disabling thread-MPI.")
39 set(GMX_THREAD_MPI OFF CACHE BOOL
40 "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" FORCE)
47 # Manage the MPI setup.
48 # Note that we may want to execute tests or Python with MPI,
49 # even if we are not using an MPI-enabled GROMACS build.
50 #TODO(#3672): find_package(MPI COMPONENTS ...)
53 if (NOT MPI_CXX_FOUND)
55 "MPI support requested, but no suitable MPI compiler found. Either set the "
56 "MPI_CXX_COMPILER to the MPI compiler wrapper (often called mpicxx or mpic++), "
57 "set CMAKE_CXX_COMPILER to a default-MPI-enabled compiler, "
58 "or set the variables reported missing for MPI_CXX above.")
59 elseif (MPI_CXX_VERSION VERSION_LESS 2.0)
60 message(FATAL_ERROR "MPI version 2.0 or higher is required. Please update your MPI library.")
62 # TODO(#3672): Replace usage of `MPI_LINKER_FLAGS` with MPI_LINK_FLAGS,
63 # MPI_<lang>_LINK_FLAGS, or target_link_libraries(... MPI::MPI_CXX)
64 set(MPI_LINKER_FLAGS ${MPI_CXX_LINK_FLAGS})
65 separate_arguments(MPI_CXX_LINK_FLAGS)
66 #TODO(#3672, #3776): These should be acquired through the MPI::MPI_CXX target.
67 include_directories(SYSTEM ${MPI_CXX_INCLUDE_PATH})
68 list(APPEND GMX_COMMON_LIBRARIES ${MPI_CXX_LIBRARIES})
72 # Test for and warn about unsuitable MPI versions
73 # Find path of the mpi compilers
75 get_filename_component(_mpi_c_compiler_path "${MPI_CXX_COMPILER}" PATH)
76 get_filename_component(_mpiexec_path "${MPIEXEC_EXECUTABLE}" PATH)
78 get_filename_component(_cmake_c_compiler_path "${CMAKE_C_COMPILER}" PATH)
79 get_filename_component(_cmake_cxx_compiler_path "${CMAKE_CXX_COMPILER}" PATH)
82 # Execute the ompi_info binary with the full path of the compiler wrapper
83 # found, otherwise we run the risk of false positives.
84 find_file(MPI_INFO_BIN ompi_info
85 HINTS ${_mpi_c_compiler_path} ${_mpiexec_path}
86 ${_cmake_c_compiler_path} ${_cmake_cxx_compiler_path}
88 NO_SYSTEM_ENVIRONMENT_PATH
91 exec_program(${MPI_INFO_BIN}
93 OUTPUT_VARIABLE OPENMPI_TYPE
94 RETURN_VALUE OPENMPI_EXEC_RETURN)
95 if (OPENMPI_EXEC_RETURN EQUAL 0)
96 string(REGEX REPLACE ".*Open MPI: \([0-9]+\\.[0-9]*\\.?[0-9]*\).*" "\\1" OPENMPI_VERSION ${OPENMPI_TYPE})
97 if (OPENMPI_VERSION VERSION_LESS "1.4.1")
99 "CMake found OpenMPI version ${OPENMPI_VERSION} on your system. "
100 "There are known problems with GROMACS and OpenMPI version < 1.4.1. "
101 "Please consider updating your OpenMPI if your MPI wrapper compilers "
102 "are using the above OpenMPI version.")
104 if (OPENMPI_VERSION VERSION_EQUAL "1.8.6")
106 "CMake found OpenMPI version ${OPENMPI_VERSION} on your system. "
107 "This OpenMPI version is known to leak memory with GROMACS,"
108 "please update to a more recent version. ")
110 unset(OPENMPI_VERSION)
112 unset(OPENMPI_EXEC_RETURN)
115 unset(MPI_INFO_BIN CACHE)
117 # Execute the mpiname binary with the full path of the compiler wrapper
118 # found, otherwise we run the risk of false positives.
119 find_file(MPINAME_BIN mpiname
120 HINTS ${_mpi_c_compiler_path}
121 ${_cmake_c_compiler_path} ${_cmake_cxx_compiler_path}
123 NO_SYSTEM_ENVIRONMENT_PATH
124 NO_CMAKE_SYSTEM_PATH)
126 exec_program(${MPINAME_BIN}
128 OUTPUT_VARIABLE MVAPICH2_TYPE
129 RETURN_VALUE MVAPICH2_EXEC_RETURN)
130 if (MVAPICH2_EXEC_RETURN EQUAL 0)
131 string(REGEX MATCH "MVAPICH2" MVAPICH2_NAME ${MVAPICH2_TYPE})
132 # Want to check for MVAPICH2 in case some other library supplies mpiname
133 string(REGEX REPLACE "MVAPICH2 \([0-9]+\\.[0-9]*[a-z]?\\.?[0-9]*\)" "\\1" MVAPICH2_VERSION ${MVAPICH2_TYPE})
134 if (${MVAPICH2_NAME} STREQUAL "MVAPICH2" AND MVAPICH2_VERSION VERSION_LESS "1.5")
135 # This test works correctly even with 1.5a1
137 "CMake found MVAPICH2 version ${MVAPICH2_VERSION} on your system. "
138 "There are known problems with GROMACS and MVAPICH2 version < 1.5. "
139 "Please consider updating your MVAPICH2 if your MPI wrapper compilers "
140 "are using the above MVAPICH2 version.")
142 unset(MVAPICH2_VERSION)
145 unset(MVAPICH2_EXEC_RETURN)
148 unset(MPINAME_BIN CACHE)
149 endif () # end if(GMX_LIB_MPI)
151 # Look for MPI process launchers that may be missed, especially if we didn't
152 # need to find the full MPI library build system support.
153 if (NOT MPIEXEC_EXECUTABLE)
155 NAMES mpiexec mpirun lamexec srun aprun poe
156 HINTS ${MPI_HOME} $ENV{MPI_HOME}
158 DOC "Executable for running MPI programs.")
160 set(MPIEXEC_EXECUTABLE "$MPIEXEC")
161 set(MPIEXEC_NUMPROC_FLAG "-np" CACHE STRING "Flag used by MPI to specify the number of processes for MPIEXEC; the next option will be the number of processes.")
162 set(MPIEXEC_PREFLAGS "" CACHE STRING "These flags will be directly before the executable that is being run by MPIEXEC.")
163 set(MPIEXEC_POSTFLAGS "" CACHE STRING "These flags will come after all flags given to MPIEXEC.")
164 set(MPIEXEC_MAX_NUMPROCS "2" CACHE STRING "Maximum number of processors available to run MPI applications.")
165 mark_as_advanced(MPIEXEC MPIEXEC_NUMPROC_FLAG MPIEXEC_PREFLAGS MPIEXEC_POSTFLAGS MPIEXEC_MAX_NUMPROCS)