forked from gromacs/gromacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmxManageMPI.cmake
178 lines (167 loc) · 8.81 KB
/
gmxManageMPI.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#
# This file is part of the GROMACS molecular simulation package.
#
# Copyright 2012- The GROMACS Authors
# and the project initiators Erik Lindahl, Berk Hess and David van der Spoel.
# Consult the AUTHORS/COPYING files and https://www.gromacs.org for details.
#
# GROMACS is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# GROMACS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with GROMACS; if not, see
# https://www.gnu.org/licenses, or write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# If you want to redistribute modifications to GROMACS, please
# consider that scientific software is very special. Version
# control is crucial - bugs must be traceable. We will be happy to
# consider code for inclusion in the official distribution, but
# derived work must not be called official GROMACS. Details are found
# in the README & COPYING files - if they are missing, get the
# official version at https://www.gromacs.org.
#
# To help us fund GROMACS development, we humbly ask that you cite
# the research papers on the package. Check out https://www.gromacs.org.
if (GMX_MPI)
if (GMX_THREAD_MPI)
message(STATUS "MPI is not compatible with thread-MPI. Disabling thread-MPI.")
set(GMX_THREAD_MPI OFF CACHE BOOL
"Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" FORCE)
endif ()
set(GMX_LIB_MPI 1)
else ()
set(GMX_LIB_MPI 0)
endif ()
# If we aren't going to use an MPI library, then don't search for one
if (NOT GMXAPI AND NOT GMX_LIB_MPI)
return()
endif()
# CMake's FindMPI.cmake is not robust enough to cope with a broken MPI
# installation that a GROMACS user might not explicitly want to use,
# but which are searched for because an MPI library is an optional
# dependency of gmxapi even when GROMACS is not built with an MPI
# library.
if (NOT GMX_LIB_MPI AND NOT CMAKE_DISABLE_FIND_PACKAGE_MPI AND NOT MPI_ALREADY_SEARCHED)
message(STATUS "GROMACS is being built without library MPI support (-DGMX_MPI=no). However "
"MPI is potentially useful for the gmxapi Python API, so we will search for MPI anyway. "
"If this causes problems, disable the check with -DCMAKE_DISABLE_FIND_PACKAGE_MPI=on.")
endif()
# Manage the MPI setup.
# Note that we may want to execute tests or Python with MPI,
# even if we are not using an MPI-enabled GROMACS build.
set(MPI_DETERMINE_LIBRARY_VERSION TRUE)
set(GMX_REQUIRED_MPI_COMPONENTS)
if (GMX_LIB_MPI OR GMXAPI)
# If we are building GROMACS against an MPI library, we need the CXX component.
# If the gmxapi interfaces are to be installed, we want to try to help client
# software to find a compatible MPI toolchain, regardless of the libgromacs configuration.
list(APPEND GMX_REQUIRED_MPI_COMPONENTS "CXX")
endif ()
if (GMX_LIB_MPI AND GMX_CP2K)
list(APPEND GMX_REQUIRED_MPI_COMPONENTS "Fortran")
endif ()
# We don't require MPI components here because we report errors elsewhere
# when we can't find a required component, and the MPI target is optional
# in some build configurations (e.g. thread-MPI gmxapi installations).
if (MPI_ALREADY_SEARCHED)
set(MPI_FIND_QUIETLY ON)
endif()
find_package(MPI COMPONENTS ${GMX_REQUIRED_MPI_COMPONENTS})
set(MPI_ALREADY_SEARCHED TRUE CACHE BOOL "True if a search for MPI has already been done")
mark_as_advanced(MPI_ALREADY_SEARCHED)
if (GMX_LIB_MPI)
if (NOT MPI_CXX_FOUND)
message(FATAL_ERROR
"MPI support requested, but no suitable MPI compiler found. Either set the "
"MPI_CXX_COMPILER to the MPI compiler wrapper (often called mpicxx or mpic++), "
"set CMAKE_CXX_COMPILER to a default-MPI-enabled compiler, "
"or set the variables reported missing for MPI_CXX above.")
elseif (MPI_CXX_VERSION VERSION_LESS 3.0)
message(FATAL_ERROR "MPI version 3.0 or higher is required. Please update your MPI library.")
endif ()
#TODO(#3672, #3776): These should be acquired through the MPI::MPI_CXX target.
include_directories(SYSTEM ${MPI_CXX_INCLUDE_PATH})
list(APPEND GMX_COMMON_LIBRARIES ${MPI_CXX_LIBRARIES})
endif ()
# Identify particular MPI implementations of interest (for compatibility checks).
if (MPI_CXX_FOUND)
string(REGEX MATCH ".*Open MPI[:]? [v]?\([0-9]+\\.[0-9]*\\.?[0-9]*\).*" _openmpi_version ${MPI_CXX_LIBRARY_VERSION_STRING})
if (_openmpi_version)
string(REGEX REPLACE ".*Open MPI[:]? [v]?\([0-9]+\\.[0-9]*\\.?[0-9]*\).*" "\\1" OPENMPI_VERSION
${_openmpi_version})
endif ()
string(REGEX MATCH ".*MVAPICH2[:]? [v]?\([0-9]+\\.[0-9]*[a-z]?\\.?[0-9]*\).*" _mvapich2_version ${MPI_CXX_LIBRARY_VERSION_STRING})
if (_mvapich2_version)
string(REGEX REPLACE ".*MVAPICH2[:]? [v]?\([0-9]+\\.[0-9]*[a-z]?\\.?[0-9]*\).*" "\\1" MVAPICH2_VERSION
${_mvapich2_version})
endif ()
unset(_mvapich2_version)
unset(_openmpi_version)
endif ()
# Test for and warn about unsuitable OpenMPI versions.
# TODO(#4093): Update tests with respect to required (compatible) OpenMPI versions.
if (GMX_LIB_MPI AND OPENMPI_VERSION)
if (OPENMPI_VERSION VERSION_EQUAL "1.8.6")
message(WARNING
"CMake found OpenMPI version ${OPENMPI_VERSION} on your system. "
"This OpenMPI version is known to leak memory with GROMACS,"
"please update to a more recent version. ")
endif ()
if (NOT MPI_FIND_QUIETLY)
message(STATUS "GROMACS library will use OpenMPI ${OPENMPI_VERSION}")
endif ()
endif ()
# Test for and warn about unsuitable MPVAPICH2 versions
# TODO(#4093): Update tests with respect to required (compatible) MVAPICH2 versions.
if (GMX_LIB_MPI AND MVAPICH2_VERSION)
if (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 ()
if (NOT MPI_FIND_QUIETLY)
message(STATUS "GROMACS library will use MVAPICH2 ${MVAPICH2_VERSION}")
endif ()
endif ()
# Look for MPI process launchers that may be missed, especially if we didn't
# need to find the full MPI library build system support.
if (NOT MPIEXEC_EXECUTABLE)
find_program(MPIEXEC
NAMES mpiexec mpirun lamexec srun aprun poe
HINTS ${MPI_HOME} $ENV{MPI_HOME}
PATH_SUFFIXES bin
DOC "Executable for running MPI programs.")
set(MPIEXEC_EXECUTABLE "$MPIEXEC")
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.")
set(MPIEXEC_PREFLAGS "" CACHE STRING "These flags will be directly before the executable that is being run by MPIEXEC.")
set(MPIEXEC_POSTFLAGS "" CACHE STRING "These flags will come after all flags given to MPIEXEC.")
set(MPIEXEC_MAX_NUMPROCS "2" CACHE STRING "Maximum number of processors available to run MPI applications.")
mark_as_advanced(MPIEXEC MPIEXEC_NUMPROC_FLAG MPIEXEC_PREFLAGS MPIEXEC_POSTFLAGS MPIEXEC_MAX_NUMPROCS)
endif ()
# MPI library headers tend to be written to compile in either C or
# C++ mode, so both use C-style casts directly and in preprocessor
# defines that then get expanded in GROMACS code. To avoid hiding
# important warnings in the noise, we suppress warnings about
# old-style casts in such builds, relying on other build
# configurations to encourage us to avoid adding C-style casts to
# the code.
if (TARGET MPI::MPI_CXX)
gmx_target_interface_warning_suppression(MPI::MPI_CXX "-Wno-old-style-cast" HAS_WARNING_NO_OLD_STYLE_CAST)
# These next four are similar and only needed by colvars, but
# can't yet be moved there.
gmx_target_interface_warning_suppression(MPI::MPI_CXX "-Wno-cast-qual" HAS_WARNING_NO_CAST_QUAL)
gmx_target_interface_warning_suppression(MPI::MPI_CXX "-Wno-suggest-override" HAS_WARNING_NO_SUGGEST_OVERRIDE)
gmx_target_interface_warning_suppression(MPI::MPI_CXX "-Wno-suggest-destructor-override" HAS_WARNING_NO_SUGGEST_DESTRUCTOR_OVERRIDE)
gmx_target_interface_warning_suppression(MPI::MPI_CXX "-Wno-zero-as-null-pointer-constant" HAS_WARNING_NO_ZERO_AS_NULL_POINTER_CONSTANT)
endif()