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 set(MPI_DETERMINE_LIBRARY_VERSION TRUE)
51 set(GMX_REQUIRED_MPI_COMPONENTS)
52 if (GMX_LIB_MPI OR GMXAPI)
53 # If we are building GROMACS against an MPI library, we need the CXX component.
54 # If the gmxapi interfaces are to be installed, we want to try to help client
55 # software to find a compatible MPI toolchain, regardless of the libgromacs configuration.
56 list(APPEND GMX_REQUIRED_MPI_COMPONENTS "CXX")
58 if (GMX_LIB_MPI AND GMX_CP2K)
59 list(APPEND GMX_REQUIRED_MPI_COMPONENTS "Fortran")
61 # We don't require MPI components here because we report errors elsewhere
62 # when we can't find a required component, and the MPI target is optional
63 # in some build configurations (e.g. thread-MPI gmxapi installations).
64 if (MPI_ALREADY_SEARCHED)
65 set(MPI_FIND_QUIETLY ON)
67 find_package(MPI COMPONENTS ${GMX_REQUIRED_MPI_COMPONENTS})
68 set(MPI_ALREADY_SEARCHED TRUE CACHE BOOL "True if a search for MPI has already been done")
69 mark_as_advanced(MPI_ALREADY_SEARCHED)
72 if (NOT MPI_CXX_FOUND)
74 "MPI support requested, but no suitable MPI compiler found. Either set the "
75 "MPI_CXX_COMPILER to the MPI compiler wrapper (often called mpicxx or mpic++), "
76 "set CMAKE_CXX_COMPILER to a default-MPI-enabled compiler, "
77 "or set the variables reported missing for MPI_CXX above.")
78 elseif (MPI_CXX_VERSION VERSION_LESS 2.0)
79 message(FATAL_ERROR "MPI version 2.0 or higher is required. Please update your MPI library.")
81 #TODO(#3672, #3776): These should be acquired through the MPI::MPI_CXX target.
82 include_directories(SYSTEM ${MPI_CXX_INCLUDE_PATH})
83 list(APPEND GMX_COMMON_LIBRARIES ${MPI_CXX_LIBRARIES})
86 # Identify particular MPI implementations of interest (for compatibility checks).
88 string(REGEX MATCH ".*Open MPI[:]? [v]?\([0-9]+\\.[0-9]*\\.?[0-9]*\).*" _openmpi_version ${MPI_CXX_LIBRARY_VERSION_STRING})
90 string(REGEX REPLACE ".*Open MPI[:]? [v]?\([0-9]+\\.[0-9]*\\.?[0-9]*\).*" "\\1" OPENMPI_VERSION
93 string(REGEX MATCH ".*MVAPICH2[:]? [v]?\([0-9]+\\.[0-9]*[a-z]?\\.?[0-9]*\).*" _mvapich2_version ${MPI_CXX_LIBRARY_VERSION_STRING})
94 if (_mvapich2_version)
95 string(REGEX REPLACE ".*MVAPICH2[:]? [v]?\([0-9]+\\.[0-9]*[a-z]?\\.?[0-9]*\).*" "\\1" MVAPICH2_VERSION
98 unset(_mvapich2_version)
99 unset(_openmpi_version)
102 # Test for and warn about unsuitable OpenMPI versions.
103 # TODO(#4093): Update tests with respect to required (compatible) OpenMPI versions.
104 if (GMX_LIB_MPI AND OPENMPI_VERSION)
105 if (OPENMPI_VERSION VERSION_LESS "1.4.1")
107 "CMake found OpenMPI version ${OPENMPI_VERSION} on your system. "
108 "There are known problems with GROMACS and OpenMPI version < 1.4.1. "
109 "Please consider updating your OpenMPI if your MPI wrapper compilers "
110 "are using the above OpenMPI version.")
112 if (OPENMPI_VERSION VERSION_EQUAL "1.8.6")
114 "CMake found OpenMPI version ${OPENMPI_VERSION} on your system. "
115 "This OpenMPI version is known to leak memory with GROMACS,"
116 "please update to a more recent version. ")
118 if (NOT MPI_FIND_QUIETLY)
119 MESSAGE(STATUS "GROMACS library will use OpenMPI ${OPENMPI_VERSION}")
123 # Test for and warn about unsuitable MPVAPICH2 versions
124 # TODO(#4093): Update tests with respect to required (compatible) MVAPICH2 versions.
125 if (GMX_LIB_MPI AND MVAPICH2_VERSION)
126 if (MVAPICH2_VERSION VERSION_LESS "1.5")
127 # This test works correctly even with 1.5a1
129 "CMake found MVAPICH2 version ${MVAPICH2_VERSION} on your system. "
130 "There are known problems with GROMACS and MVAPICH2 version < 1.5. "
131 "Please consider updating your MVAPICH2 if your MPI wrapper compilers "
132 "are using the above MVAPICH2 version.")
134 if (NOT MPI_FIND_QUIETLY)
135 MESSAGE(STATUS "GROMACS library will use MVAPICH2 ${MVAPICH2_VERSION}")
139 # Look for MPI process launchers that may be missed, especially if we didn't
140 # need to find the full MPI library build system support.
141 if (NOT MPIEXEC_EXECUTABLE)
143 NAMES mpiexec mpirun lamexec srun aprun poe
144 HINTS ${MPI_HOME} $ENV{MPI_HOME}
146 DOC "Executable for running MPI programs.")
148 set(MPIEXEC_EXECUTABLE "$MPIEXEC")
149 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.")
150 set(MPIEXEC_PREFLAGS "" CACHE STRING "These flags will be directly before the executable that is being run by MPIEXEC.")
151 set(MPIEXEC_POSTFLAGS "" CACHE STRING "These flags will come after all flags given to MPIEXEC.")
152 set(MPIEXEC_MAX_NUMPROCS "2" CACHE STRING "Maximum number of processors available to run MPI applications.")
153 mark_as_advanced(MPIEXEC MPIEXEC_NUMPROC_FLAG MPIEXEC_PREFLAGS MPIEXEC_POSTFLAGS MPIEXEC_MAX_NUMPROCS)