forked from GOMC-WSU/GOMC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GOMCManageMPI.cmake
176 lines (166 loc) · 7.98 KB
/
GOMCManageMPI.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
#
# This file is part of the GROMACS molecular simulation package.
#
# Copyright (c) 2012,2013,2014,2015,2016,2019, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
#
# 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
# http://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 http://www.gromacs.org.
#
# To help us fund GROMACS development, we humbly ask that you cite
# the research papers on the package. Check out http://www.gromacs.org.
# Manage the MPI setup, assuming that CMAKE_C_COMPILER is an MPI
# (wrapper) compiler.
if(GOMC_MPI)
if(GOMC_THREAD_MPI)
message(STATUS "MPI is not compatible with thread-MPI. Disabling thread-MPI.")
set(GOMC_THREAD_MPI OFF CACHE BOOL
"Build a thread-MPI-based multithreaded version of GOMC (not compatible with MPI)" FORCE)
endif()
# Test the CMAKE_C_COMPILER for being an MPI (wrapper) compiler
TRY_COMPILE(MPI_FOUND ${CMAKE_BINARY_DIR}
"${CMAKE_SOURCE_DIR}/CMake/TestMPI.cpp"
COMPILE_DEFINITIONS )
# If CMAKE_C_COMPILER is not a MPI wrapper. Try to find MPI using cmake module as fall-back.
if(NOT MPI_FOUND)
find_package(MPI)
if(MPI_C_FOUND)
set(MPI_COMPILE_FLAGS ${MPI_C_COMPILE_FLAGS})
set(MPI_LINKER_FLAGS ${MPI_C_LINK_FLAGS})
include_directories(SYSTEM ${MPI_C_INCLUDE_PATH})
list(APPEND GOMC_COMMON_LIBRARIES ${MPI_C_LIBRARIES})
endif()
set(MPI_FOUND ${MPI_C_FOUND})
else()
# The following defaults are based on FindMPI.cmake in cmake
# 3.1.2. (That package does not actually do any detection of the
# flags, but if it ever does then we should re-visit how we use
# the package.) If we are compiling with an MPI wrapper
# compiler, then MPI_FOUND will be set above, and will mean that
# none of these cache variables are populated by the package. We
# need to do it manually so that test drivers can work using the
# standard machinery for CMake + FindMPI.cmake. Users will need
# to set these to suit their MPI setup in order for tests to
# work.
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_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()
if(MPI_FOUND)
include(${PROJECT_SOURCE_DIR}/CMake/GOMCTestMPI_IN_PLACE.cmake)
if (GOMC_MPI_IN_PLACE)
GOMC_test_mpi_in_place(MPI_IN_PLACE_EXISTS)
endif()
# Find path of the mpi compilers
if (${MPI_C_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
#
# 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 GOMC and OpenMPI version < 1.4.1. "
"Please consider updating your OpenMPI if your MPI wrapper compilers "
"are using the above OpenMPI version.")
endif()
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 GOMC,"
"please update to a more recent version. ")
endif()
unset(OPENMPI_VERSION)
unset(OPENMPI_TYPE)
unset(OPENMPI_EXEC_RETURN)
endif()
endif()
unset(MPI_INFO_BIN CACHE)
# 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 GOMC 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()
endif()
unset(MPINAME_BIN CACHE)
else()
message(FATAL_ERROR
"MPI support requested, but no MPI compiler found. Either set the "
"C-compiler (CMAKE_C_COMPILER) to the MPI compiler (often called mpicc), "
"or set the variables reported missing for MPI_C above.")
endif()
set(GOMC_LIB_MPI 1)
endif()