Fix grompp .edr IO estimate for free-energy calcs
[alexxy/gromacs.git] / cmake / gmxManageFFTLibraries.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
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.
13 #
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.
18 #
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.
23 #
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.
31 #
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.
34
35 # Manage setup of the different FFT libraries we can use in Gromacs.
36 set(PKG_FFT "")
37 set(PKG_FFT_LIBS "")
38 # Intel 11 and up makes life somewhat easy if you just want to use
39 # all their stuff. It's not easy if you only want some of their
40 # stuff...
41 set(MKL_MANUALLY FALSE)
42 if (GMX_FFT_LIBRARY STREQUAL "MKL" AND
43     NOT (CMAKE_C_COMPILER_ID MATCHES "Intel" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "11"))
44     # The user will have to provide the set of magic libraries in
45     # MKL_LIBRARIES (see below), which we cache (non-advanced), so that they
46     # don't have to keep specifying it, and can easily see that
47     # CMake is still using that information.
48     set(MKL_MANUALLY TRUE)
49 endif()
50 set(MKL_LIBRARIES_FORMAT_DESCRIPTION "Use full paths to library files, in the right order, and separated by semicolons.")
51 gmx_dependent_cache_variable(
52     MKL_LIBRARIES
53     "List of libraries for linking to MKL. ${MKL_LIBRARIES_FORMAT_DESCRIPTION}"
54     STRING ""
55     MKL_MANUALLY)
56 gmx_dependent_cache_variable(
57     MKL_INCLUDE_DIR
58     "Path to mkl.h (non-inclusive)."
59     PATH ""
60     MKL_MANUALLY)
61 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
62     if(GMX_DOUBLE)
63         set(FFTW fftw)
64     else()
65         set(FFTW fftwf)
66     endif()
67
68     # Note that these calls are expected to function the same way,
69     # particularly with respect to setting CMake variables that
70     # record the presence of particular FFTW SIMD support.
71     # TODO There is no need for this requirement, all the remaining
72     # code here can be refactored to have just one check of
73     # GMX_BUILD_OWN_FFTW, which simplifies both code paths.
74     if(GMX_BUILD_OWN_FFTW)
75       add_subdirectory(src/contrib/fftw)
76     else()
77       find_package(FFTW COMPONENTS ${FFTW})
78     endif()
79
80     string(TOUPPER "${FFTW}" FFTW)
81     if(NOT ${FFTW}_FOUND)
82       MESSAGE(FATAL_ERROR "Cannot find FFTW 3 (with correct precision - libfftw3f for mixed-precision GROMACS or libfftw3 for double-precision GROMACS). Either choose the right precision, choose another FFT(W) library (-DGMX_FFT_LIBRARY), enable the advanced option to let GROMACS build FFTW 3 for you (-GMX_BUILD_OWN_FFTW=ON), or use the really slow GROMACS built-in fftpack library (-DGMX_FFT_LIBRARY=fftpack).")
83     endif()
84
85     set(PKG_FFT "${${FFTW}_PKG}")
86     if (GMX_BUILD_OWN_FFTW)
87         include_directories(BEFORE ${${FFTW}_INCLUDE_DIRS})
88     else()
89         include_directories(${${FFTW}_INCLUDE_DIRS})
90     endif()
91     set(FFT_LIBRARIES ${${FFTW}_LIBRARIES})
92     set(GMX_FFT_FFTW3 1)
93
94     if ((${GMX_SIMD} MATCHES "SSE" OR ${GMX_SIMD} MATCHES "AVX") AND NOT ${FFTW}_HAVE_SIMD)
95       message(WARNING "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin")
96     else()
97       if(${GMX_SIMD} MATCHES "AVX" AND NOT (${FFTW}_HAVE_SSE OR ${FFTW}_HAVE_SSE2 OR ${FFTW}_HAVE_AVX_128 OR ${FFTW}_HAVE_AVX2_128))
98         # If we end up here we have an AVX Gromacs build, and FFTW with SIMD, but no 128-bit SIMD, this means AVX is enabled for FFTW.
99         message(WARNING "The FFTW library was compiled with neither --enable-sse nor --enable-sse2; those would have enabled SSE(2) SIMD instructions. This will give suboptimal performance. You should (re)compile the FFTW library with both SSE2 and AVX instruction support (use both --enable-sse2 and --enable-avx). The FFTW library will determine at runtime which SIMD instruction set is fastest for different parts of the FFTs.")
100         endif()
101     endif()
102
103     set(FFT_STATUS_MESSAGE "Using external FFT library - FFTW3")
104 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
105     # Intel 11 and up makes life somewhat easy if you just want to use
106     # all their stuff. It's not easy if you only want some of their
107     # stuff...
108     if (NOT MKL_MANUALLY)
109         # The next line takes care of everything for MKL
110         if (WIN32)
111             # This works according to the Intel MKL 10.3 for Windows
112             # docs, but on Jenkins Win2k8, icl tries to interpret it
113             # as a file. Shrug.
114             set(FFT_LINKER_FLAGS "/Qmkl:sequential")
115         else()
116             set(FFT_LINKER_FLAGS "-mkl=sequential")
117         endif()
118         # Some versions of icc require this in order that mkl.h can be
119         # found at compile time.
120         set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} ${FFT_LINKER_FLAGS}")
121
122         set(MKL_ERROR_MESSAGE "Make sure you have configured your compiler so that ${FFT_LINKER_FLAGS} will work.")
123     else()
124         include_directories(${MKL_INCLUDE_DIR})
125         set(FFT_LIBRARIES "${MKL_LIBRARIES}")
126         set(MKL_ERROR_MESSAGE "The include path to mkl.h in MKL_INCLUDE_DIR, and the link libraries in MKL_LIBRARIES=${MKL_LIBRARIES} need to match what the MKL documentation says you need for your system: ${MKL_LIBRARIES_FORMAT_DESCRIPTION}")
127         # Convert the semi-colon separated list to a list of
128         # command-line linker arguments so that code using our
129         # pkgconfig setup can use it.
130         string(REGEX REPLACE ";" " " PKG_FFT_LIBS "${MKL_LIBRARIES}")
131     endif()
132
133     # Check MKL works. If we were in a non-global scope, we wouldn't
134     # have to play nicely.
135     set(old_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
136     set(CMAKE_REQUIRED_FLAGS "${FFT_LINKER_FLAGS}")
137     set(old_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
138     set(CMAKE_REQUIRED_LIBRARIES "${FFT_LIBRARIES}")
139
140     check_function_exists(DftiCreateDescriptor TEST_MKL)
141
142     set(CMAKE_REQUIRED_FLAGS "${old_CMAKE_REQUIRED_FLAGS}")
143     set(CMAKE_REQUIRED_LIBRARIES "${old_CMAKE_REQUIRED_LIBRARIES}")
144
145     if(NOT TEST_MKL)
146         # Hack to help the user vary MKL settings until they work.
147         # TODO Make this logic more useful.
148         unset(TEST_MKL CACHE)
149         message(FATAL_ERROR "Linking with MKL was requested, but was not successful: ${MKL_ERROR_MESSAGE}")
150     endif()
151
152     # Set variables to signal that we have MKL available and should use it for FFTs.
153     set(GMX_FFT_MKL 1)
154     set(HAVE_LIBMKL 1)
155
156     set(FFT_STATUS_MESSAGE "Using external FFT library - Intel MKL")
157 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
158     set(GMX_FFT_FFTPACK 1)
159     set(FFT_STATUS_MESSAGE "Using internal FFT library - fftpack")
160 else()
161     gmx_invalid_option_value(GMX_FFT_LIBRARY)
162 endif()
163 gmx_check_if_changed(FFT_CHANGED GMX_FFT_LIBRARY)
164 if (FFT_CHANGED)
165     message(STATUS "${FFT_STATUS_MESSAGE}")
166 endif()
167
168 # enable threaded fftw3 if we've found it
169 if(FFTW3_THREADS OR FFTW3F_THREADS)
170     add_definitions(-DFFT5D_FFTW_THREADS)
171 endif()
172