2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2012, by the GROMACS development team, led by
5 # David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 # others, as listed in the AUTHORS file in the top-level source
7 # directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 # Manage the MPI setup, assuming that CMAKE_C_COMPILER is an MPI
39 message(STATUS "MPI is not compatible with thread-MPI. Disabling thread-MPI.")
40 set(GMX_THREAD_MPI OFF CACHE BOOL
41 "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" FORCE)
44 # Test the CMAKE_C_COMPILER for being an MPI (wrapper) compiler
45 TRY_COMPILE(MPI_FOUND ${CMAKE_BINARY_DIR}
46 "${CMAKE_SOURCE_DIR}/cmake/TestMPI.c"
49 # If CMAKE_C_COMPILER is not a MPI wrapper. Try to find MPI using cmake module as fall-back.
50 # cmake < 2.8.5 not recommended for fall-back because of unreliability (redmine #851)
52 if(CMAKE_VERSION VERSION_LESS "2.8.5")
58 if(${${MPI_PREFIX}_FOUND})
59 set(MPI_COMPILE_FLAGS ${${MPI_PREFIX}_COMPILE_FLAGS})
60 set(MPI_LINKER_FLAGS ${${MPI_PREFIX}_LINK_FLAGS})
61 include_directories(${${MPI_PREFIX}_INCLUDE_PATH})
62 list(APPEND GMX_EXTRA_LIBRARIES ${${MPI_PREFIX}_LIBRARIES})
64 set(MPI_FOUND ${${MPI_PREFIX}_FOUND})
68 include(gmxTestMPI_IN_PLACE)
70 gmx_test_mpi_in_place(MPI_IN_PLACE_EXISTS)
73 # Find path of the mpi compilers
74 if (${${MPI_PREFIX}_FOUND})
75 get_filename_component(_mpi_c_compiler_path "${MPI_C_COMPILER}" PATH)
76 get_filename_component(_mpiexec_path "${MPIEXEC}" 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 # Test for and warn about unsuitable MPI versions
84 # Execute the ompi_info binary with the full path of the compiler wrapper
85 # found, otherwise we run the risk of false positives.
86 find_file(MPI_INFO_BIN ompi_info
87 HINTS ${_mpi_c_compiler_path} ${_mpiexec_path}
88 ${_cmake_c_compiler_path} ${_cmake_cxx_compiler_path}
90 NO_SYSTEM_ENVIRONMENT_PATH
93 exec_program(${MPI_INFO_BIN}
95 OUTPUT_VARIABLE OPENMPI_TYPE
96 RETURN_VALUE OPENMPI_EXEC_RETURN)
97 if(OPENMPI_EXEC_RETURN EQUAL 0)
98 string(REGEX REPLACE ".*Open MPI: \([0-9]+\\.[0-9]*\\.?[0-9]*\).*" "\\1" OPENMPI_VERSION ${OPENMPI_TYPE})
99 if(OPENMPI_VERSION VERSION_LESS "1.4.1")
101 "CMake found OpenMPI version ${OPENMPI_VERSION} on your system. "
102 "There are known problems with GROMACS and OpenMPI version < 1.4.1. "
103 "Please consider updating your OpenMPI if your MPI wrapper compilers "
104 "are using the above OpenMPI version.")
106 unset(OPENMPI_VERSION)
108 unset(OPENMPI_EXEC_RETURN)
111 unset(MPI_INFO_BIN CACHE)
113 # Execute the mpiname binary with the full path of the compiler wrapper
114 # found, otherwise we run the risk of false positives.
115 find_file(MPINAME_BIN mpiname
116 HINTS ${_mpi_c_compiler_path}
117 ${_cmake_c_compiler_path} ${_cmake_cxx_compiler_path}
119 NO_SYSTEM_ENVIRONMENT_PATH
120 NO_CMAKE_SYSTEM_PATH)
122 exec_program(${MPINAME_BIN}
124 OUTPUT_VARIABLE MVAPICH2_TYPE
125 RETURN_VALUE MVAPICH2_EXEC_RETURN)
126 if(MVAPICH2_EXEC_RETURN EQUAL 0)
127 string(REGEX MATCH "MVAPICH2" MVAPICH2_NAME ${MVAPICH2_TYPE})
128 # Want to check for MVAPICH2 in case some other library supplies mpiname
129 string(REGEX REPLACE "MVAPICH2 \([0-9]+\\.[0-9]*[a-z]?\\.?[0-9]*\)" "\\1" MVAPICH2_VERSION ${MVAPICH2_TYPE})
130 if(${MVAPICH2_NAME} STREQUAL "MVAPICH2" AND MVAPICH2_VERSION VERSION_LESS "1.5")
131 # This test works correctly even with 1.5a1
133 "CMake found MVAPICH2 version ${MVAPICH2_VERSION} on your system. "
134 "There are known problems with GROMACS and MVAPICH2 version < 1.5. "
135 "Please consider updating your MVAPICH2 if your MPI wrapper compilers "
136 "are using the above MVAPICH2 version.")
138 unset(MVAPICH2_VERSION)
141 unset(MVAPICH2_EXEC_RETURN)
144 unset(MPINAME_BIN CACHE)
147 if (CMAKE_VERSION VERSION_LESS "2.8.5")
149 "MPI support requested, but no MPI compiler found. Either set the "
150 "C-compiler (CMAKE_C_COMPILER) to the MPI compiler (often called mpicc), "
151 "or use a newer cmake version (>=2.8.5) which has improved MPI detection.")
154 "MPI support requested, but no MPI compiler found. Either set the "
155 "C-compiler (CMAKE_C_COMPILER) to the MPI compiler (often called mpicc), "
156 "or set the variables reported missing for MPI_C above.")
161 include(gmxTestCatamount)
162 gmx_test_catamount(GMX_CRAY_XT3)
164 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_CRAY_XT3")
170 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_LIB_MPI")