Merge release-4-6 into master
authorRoland Schulz <roland@utk.edu>
Mon, 12 Nov 2012 23:45:33 +0000 (18:45 -0500)
committerRoland Schulz <roland@utk.edu>
Mon, 12 Nov 2012 23:45:33 +0000 (18:45 -0500)
Conflicts:
CMakeLists.txt

Change-Id: I42951043675af21763778a3022403166f8cc70e0

1  2 
CMakeLists.txt
src/config.h.cmakein
src/gromacs/legacyheaders/gmx_math_x86_avx_128_fma_single.h
src/gromacs/mdlib/nbnxn_atomdata.c

diff --combined CMakeLists.txt
index 356f6ce19f70816f61e40e399730c66f4fb2c943,3262247f85a43222e0daf343eff51f45a241b3b7..46a2e31c6dfbbf8231e3855fa8707f7177165110
@@@ -2,19 -2,19 +2,19 @@@ cmake_minimum_required(VERSION 2.8
  # Keep CMake suitably quiet on Cygwin
  set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
  
 -# Allows CPack to act differently for normal tools and mdrun (e.g. because of MPI)
 -set(CPACK_COMPONENT_GROUP_TOOLS_DESCRIPTION "All GROMACS executable tools")
 -set(CPACK_COMPONENT_GROUP_MDRUN_DESCRIPTION "GROMACS executable for running simulations")
 -
  # override bugs on OS X where Cmake picks gcc (GNU) for C instead of system default cc (Clang).
  if(APPLE)
      set(CMAKE_C_COMPILER_INIT "cc")
  endif(APPLE)
  
 -project(Gromacs C)
 +project(Gromacs)
  include(Dart)
  mark_as_advanced(DART_ROOT)
  
 +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
 +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
 +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
 +
  # PROJECT_VERSION should have the following structure: 
  # VERSION-dev[-SUFFIX] where the VERSION should have the for: vMajor.vMinor.vPatch
  #
@@@ -23,7 -23,7 +23,7 @@@
  # machine with no git. 
  #
  # NOTE: when releasing the "-dev" suffix needs to be stripped off!
 -set(PROJECT_VERSION "4.6-dev")
 +set(PROJECT_VERSION "5.0-dev")
  set(CUSTOM_VERSION_STRING ""
      CACHE STRING "Custom version string (if empty, use hard-coded default)")
  mark_as_advanced(CUSTOM_VERSION_STRING)
@@@ -32,8 -32,8 +32,8 @@@ if (CUSTOM_VERSION_STRING
  endif (CUSTOM_VERSION_STRING)
  set(SOVERSION 6)
  # It is a bit irritating, but this has to be set separately for now!
 -SET(CPACK_PACKAGE_VERSION_MAJOR "4")
 -SET(CPACK_PACKAGE_VERSION_MINOR "6")
 +SET(CPACK_PACKAGE_VERSION_MAJOR "5")
 +SET(CPACK_PACKAGE_VERSION_MINOR "0")
  #SET(CPACK_PACKAGE_VERSION_PATCH "0")
  
  # The numerical gromacs version. It is 40600 for 4.6.0.
@@@ -56,22 -56,24 +56,22 @@@ set(API_VERSION ${NUM_VERSION}
  set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
  
  if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
 -set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
 +    set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
  endif()
  
 +set(GMX_INSTALL_PREFIX "" CACHE STRING "Prefix gets appended to CMAKE_INSTALL_PREFIX. For cpack it sets the root folder of the archive.")
 +mark_as_advanced(GMX_INSTALL_PREFIX)
 +
  if(NOT CMAKE_BUILD_TYPE)
      set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
  endif(NOT CMAKE_BUILD_TYPE)
  
  enable_language(C)
 -
 -set(GMX_USE_RELATIVE_INSTALL_PATH OFF CACHE STRING "Use relative paths not absolute paths for cmake install. Has only an effect on cpack.")
 -mark_as_advanced(GMX_USE_RELATIVE_INSTALL_PATH)
 +enable_language(CXX)
  
  set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
  set(CPACK_PACKAGE_VENDOR "gromacs.org")
  set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gromacs - a toolkit for high-performance molecular simulation")
 -if (NOT GMX_USE_RELATIVE_INSTALL_PATH)
 -    set(CPACK_SET_DESTDIR "ON")
 -endif()
  set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/admin/InstallWelcome.txt")
  # Its GPL/LGPL, so they do not have to agree to a license for mere usage, but some installers require this...
  set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
@@@ -84,11 -86,6 +84,11 @@@ set(CPACK_PACKAGE_CONTACT "gmx-users@gr
  #must come after all cpack settings!
  include(CPack)
  
 +set(SOURCE_IS_GIT_REPOSITORY OFF)
 +if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
 +    set(SOURCE_IS_GIT_REPOSITORY ON)
 +endif()
 +
  ########################################################################
  # Check and warn if cache generated on a different host is being reused
  ########################################################################
@@@ -106,6 -103,17 +106,6 @@@ if(CMAKE_HOST_UNIX
              "Hostname of the machine where the cache was generated.")
  endif()
  
 -########################################################################
 -# User input options - enable C++ - before any CXX flags are changed   #
 -########################################################################
 -option(GMX_GPU  "Enable GPU acceleration" ON)
 -option(GMX_OPENMM "Accelerated execution on GPUs through the OpenMM library (rerun cmake after changing to see relevant options)" OFF)
 -option(GMX_FORCE_CXX "Enable C++ compilation even if not necessary" OFF)
 -mark_as_advanced(GMX_FORCE_CXX)
 -if(GMX_GPU OR GMX_OPENMM OR GMX_FORCE_CXX)
 -    enable_language(CXX)
 -endif()
 -
  ########################################################################
  # Fix stupid flags on Windows
  ########################################################################
@@@ -114,9 -122,6 +114,9 @@@ IF( WIN32 AND NOT CYGWIN
    option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static system libraries (MT instead of MD)!" ON)
    mark_as_advanced(GMX_PREFER_STATIC_LIBS)
    SET(SHARED_LIBS_DEFAULT OFF)  #is currently not working on Windows
 +  # This makes windows.h not declare min/max as macros that would break
 +  # C++ code using std::min/std::max.
 +  add_definitions(-DNOMINMAX)
  
    IF (GMX_PREFER_STATIC_LIBS)
      #Only setting Debug and Release flags. Others configurations current not used.
      SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
      STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
      SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
 -    if(CMAKE_CXX_COMPILER_LOADED)
 -        STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
 -        SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
 -        STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
 -        SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
 -    endif()
 +    STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
 +    SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
 +    STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
 +    SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
    ENDIF()
  
    #Workaround for cmake bug 13174. Replace deprecated options.
      STRING(REPLACE /GZ /RTC1 CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
      SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
    ENDIF()
 -  IF( CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND CMAKE_CXX_COMPILER_LOADED)
 +  IF( CMAKE_CXX_COMPILER_ID MATCHES "Intel" )
      STRING(REPLACE /GZ /RTC1 CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
      STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
      SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
@@@ -158,7 -165,6 +158,7 @@@ option(GMX_POWERPC_INVSQRT "Use PowerP
  mark_as_advanced(GMX_POWERPC_INVSQRT)
  option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
  mark_as_advanced(GMX_FAHCORE)
 +option(GMX_OPENMM "Accelerated execution on GPUs through the OpenMM library (rerun cmake after changing to see relevant options)" OFF)
  
  include(gmxDetectAcceleration)
  if(NOT DEFINED GMX_ACCELERATION)
@@@ -186,16 -192,12 +186,16 @@@ mark_as_advanced(GMX_MPI_IN_PLACE
  option(GMX_LOAD_PLUGINS "Compile with plugin support, needed to read VMD supported file formats" ON)
  mark_as_advanced(GMX_LOAD_PLUGINS)
  
 +option(GMX_GPU  "Enable GPU acceleration" ON)
  option(GMX_OPENMP "Enable OpenMP-based multithreading" ON)
  
 -option(USE_VERSION_H "Generate development version string/information" ON)
 -mark_as_advanced(USE_VERSION_H)
 +option(GMX_GIT_VERSION_INFO "Generate git version information" ${SOURCE_IS_GIT_REPOSITORY})
 +mark_as_advanced(GMX_GIT_VERSION_INFO)
  
  option(GMX_DEFAULT_SUFFIX "Use default suffixes for GROMACS binaries and libs (_d for double, _mpi for MPI; rerun cmake after changing to see relevant options)" ON)
 +if(UNIX)
 +    option(GMX_SYMLINK_OLD_BINARY_NAMES "Create symbolic links for pre-5.0 binary names" ON)
 +endif()
  
  if(UNIX)
      option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static archives (not available on non-*nix platforms and it will only work if static versions of external dependencies are available and found)!" OFF)
@@@ -216,7 -218,9 +216,7 @@@ mark_as_advanced(GMX_CYCLE_SUBCOUNTERS
  # Remove these files from the source tree when a CMake version that
  # includes the features in question becomes required.
  include(CheckCCompilerFlag)
 -if(CMAKE_CXX_COMPILER_LOADED)
 -    include(CheckCXXCompilerFlag)
 -endif()
 +include(CheckCXXCompilerFlag)
  
  # OpenMP check must come before other CFLAGS!
  if(GMX_OPENMP)
@@@ -364,26 -368,38 +364,26 @@@ endif(GMX_OPENMM
  # Basic system tests (standard libraries, headers, functions, types)   #
  ########################################################################
  include(CheckIncludeFiles)
 -check_include_files(string.h     HAVE_STRING_H)
 -check_include_files(math.h       HAVE_MATH_H)
 -check_include_files(limits.h     HAVE_LIMITS_H)
 -check_include_files(memory.h     HAVE_MEMORY_H)
 +include(CheckIncludeFileCXX)
  check_include_files(unistd.h   HAVE_UNISTD_H)
 -check_include_files(direct.h   HAVE_DIRECT_H)
  check_include_files(pwd.h        HAVE_PWD_H)
 -check_include_files(stdint.h   HAVE_STDINT_H)
 -check_include_files(stdlib.h   HAVE_STDLIB_H)
  check_include_files(pthread.h    HAVE_PTHREAD_H)
  check_include_files(dirent.h     HAVE_DIRENT_H)
 -check_include_files(inttypes.h   HAVE_INTTYPES_H)
 -check_include_files(regex.h      HAVE_REGEX_H)
 -check_include_files(sys/types.h  HAVE_SYS_TYPES_H)
 -check_include_files(sys/stat.h   HAVE_SYS_STAT_H)
  check_include_files(sys/time.h   HAVE_SYS_TIME_H)
 -check_include_files(rpc/rpc.h    HAVE_RPC_RPC_H)
 -check_include_files("rpc/rpc.h;rpc/xdr.h"    HAVE_RPC_XDR_H)
  check_include_files(io.h               HAVE_IO_H)
  check_include_files(sched.h      HAVE_SCHED_H)
  
 +check_include_files(regex.h      HAVE_POSIX_REGEX)
 +check_include_file_cxx(regex     HAVE_CXX11_REGEX)
 +# TODO: It could be nice to inform the user if no regex support is found,
 +# as selections won't be fully functional.
 +
  include(CheckFunctionExists)
 -check_function_exists(strcasecmp        HAVE_STRCASECMP)
  check_function_exists(strdup            HAVE_STRDUP)
 -check_function_exists(vprintf           HAVE_VPRINTF)
 -check_function_exists(memcmp            HAVE_MEMCMP)
  check_function_exists(posix_memalign    HAVE_POSIX_MEMALIGN)
  check_function_exists(memalign          HAVE_MEMALIGN)
  check_function_exists(_aligned_malloc   HAVE__ALIGNED_MALLOC)
  check_function_exists(gettimeofday      HAVE_GETTIMEOFDAY)
 -check_function_exists(isnan             HAVE_ISNAN)
 -check_function_exists(_isnan            HAVE__ISNAN)
  check_function_exists(fsync             HAVE_FSYNC)
  check_function_exists(_fileno           HAVE__FILENO)
  check_function_exists(fileno            HAVE_FILENO)
@@@ -404,6 -420,7 +404,6 @@@ check_library_exists(m cbrt "" HAVE_CBR
  
  include(CheckTypeSize)
  
 -check_type_size("bool"          SIZEOF_BOOL) # will also set HAVE_BOOL
  check_type_size("int"           SIZEOF_INT) 
  check_type_size("long int"      SIZEOF_LONG_INT) 
  check_type_size("long long int" SIZEOF_LONG_LONG_INT) 
@@@ -416,6 -433,35 +416,6 @@@ else (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8
      set(GMX_64_BIT FALSE)
  endif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
  
 -# Check for some basic types that we *need*, so set these to int if they are not present 
 -check_type_size(uid_t uid_t)
 -if(NOT uid_t)
 -  set(uid_t int)
 -else(NOT uid_t)
 -  set(uid_t 0)
 -endif(NOT uid_t)
 -
 -check_type_size(gid_t gid_t)
 -if(NOT gid_t)
 -  set(gid_t 1)
 -else(NOT gid_t)
 -  set(gid_t 0)
 -endif(NOT gid_t)
 -
 -check_type_size(size_t size_t)
 -if(NOT size_t)
 -  set(size_t int)
 -else(NOT size_t)
 -  set(size_t 0)
 -endif(NOT size_t)
 -
 -check_type_size(off_t off_t)
 -if(NOT off_t)
 -  set(off_t int)
 -else(NOT off_t)
 -  set(off_t 0)
 -endif(NOT off_t)
 -
  include(TestBigEndian)
  test_big_endian(GMX_INTEGER_BIG_ENDIAN)
  
@@@ -450,6 -496,7 +450,6 @@@ if (GMX_XML
      include_directories(${LIBXML2_INCLUDE_DIR})
      set(PKG_XML libxml-2.0)
      set(XML_LIBRARIES ${LIBXML2_LIBRARIES})
 -    set(HAVE_LIBXML2 1)
    endif(LIBXML2_FOUND)
  endif(GMX_XML)
  
@@@ -476,11 -523,11 +476,11 @@@ endif(GMX_X11
  include(ThreadMPI)
  set(THREAD_MPI_LIB thread_mpi)
  if(GMX_THREAD_MPI)
 -    tmpi_get_source_list(THREAD_MPI_SRC)
 +    tmpi_get_source_list(THREAD_MPI_SRC CXX)
      set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI")
      set(GMX_MPI 1)
  else(GMX_THREAD_MPI)
 -    tmpi_get_source_list(THREAD_MPI_SRC NOMPI)
 +    tmpi_get_source_list(THREAD_MPI_SRC CXX NOMPI)
  endif(GMX_THREAD_MPI)
  
  if(GMX_OPENMM)
@@@ -565,66 -612,30 +565,66 @@@ if(WIN32 AND NOT CYGWIN
  endif()
  
  # only bother with finding git and using version.h if the source is a git repo
 -if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
 -    if(USE_VERSION_H)
 -        # We need at least git v1.5.3 be able to parse git's date output. If not
 -        # found or the version is too small, we can't generate version information.
 -        find_package(Git)
 -
 -      # Find out the git version
 -      if(GIT_FOUND AND NOT GIT_VERSION)
 -        execute_process(COMMAND ${GIT_EXECUTABLE} "--version"
 -            OUTPUT_VARIABLE _exec_out
 -            OUTPUT_STRIP_TRAILING_WHITESPACE)
 -        string(REGEX REPLACE "git version (.*)" "\\1" GIT_VERSION ${_exec_out})
 -        set(GIT_VERSION ${GIT_VERSION} CACHE STRING "Git version")
 -        mark_as_advanced(GIT_VERSION)
 -      endif()
 -
 -        if(NOT GIT_FOUND OR GIT_VERSION VERSION_LESS "1.5.3")
 -          message("No compatible git version found, won't be able to generate proper development version information.")
 -          set(USE_VERSION_H OFF)
 -        endif()
 +if(GMX_GIT_VERSION_INFO)
 +    if (NOT SOURCE_IS_GIT_REPOSITORY)
 +        message(FATAL_ERROR
 +            "Cannot generate git version information from source tree not under git. "
 +            "Set GMX_GIT_VERSION_INFO=OFF to proceed.")
 +    endif ()
 +    # We need at least git v1.5.3 be able to parse git's date output. If not
 +    # found or the version is too small, we can't generate version information.
 +    find_package(Git)
 +
 +    # Find out the git version
 +    if(GIT_FOUND AND NOT GIT_VERSION)
 +      execute_process(COMMAND ${GIT_EXECUTABLE} "--version"
 +        OUTPUT_VARIABLE _exec_out
 +        OUTPUT_STRIP_TRAILING_WHITESPACE)
 +      string(REGEX REPLACE "git version (.*)" "\\1" GIT_VERSION ${_exec_out})
 +      set(GIT_VERSION ${GIT_VERSION} CACHE STRING "Git version")
 +      mark_as_advanced(GIT_VERSION)
      endif()
 +
 +    if(NOT GIT_FOUND OR GIT_VERSION VERSION_LESS "1.5.3")
 +        message(FATAL_ERROR
 +            "No compatible git version found (>= 1.5.3 required). "
 +            "Won't be able to generate development version information. "
 +            "Set GMX_GIT_VERSION_INFO=OFF to proceed.")
 +    endif()
 +endif()
 +
 +option(GMX_INTERNAL_BOOST "Use minimal internal version of boost" OFF)
 +if ( NOT GMX_INTERNAL_BOOST )
 +  find_package( Boost 1.44.0 )
 +else ( NOT GMX_INTERNAL_BOOST )
 +  set (Boost_FOUND FALSE)
 +endif( NOT GMX_INTERNAL_BOOST )
 +
 +if(Boost_FOUND AND NOT Boost_VERSION VERSION_LESS "104400" )
 +  include_directories(${Boost_INCLUDE_DIRS})
  else()
 -    set(USE_VERSION_H OFF)
 +  if(NOT BOOST_QUIETLY)
 +    message("Boost >= 1.44 not found. Using minimal internal version. Not recommended if GROMACS is used as library!")
 +  endif()
 +  include_directories(${CMAKE_SOURCE_DIR}/src/external/boost)
 +  add_definitions( -DBOOST_NO_TYPEID )  #TYPEID not supported for minimal internal version (would add significant more code)
 +  # TODO: Propagate the above settings to the installed CMakeFiles.txt template
 +  # (from share/template/)
 +  # TODO: Reorder stuff such that INCL_INSTALL_DIR could be used here
 +  set(PKG_CFLAGS "${PKG_CFLAGS} -DBOOST_NO_TYPEID -I${GMX_INSTALL_PREFIX}include/gromacs/external/boost")
 +  install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/external/boost/boost
 +          DESTINATION ${GMX_INSTALL_PREFIX}include/gromacs/external/boost
 +          COMPONENT development)
  endif()
 +set(BOOST_QUIETLY TRUE CACHE INTERNAL "")
 +
 +if (LIBXML2_FOUND)
 +    option(GMX_BUILD_UNITTESTS "Build unit tests with BUILD_TESTING (uses Google C++ Testing and Mocking Frameworks, requires libxml2)" ON)
 +else (LIBXML2_FOUND)
 +    set(GMX_BUILD_UNITTESTS OFF)
 +endif (LIBXML2_FOUND)
 +mark_as_advanced(GMX_BUILD_UNITTESTS)
 +set(MEMORYCHECK_SUPPRESSIONS_FILE ${CMAKE_SOURCE_DIR}/cmake/legacy_and_external.supp)
  
  ########################################################################
  # Generate development version info for cache
  ########################################################################
  
  add_definitions( -DHAVE_CONFIG_H )
 +include_directories(${CMAKE_SOURCE_DIR}/src)
 +# Required for config.h, maybe should only be set in src/CMakeLists.txt
  include_directories(${CMAKE_BINARY_DIR}/src)
 -include_directories(${CMAKE_BINARY_DIR}/include)
 -include_directories(${CMAKE_SOURCE_DIR}/include)
 +# Required for gmx_header_config_gen.h to be found before installation
 +include_directories(${CMAKE_BINARY_DIR}/src/gromacs/utility)
 +# Required for now to make old code compile
 +include_directories(${CMAKE_SOURCE_DIR}/src/gromacs/legacyheaders)
  
  include(gmxTestInlineASM)
  gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
  
  include(gmxSetBuildInformation)
  gmx_set_build_information()
- if(BUILD_CPU_FEATURES MATCHES "rdtscp")
+ if(BUILD_CPU_FEATURES MATCHES "rdtscp" AND NOT GMX_DISTRIBUTABLE_BUILD)
      # The timestep counter headers do not include config.h
      add_definitions(-DHAVE_RDTSCP)
- endif(BUILD_CPU_FEATURES MATCHES "rdtscp")
+ endif(BUILD_CPU_FEATURES MATCHES "rdtscp" AND NOT GMX_DISTRIBUTABLE_BUILD)
  
  include(gmxTestFloatFormat)
  gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754 
@@@ -680,15 -687,6 +680,15 @@@ gmx_test_isfinite(HAVE_ISFINITE
  gmx_test__isfinite(HAVE__ISFINITE)
  gmx_test__finite(HAVE__FINITE)
  
 +include(gmxTestCXX11)
 +gmx_test_cxx11(GMX_CXX11 CXX11_FLAG)
 +set(GROMACS_CXX_FLAGS "${CXX11_FLAG} ${GROMACS_CXX_FLAGS}")
 +if(CXX11_FLAG)
 +    #FIXME: add proper solution for progate all but cxx11 flag
 +    set(CUDA_PROPAGATE_HOST_FLAGS no)
 +    message(WARNING "Please manually add compiler flags to CUDA_NVCC_FLAGS. Automatic propogation temporary not working.")
 +endif()
 +
  include(gmxTestXDR)
  gmx_test_xdr(GMX_SYSTEM_XDR)
  if(NOT GMX_SYSTEM_XDR)
@@@ -707,10 -705,12 +707,10 @@@ elseif(${GMX_ACCELERATION} STREQUAL "SS
          GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
      endif(NOT GNU_SSE2_CFLAG)
  
 -    if (CMAKE_CXX_COMPILER_LOADED)
 -        GMX_TEST_CXXFLAG(GNU_SSE2_CXXFLAG "-msse2" GROMACS_CXX_FLAGS)
 -        if(NOT GNU_SSE2_CXXFLAG)
 -            GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
 -        endif(NOT GNU_SSE2_CXXFLAG)
 -    endif()
 +    GMX_TEST_CXXFLAG(GNU_SSE2_CXXFLAG "-msse2" GROMACS_CXX_FLAGS)
 +    if(NOT GNU_SSE2_CXXFLAG)
 +        GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
 +    endif(NOT GNU_SSE2_CXXFLAG)
  
      # We dont warn for lacking SSE2 flag support, since that is probably standard today.
  
@@@ -740,16 -740,18 +740,16 @@@ elseif(${GMX_ACCELERATION} STREQUAL "SS
          GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
      endif(NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
  
 -    if (CMAKE_CXX_COMPILER_LOADED)
 -        GMX_TEST_CXXFLAG(GNU_SSE4_CXXFLAG "-msse4.1" GROMACS_CXX_FLAG)
 -        if (NOT GNU_SSE4_CXXFLAG)
 -            GMX_TEST_CXXFLAG(MSVC_SSE4_CXXFLAG "/arch:SSE4.1" GROMACS_CXX_FLAGS)
 -        endif(NOT GNU_SSE4_CXXFLAG)
 -        if (NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG) 
 -            message(WARNING "No C++ SSE4.1 flag found. Consider a newer compiler, or disable SSE4.1 for slightly lower performance.")
 -            # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
 -            # intrinsics when SSE2 support is enabled, so we try that instead.
 -            GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
 -        endif(NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
 -    endif()
 +    GMX_TEST_CXXFLAG(GNU_SSE4_CXXFLAG "-msse4.1" GROMACS_CXX_FLAG)
 +    if (NOT GNU_SSE4_CXXFLAG)
 +       GMX_TEST_CXXFLAG(MSVC_SSE4_CXXFLAG "/arch:SSE4.1" GROMACS_CXX_FLAGS)
 +    endif(NOT GNU_SSE4_CXXFLAG)
 +    if (NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
 +        message(WARNING "No C++ SSE4.1 flag found. Consider a newer compiler, or disable SSE4.1 for slightly lower performance.")
 +        # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
 +        # intrinsics when SSE2 support is enabled, so we try that instead.
 +        GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
 +    endif(NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
  
      # This must come after we have added the -msse4.1 flag on some platforms.
      check_include_file(smmintrin.h  HAVE_SMMINTRIN_H ${GROMACS_C_FLAGS})
@@@ -777,14 -779,30 +777,28 @@@ elseif(${GMX_ACCELERATION} STREQUAL "AV
          message(WARNING "No C AVX flag found. Consider a newer compiler, or disable AVX for much lower performance.")
      endif (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
  
 -    if (CMAKE_CXX_COMPILER_LOADED)
 -        GMX_TEST_CXXFLAG(GNU_AVX_CXXFLAG "-mavx" GROMACS_CXX_FLAGS)
 -        if (NOT GNU_AVX_CXXFLAG)
 -            GMX_TEST_CXXFLAG(MSVC_AVX_CXXFLAG "/arch:AVX" GROMACS_CXX_FLAGS)
 -        endif (NOT GNU_AVX_CXXFLAG)
 -        if (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
 -            message(WARNING "No C++ AVX flag found. Consider a newer compiler, or disable AVX for much lower performance.")
 -        endif (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
 -    endif()
 +    GMX_TEST_CXXFLAG(GNU_AVX_CXXFLAG "-mavx" GROMACS_CXX_FLAGS)
 +    if (NOT GNU_AVX_CXXFLAG)
 +       GMX_TEST_CXXFLAG(MSVC_AVX_CXXFLAG "/arch:AVX" GROMACS_CXX_FLAGS)
 +    endif (NOT GNU_AVX_CXXFLAG)
 +    if (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
 +       message(WARNING "No C++ AVX flag found. Consider a newer compiler, or disable AVX for much lower performance.")
 +    endif (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
  
+     # Set the FMA4 flags (MSVC doesn't require any)
+     if(${GMX_ACCELERATION} STREQUAL "AVX_128_FMA" AND NOT MSVC)
+         GMX_TEST_CFLAG(GNU_FMA_CFLAG "-mfma4" GROMACS_C_FLAGS)
+         if (NOT GNU_FMA_CFLAG)
+             message(WARNING "No C FMA4 flag found. Consider a newer compiler, or disable AVX_128_FMA for much lower performance.")
+         endif(NOT GNU_FMA_CFLAG)
+         if (CMAKE_CXX_COMPILER_LOADED)
+             GMX_TEST_CXXFLAG(GNU_FMA_CXXFLAG "-mfma4" GROMACS_CXX_FLAGS)
+             if (NOT GNU_FMA_CXXFLAG)
+                 message(WARNING "No C++ FMA flag found. Consider a newer compiler, or disable AVX_128_FMA for much lower performance.")
+             endif (NOT GNU_FMA_CXXFLAG)
+         endif()
+     endif()
      # Only test the header after we have tried to add the flag for AVX support
      check_include_file(immintrin.h  HAVE_IMMINTRIN_H ${GROMACS_C_FLAGS})
  
          message(FATAL_ERROR "Cannot find immintrin.h, which is required for AVX intrinsics support. Consider switching compiler.")
      endif(NOT HAVE_IMMINTRIN_H)
  
-     # AMD says we should include x86intrin.h for FMA support, but MSVC seems to do fine without it, so don't require it.
+     # GCC requires x86intrin.h for FMA support. MSVC 2010 requires intrin.h for FMA support.
      check_include_file(x86intrin.h HAVE_X86INTRIN_H ${GROMACS_C_FLAGS})
+     check_include_file(intrin.h HAVE_INTRIN_H ${GROMACS_C_FLAGS})
  
      # The user should not be able to set this orthogonally to the acceleration
      set(GMX_X86_SSE4_1 1)
@@@ -877,15 -896,14 +892,15 @@@ if(GMX_FORTRAN OR GMX_POWER6
  
      if(isupper)
          set(F77_FUNCDEF   "${prefix} NAME ${suffix}")
 -        set(F77_FUNCDEF_  "${prefix} NAME ${extrasuffix}")
 +        # The underscored versions are not currently used.
 +        #set(F77_FUNCDEF_  "${prefix} NAME ${extrasuffix}")
      else(isupper)
          set(F77_FUNCDEF   "${prefix} name ${suffix}")
 -        set(F77_FUNCDEF_  "${prefix} name ${extrasuffix}")
 +        #set(F77_FUNCDEF_  "${prefix} name ${extrasuffix}")
      endif(isupper)
  else(GMX_FORTRAN OR GMX_POWER6)
          set(F77_FUNCDEF   "name ## _")
 -        set(F77_FUNCDEF_  "name ## _")
 +        #set(F77_FUNCDEF_  "name ## _")
  endif(GMX_FORTRAN OR GMX_POWER6)
  
  # Process QM/MM Settings
@@@ -1053,8 -1071,10 +1068,8 @@@ if (NOT DEFINED GROMACS_C_FLAGS_SET
          FORCE)
      set(CMAKE_C_FLAGS "${GROMACS_C_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING 
          "Flags used by the compiler during all build types" FORCE)
 -    if (CMAKE_CXX_COMPILER_LOADED)
 -        set(CMAKE_CXX_FLAGS "${GROMACS_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" CACHE STRING 
 -            "Flags used by the compiler during all build types" FORCE)
 -    endif()
 +    set(CMAKE_CXX_FLAGS "${GROMACS_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" CACHE STRING 
 +        "Flags used by the compiler during all build types" FORCE)
      set(CMAKE_EXE_LINKER_FLAGS 
          "${GROMACS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" 
          CACHE STRING "Linker flags for creating executables" FORCE) 
@@@ -1100,6 -1120,13 +1115,6 @@@ endif(
  ########################################################################
  # Specify install locations and which subdirectories to process        #
  ########################################################################
 -if (GMX_USE_RELATIVE_INSTALL_PATH)
 -    set(GMX_INSTALL_PREFIX "" CACHE STRING "Prefix gets appended to CMAKE_INSTALL_PREFIX. For cpack it sets the root folder of the archive.")
 -    mark_as_advanced(GMX_INSTALL_PREFIX)
 -else()
 -    set(GMX_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
 -endif()
 -
  if ( NOT DEFINED GMXLIB )
      set(GMXLIB lib)
  endif()
@@@ -1125,8 -1152,8 +1140,8 @@@ endif(
  #Simpler to always install.
  install(FILES COPYING DESTINATION ${DATA_INSTALL_DIR} COMPONENT data)
  
 +add_subdirectory(doxygen)
  add_subdirectory(share)
 -add_subdirectory(include)
  add_subdirectory(src)
  add_subdirectory(scripts)
  
@@@ -1151,7 -1178,7 +1166,7 @@@ ADD_CUSTOM_TARGET(uninstal
  include(CTest)
  mark_as_advanced(BUILD_TESTING)
  IF(BUILD_TESTING)
 -      enable_testing()
 -      add_subdirectory(tests)
 +    enable_testing()
 +    add_subdirectory(tests)
  ENDIF()
  
diff --combined src/config.h.cmakein
index ade12fd5464b381d176cbf3cb067764574f5101e,a5024ef659bdb8339049a0da9f279302b23f9e41..3e9448c5729d67625c029fe3ed2056844d3a0fca
@@@ -1,16 -1,4 +1,16 @@@
 -/* Manually created from config.h.in to work with cmake */
 +/*! \libinternal \file
 + * \brief
 + * Include file for configuration macros from the build system.
 + *
 + * This header is not installed, so headers must not reference macros defined
 + * here.
 + *
 + * \inlibraryapi
 + */
 +#include "gromacs/utility/gmx_header_config.h"
 +
 +/* TODO: For now, disable Doxygen warnings from here */
 +/*! \cond */
  
  /* Disable warnings about double-to-float conversion accuracy loss on MSVC */
  #ifdef _MSC_VER
@@@ -28,8 -16,8 +28,8 @@@
  /* Version number of package (translate from cmake to autoconf macro name) */
  #define VERSION  "@PROJECT_VERSION@"
  
 -/* Use the version string from generated version.h */
 -#cmakedefine USE_VERSION_H
 +/* Use extra version information generated with git */
 +#cmakedefine GMX_GIT_VERSION_INFO
  
  /* Default location of data files */
  #define GMXLIBDIR "@GMXLIBDIR@"
  /* User doing build */
  #define BUILD_USER "@BUILD_USER@"
  
 +/* Binary suffix for the created binaries */
 +#define GMX_BINARY_SUFFIX "@GMX_BINARY_SUFFIX@"
 +
 +/* Source directory for the build */
 +#cmakedefine CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@"
 +
 +/* Binary directory for the build */
 +#cmakedefine CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@"
 +
  /* Turn off water-water neighborlist optimization only - not used right now */
  #cmakedefine DISABLE_WATERWATER_NLIST
  
@@@ -83,6 -62,9 +83,6 @@@
     case), which must not contain underscores, for linking with Fortran. */
  #define F77_FUNC(name,NAME)     @F77_FUNCDEF@
  
 -/* As F77_FUNC, but for C identifiers containing underscores. */
 -#define F77_FUNC_(name,NAME)    @F77_FUNCDEF_@
 -
  /* IEEE754 floating-point format. Memory layout is defined by macros
   * GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER and GMX_IEEE754_BIG_ENDIAN_WORD_ORDER. 
   */
  /* Define for Linux pthread_setaffinity */
  #cmakedefine HAVE_PTHREAD_SETAFFINITY
  
 -/* Define for Windows NUMA-aware allocator functions*/
 -#cmakedefine TMPI_WINDOWS_NUMA_API
 -
  /* Define for sysconf() */
  #cmakedefine HAVE_SYSCONF
  
 -/* Define for GetSystemInfo() */
 -#cmakedefine HAVE_SYSTEM_INFO
 -
  /* Enable x86 gcc inline assembly */
  #cmakedefine GMX_X86_GCC_INLINE_ASM
  
  /* Use GPU native acceleration */
  #cmakedefine GMX_GPU
  
 -/* Define to 1 if the system has the type gmx_bool. */
 -#cmakedefine HAVE_BOOL
 -
  /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
  #cmakedefine HAVE_FSEEKO
  
  /* Define to 1 if _fseeki64 (and presumably _fseeki64) exists and is declared. */
  #cmakedefine HAVE__FSEEKI64
  
 -/* Define to 1 if you have the m library (-lm). */
 -#cmakedefine HAVE_LIBM
 -
 -/* Define to 1 if you have the mkl library (-lmkl). */
 -#cmakedefine HAVE_LIBMKL
 -
  /* Define to 1 if you have the gsl library (-lgsl). */
  #cmakedefine HAVE_LIBGSL
  
 -/* Define to 1 if you have the xml2 library (-lxml2). */
 -#cmakedefine HAVE_LIBXML2
 -
 -/* Define to 1 if you have the dl library (-ldl). */
 -#cmakedefine HAVE_LIBDL
 -
  /* Have io.h (windows)*/
  #cmakedefine HAVE_IO_H
  
 -/* Define to 1 if you have the strcasecmp() function. */
 -#cmakedefine HAVE_STRCASECMP
 -
  /* Define to 1 if you have the strdup() function. */
  #cmakedefine HAVE_STRDUP
  
 -/* Define to 1 if you have the vfprintf() function. */
 -#cmakedefine HAVE_VFPRINTF
 -
 -/* Define to 1 if you have the memcmp() function. */
 -#cmakedefine HAVE_MEMCMP
 -
  /* Define to 1 if you have the posix_memalign() function. */
  #cmakedefine HAVE_POSIX_MEMALIGN
  
  /* Define to 1 if you have the cbrt() function. */
  #cmakedefine HAVE_CBRT
  
 -/* Define to 1 if you have the isnan() function. */
 -#cmakedefine HAVE_ISNAN
 -
 -/* Define to 1 if you have the _isnan() function. */
 -#cmakedefine HAVE__ISNAN
 -
  /* Define to 1 if you have the isfinite() function. */
  #cmakedefine HAVE_ISFINITE
  
  /* Define to 1 if you have the sqrtf() function. */
  #cmakedefine HAVE_SQRTF
  
 -/* Define to 1 if you have the <string.h> header file. */
 -#cmakedefine HAVE_STRING_H
 -
 -/* Define to 1 if yo have the <math.h> header file. */
 -#cmakedefine HAVE_MATH_H
 -
 -/* Define to 1 if yo have the <limits.h> header file. */
 -#cmakedefine HAVE_LIMITS_H
 -
 -/* Define to 1 if yo have the <memory.h> header file. */
 -#cmakedefine HAVE_MEMORY_H
 -
  /* Define to 1 if yo have the <unistd.h> header file. */
  #cmakedefine HAVE_UNISTD_H
  
 -/* Define to 1 if yo have the <direct.h> header file. */
 -#cmakedefine HAVE_DIRECT_H
 -
  /* Define to 1 if yo have the <pwd.h> header file. */
  #cmakedefine HAVE_PWD_H
  
 -/* Define to 1 if yo have the <stdint.h> header file. */
 -#cmakedefine HAVE_STDINT_H
 -
 -/* Define to 1 if yo have the <stdlib.h> header file. */
 -#cmakedefine HAVE_STDLIB_H
 -
  /* Define to 1 if yo have the <pthread.h> header file. */
  #cmakedefine HAVE_PTHREAD_H
  
  /* Define to 1 if yo have the <dirent.h> header file. */
  #cmakedefine HAVE_DIRENT_H
  
 -/* Define to 1 if yo have the <inttypes.h> header file. */
 -#cmakedefine HAVE_INTTYPES_H
 -
 -/* Define to 1 if yo have the <regex.h> header file. */
 -#cmakedefine HAVE_REGEX_H
 -
 -/* Define to 1 if you have the <sys/types.h> header file. */
 -#cmakedefine HAVE_SYS_TYPES_H
 -
 -/* Define to 1 if you have the <sys/stat.h> header file. */
 -#cmakedefine HAVE_SYS_STAT_H
 -
  /* Define to 1 if you have the <sys/time.h> header file. */
  #cmakedefine HAVE_SYS_TIME_H
  
 -/* Define to 1 if you have the <rpc/rpc.h> header file. */
 -#cmakedefine HAVE_RPC_RPC_H
 -
 -/* Define to 1 if you have the <rpc/xdr.h> header file. */
 -#cmakedefine HAVE_RPC_XDR_H
 -
  /* Define to 1 if you have the <x86intrin.h> header file */
  #cmakedefine HAVE_X86INTRIN_H
  
+ /* Define to 1 if you have the <intrin.h> header file */
+ #cmakedefine HAVE_INTRIN_H
  /* Define to 1 if you have the <sched.h> header */
  #cmakedefine HAVE_SCHED_H
  
 -/* Define to 1 if you have the vprintf() function. */
 -#cmakedefine HAVE_VPRINTF
 +/* Define to 1 if you have the POSIX <regex.h> header file. */
 +#cmakedefine HAVE_POSIX_REGEX
 +
 +/* Define to 1 if you have the C++11 <regex> header file. */
 +#cmakedefine HAVE_CXX11_REGEX
  
  /* Define to 1 if you have the sysconf() function */
  #cmakedefine HAVE_SYSCONF
  /* Some systems requires this to be set to 64 for large file support */
  #cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
  
 -/* Gromacs shortcut define for fseeko & ftello being present with 64-bit support */
 -#cmakedefine GMX_LARGEFILES
 -
 -/* Define to int if <sys/types.h> does not define. */
 -#cmakedefine gid_t int
 -
  /* Define to __inline__ or __inline if that is what the C compiler
     calls it, or to nothing if inline is not supported under any name.
     Please do NOT remove the gmx_inline keyword from here. The classical
     to identify the language standard level. If it is not supported, it
     is still defined to an empty string here. */
  #define gmx_restrict ${RESTRICT_KEYWORD}
 -
 -#ifndef CPLUSPLUS
 -#ifdef __cplusplus
 -#define CPLUSPLUS
 -#endif
 -#endif  
 -
 -/* Define to long int if <sys/types.h> does not define. */                    
 -#cmakedefine off_t int
 -
 -/* Define to unsigned int if <sys/types.h> does not define. */
 -#cmakedefine size_t int
 -
 -/* Define to int if <sys/types.h> does not define. */
 -#cmakedefine uid_t int
 -
  /* Build special-purpose mdrun library */
  #cmakedefine GMX_FAHCORE   
  
  /* Define if we have pipes */
  #cmakedefine HAVE_PIPES
  
 -
  /* Catch stupid CMake problems on OS X */
  #ifdef __APPLE__
  #  if ((defined(__LP64__) && __LP64__ && defined(SIZEOF_VOIDP) && SIZEOF_VOIDP<8) || ( (!defined(__LP64__) || __LP64__==0) && (defined(SIZEOF_VOIDP) && SIZEOF_VOIDP>4)))
  #    error "or create a new such entry with your choice in the GUI _before_ hitting 'configure'."
  #  endif
  #endif
 +
 +/*! \endcond */
index 8d48f2cbca1d5ffd3c5008ef07728b2a77d819e3,0adb058a9d152ac5671184b22de97829ad82b3d0..0adb058a9d152ac5671184b22de97829ad82b3d0
@@@ -25,6 -25,9 +25,9 @@@
  #ifdef HAVE_X86INTRIN_H
  #include <x86intrin.h> /* FMA */
  #endif
+ #ifdef HAVE_INTRIN_H
+ #include <intrin.h> /* FMA MSVC */
+ #endif
  
  #include <math.h>
  
index fb3614274ca99f3921a390d054cc80bedb71c193,54e327e9f1272769a32f4fe0deb38e8c7f940f05..54e327e9f1272769a32f4fe0deb38e8c7f940f05
@@@ -962,6 -962,62 +962,62 @@@ void nbnxn_atomdata_copy_x_to_nbat_x(co
      }
  }
  
+ static void
+ nbnxn_atomdata_reduce_reals(real * gmx_restrict dest,
+                             nbnxn_atomdata_output_t * gmx_restrict src,
+                             int nsrc,
+                             int i0, int i1)
+ {
+     int i,s;
+     for(i=i0; i<i1; i++)
+     {
+         for(s=0; s<nsrc; s++)
+         {
+             dest[i] += src[s].f[i];
+         }
+     }
+ }
+ static void
+ nbnxn_atomdata_reduce_reals_x86_simd(real * gmx_restrict dest,
+                                      nbnxn_atomdata_output_t * gmx_restrict src,
+                                      int nsrc,
+                                      int i0, int i1)
+ {
+ #ifdef NBNXN_SEARCH_SSE
+ #ifdef GMX_X86_AVX_256
+ #define GMX_MM256_HERE
+ #else
+ #define GMX_MM128_HERE
+ #endif
+ #include "gmx_x86_simd_macros.h"
+     int       i,s;
+     gmx_mm_pr dest_SSE,src_SSE;
+     if ((i0 & (GMX_X86_SIMD_WIDTH_HERE-1)) ||
+         (i1 & (GMX_X86_SIMD_WIDTH_HERE-1)))
+     {
+         gmx_incons("bounds not a multiple of GMX_X86_SIMD_WIDTH_HERE in nbnxn_atomdata_reduce_reals_x86_simd");
+     }
+     for(i=i0; i<i1; i+=GMX_X86_SIMD_WIDTH_HERE)
+     {
+         dest_SSE = gmx_load_pr(dest+i);
+         for(s=0; s<nsrc; s++)
+         {
+             src_SSE  = gmx_load_pr(src[s].f+i);
+             dest_SSE = gmx_add_pr(dest_SSE,src_SSE);
+         }
+         gmx_store_pr(dest+i,dest_SSE);
+     }
+ #undef GMX_MM128_HERE
+ #undef GMX_MM256_HERE
+ #endif
+ }
  /* Add part of the force array(s) from nbnxn_atomdata_t to f */
  static void
  nbnxn_atomdata_add_nbat_f_to_f_part(const nbnxn_search_t nbs,
@@@ -1079,6 -1135,7 +1135,7 @@@ void nbnxn_atomdata_add_nbat_f_to_f(con
  {
      int a0=0,na=0;
      int nth,th;
+     gmx_bool bStreamingReduce;
  
      nbs_cycle_start(&nbs->cc[enbsCCreducef]);
  
      }
  
      nth = gmx_omp_nthreads_get(emntNonbonded);
+     /* Using the two-step streaming reduction is probably always faster */
+     bStreamingReduce = (nbat->nout > 1);
+     if (bStreamingReduce)
+     {
+         /* Reduce the force thread output buffers into buffer 0, before adding
+          * them to the, differently ordered, "real" force buffer.
+          */
+ #pragma omp parallel for num_threads(nth) schedule(static)
+         for(th=0; th<nth; th++)
+         {
+             int g0,g1;
+             int b0,b1,nb;
+             int blocksize,i0,i1;
+             /* For which grids should we reduce the force output? */
+             g0 = ((locality==eatLocal || locality==eatAll) ? 0 : 1);
+             g1 = (locality==eatLocal ? 1 : nbs->ngrid);
+             /* Get the grid cell bounds */
+             b0 = nbs->grid[g0].cell0;
+             b1 = nbs->grid[g1-1].cell0 + nbs->grid[g1-1].nc;
+             blocksize = nbs->grid[g0].na_sc*nbat->fstride;
+             /* The simple grid size in atoms is a multiple of na_cj.
+              * With float-AVX256 we use this and make blocksize a multiple of 8.
+              */
+             if (nbs->grid[0].bSimple && nbs->grid[0].na_cj > nbs->grid[0].na_c)
+             {
+                 blocksize *= 2;
+                 b0 /= 2;
+                 b1 /= 2;
+             }
+             nb = b1 - b0;
+             /* Calculate the index range for our thread */
+             i0 = (b0 + (nb* th   )/nth)*blocksize;
+             i1 = (b0 + (nb*(th+1))/nth)*blocksize;
+ #ifdef NBNXN_SEARCH_SSE
+             nbnxn_atomdata_reduce_reals_x86_simd(
+ #else
+             nbnxn_atomdata_reduce_reals(    
+ #endif
+                                         nbat->out[0].f,
+                                         nbat->out+1,nbat->nout - 1,
+                                         i0,i1);
+         }
+     }
  #pragma omp parallel for num_threads(nth) schedule(static)
      for(th=0; th<nth; th++)
      {
          nbnxn_atomdata_add_nbat_f_to_f_part(nbs,nbat,
-                                              nbat->out,
-                                              nbat->nout,
-                                              a0+((th+0)*na)/nth,
-                                              a0+((th+1)*na)/nth,
-                                              f);
+                                             nbat->out,
+                                             bStreamingReduce ? 1 : nbat->nout,
+                                             a0+((th+0)*na)/nth,
+                                             a0+((th+1)*na)/nth,
+                                             f);
      }
  
      nbs_cycle_stop(&nbs->cc[enbsCCreducef]);