Moved OpenMP detection to separate file.
authorErik Lindahl <erik@kth.se>
Thu, 12 Dec 2013 15:58:28 +0000 (16:58 +0100)
committerTeemu Murtola <teemu.murtola@gmail.com>
Mon, 16 Dec 2013 16:29:15 +0000 (18:29 +0200)
This cleans up the main CMakeLists.txt file a bit and
removes manual line breaking from the OpenMP warning
message. It also emphasizes the different parts
(compiler detection, finding package, and final setup)
that are part of the OpenMP detection in Gromacs.

Change-Id: Id13e555d8dac1b5e8bb9c07111a4546a3b438a55

CMakeLists.txt
cmake/gmxManageGPU.cmake
cmake/gmxManageOpenMP.cmake [new file with mode: 0644]

index 3ec50419e184779d56b3cb95f5c2c8e193f01b4e..aa0f47557836b8d73f938c2cefa1ceebb2b5e742 100644 (file)
@@ -270,42 +270,12 @@ endif()
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
 
-# First exclude compilers known to not work with OpenMP although claim to support it:
-# gcc 4.2.1 and gcc-llvm 4.2.1 (also claims to be 4.2.1) on Mac OS X
-# This fixes redmine 900 and needs to run before OpenMP flags are set below.
-if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND
-    (CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION AND CMAKE_C_COMPILER_VERSION VERSION_LESS 4.3))
-    message(STATUS "OpenMP multithreading not supported with gcc/llvm-gcc 4.2 on Mac OS X, disabled")
-    set(GMX_OPENMP OFF CACHE BOOL
-        "OpenMP multithreading not not supported with gcc/llvm-gcc 4.2 on Mac OS X, disabled!" FORCE)
-endif()
+######################################################################
+# Detect OpenMP
+#####################################################################
+# The OpenMP detection must come before tests for other CFLAGS.
+include(gmxManageOpenMP)
 
-# OpenMP check must come before other CFLAGS!
-if(GMX_OPENMP)
-    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 CYGWIN))
-            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()
-    else(OPENMP_FOUND)
-        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(OPENMP_FOUND)
-endif()
 
 
 include(gmxCFlags)
@@ -318,7 +288,8 @@ set(EXTRA_CXX_FLAGS "")
 
 # gcc 4.4.x is buggy and crashes when compiling some files with O3 and OpenMP on.
 # Detect here whether applying a workaround is needed and will apply it later
-# on the affected files.
+# on the affected files. This test must come after gmx_c_flags(), since we
+# only want to enable the workaround when using the -O3 flag.
 include(gmxGCC44O3BugWorkaround)
 gmx_check_gcc44_bug_workaround_needed(GMX_USE_GCC44_BUG_WORKAROUND)
 
index 2c416164cea8df1e0f8c130c524d23cb8e289146..0659db49899b0a7ab11a6e69d3ea8bf57187f644 100644 (file)
@@ -89,35 +89,27 @@ if((GMX_GPU OR GMX_GPU_AUTO) AND NOT GMX_GPU_DETECTION_DONE)
 
     # assemble warning/error message
     if (GMX_DETECT_GPU_AVAILABLE)
-        set(_msg "
-    ${GMX_DETECT_GPU_COUNT} NVIDIA GPU(s) found in the system")
+        set(_msg "${GMX_DETECT_GPU_COUNT} NVIDIA GPU(s) found in the system")
 
         # append GPU names
         if (NOT GMX_DETECT_GPU_INFO STREQUAL "")
             set(_msg "${_msg}:")
             foreach(gpu ${GMX_DETECT_GPU_INFO})
                 set(_msg "${_msg}
-                ${gpu}")
+${gpu}")
             endforeach()
         endif()
 
         # TODO remove the second part of the message when we'll have compute
         # capability information from the detection.
         set(_msg "${_msg}
-    Compute capability information not available, consult the NVIDIA website:
-    https://developer.nvidia.com/cuda-gpus
-            ")
+Compute capability information not available, consult the NVIDIA website:
+https://developer.nvidia.com/cuda-gpus")
     endif()
 
-        set(CUDA_NOTFOUND_MESSAGE "
-    mdrun supports native GPU acceleration on NVIDIA hardware with compute
-    capability >=2.0 (Fermi or later). This requires the NVIDIA CUDA toolkit,
-    which was not found. Its location can be hinted by setting the
-    CUDA_TOOLKIT_ROOT_DIR CMake option (does not work as an environment variable).
-    The typical location would be /usr/local/cuda[-version].
-    Note that CPU or GPU acceleration can be selected at runtime!
+        set(CUDA_NOTFOUND_MESSAGE "mdrun supports native GPU acceleration on NVIDIA hardware with compute capability >=2.0 (Fermi or later). This requires the NVIDIA CUDA toolkit, which was not found. Its location can be hinted by setting the CUDA_TOOLKIT_ROOT_DIR CMake option (does not work as an environment variable). The typical location would be /usr/local/cuda[-version]. Note that CPU or GPU acceleration can be selected at runtime.
 
-    ${_msg}")
+${_msg}")
         unset(_msg)
 
     if (NOT CUDA_FOUND)
@@ -193,11 +185,6 @@ macro(gmx_gpu_setup)
 
     # no OpenMP is no good!
     if(NOT GMX_OPENMP)
-        message(WARNING "
-    To use GPU acceleration efficiently, mdrun requires OpenMP multi-threading.
-    Without OpenMP a single CPU core can be used with a GPU which is not optimal.
-    Note that with MPI multiple processes can be forced to use a single GPU, but this
-    typically inefficient. Note that you need to set both C and C++ compilers that
-    support OpenMP (CC and CXX environment variables, respectively) when using GPUs.")
+        message(WARNING "To use GPU acceleration efficiently, mdrun requires OpenMP multi-threading. Without OpenMP a single CPU core can be used with a GPU which is not optimal. Note that with MPI multiple processes can be forced to use a single GPU, but this is typically inefficient. You need to set both C and C++ compilers that support OpenMP (CC and CXX environment variables, respectively) when using GPUs.")
     endif()
 endmacro()
diff --git a/cmake/gmxManageOpenMP.cmake b/cmake/gmxManageOpenMP.cmake
new file mode 100644 (file)
index 0000000..d7b5589
--- /dev/null
@@ -0,0 +1,75 @@
+#
+# This file is part of the GROMACS molecular simulation package.
+#
+# Copyright (c) 2012,2013, 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.
+
+# First exclude compilers known to not work with OpenMP although claim to support it:
+# gcc 4.2.1 and gcc-llvm 4.2.1 (also claims to be 4.2.1) on Mac OS X
+# This fixes redmine 900 and needs to run before OpenMP flags are set below.
+if(GMX_OPENMP)
+    if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND
+        (CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION AND CMAKE_C_COMPILER_VERSION VERSION_LESS 4.3))
+        message(STATUS "OpenMP multithreading not supported with gcc/llvm-gcc 4.2 on Mac OS X, disabled")
+        set(GMX_OPENMP OFF CACHE BOOL
+            "OpenMP multithreading not not supported with gcc/llvm-gcc 4.2 on Mac OS X, disabled!" 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 CYGWIN))
+                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()
+        else(OPENMP_FOUND)
+            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(OPENMP_FOUND)
+    endif()
+endif()