From: Alexey Shvetsov Date: Thu, 22 Dec 2016 12:04:33 +0000 (+0300) Subject: Add openmp X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=662e6d243a5bb68a3ae9c198622363fae8b7123d;p=alexxy%2Fgromacs-domains.git Add openmp Signed-off-by: Alexey Shvetsov --- diff --git a/CMakeLists.txt b/CMakeLists.txt index fa48432..4d77447 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # user explicitly sets what they want to get, and then need to provide a suffix # to match. option(GMX_DOUBLE "Use double precision" OFF) +option(GMX_OPENMP "Enable OpenMP-based multithreading" ON) set(GMX_SUFFIX "" CACHE STRING "Suffix for the GROMACS installation to use (empty for default)") # This does not allow for a non-suffixed double-precision libgromacs, but @@ -31,6 +32,7 @@ endif() find_package(GROMACS 2016 REQUIRED) gromacs_check_double(GMX_DOUBLE) gromacs_check_compiler(CXX) +include(gmxManageOpenMP) add_definitions(${GROMACS_DEFINITIONS}) @@ -42,4 +44,12 @@ if (CMAKE_GENERATOR MATCHES "Visual Studio") set(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE) endif() +if(NOT GMX_OPENMP) + #Unset all OpenMP flags in case OpenMP was disabled either by the user + #or because it was only partially detected (e.g. only for C but not C++ compiler) + unset(OpenMP_C_FLAGS CACHE) + unset(OpenMP_CXX_FLAGS CACHE) +endif() + + add_subdirectory(src) diff --git a/cmake/gmxManageOpenMP.cmake b/cmake/gmxManageOpenMP.cmake new file mode 100644 index 0000000..4aad27a --- /dev/null +++ b/cmake/gmxManageOpenMP.cmake @@ -0,0 +1,75 @@ +# +# This file is part of the GROMACS molecular simulation package. +# +# Copyright (c) 2012,2013,2014,2015, 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 OpenMP setup. This wrapper file checks for some known-bad compiler +# versions before trying to detect OpenMP with the standard find-package-module, +# and then does some additional tests for flags afterwards. + +if(GMX_OPENMP) + if(CMAKE_C_COMPILER_ID MATCHES "Cray" AND CMAKE_VERSION VERSION_LESS 3) + message(STATUS "OpenMP multithreading is not detected correctly for the Cray compiler with CMake before version 3.0 (see http://public.kitware.com/Bug/view.php?id=14567)") + set(GMX_OPENMP OFF CACHE BOOL + "OpenMP multithreading is not detected correctly for the Cray compiler with CMake before version 3.0 (see http://public.kitware.com/Bug/view.php?id=14567)" FORCE) + else() + # We should do OpenMP detection if we get here + # OpenMP check must come before other CFLAGS! + find_package(OpenMP) + if(OPENMP_FOUND) + # CMake on Windows doesn't support linker flags passed to target_link_libraries + # (i.e. it treats /openmp as \openmp library file). Also, no OpenMP linker flags are needed. + if(NOT (WIN32 AND NOT MINGW)) + if(CMAKE_COMPILER_IS_GNUCC AND GMX_PREFER_STATIC_OPENMP AND NOT APPLE) + set(OpenMP_LINKER_FLAGS "-Wl,-static -lgomp -lrt -Wl,-Bdynamic -lpthread") + set(OpenMP_SHARED_LINKER_FLAGS "") + else() + # Only set a linker flag if the user didn't set them manually + if(NOT DEFINED OpenMP_LINKER_FLAGS) + set(OpenMP_LINKER_FLAGS "${OpenMP_C_FLAGS}") + endif() + if(NOT DEFINED OpenMP_SHARED_LINKER_FLAGS) + set(OpenMP_SHARED_LINKER_FLAGS "${OpenMP_C_FLAGS}") + endif() + endif() + endif() + if(MINGW) + #GCC Bug 48659 + set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS} -mstackrealign") + endif() + else() + message(WARNING + "The compiler you are using does not support OpenMP parallelism. This might hurt your performance a lot, in particular with GPUs. Try using a more recent version, or a different compiler. For now, we are proceeding by turning off OpenMP.") + set(GMX_OPENMP OFF CACHE STRING "Whether GROMACS will use OpenMP parallelism." FORCE) + endif() + endif() +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 29794d0..825fde8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,5 +3,5 @@ include_directories( ${GROMACS_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include) set_target_properties(domains PROPERTIES - COMPILE_FLAGS "${GROMACS_CXX_FLAGS}") + COMPILE_FLAGS "${GROMACS_CXX_FLAGS} ${OpenMP_C_FLAGS}") target_link_libraries(domains ${GROMACS_LIBRARIES})