From 370292079818dd600b3a8a6edaf37cf75a256e2b Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Sun, 26 May 2013 12:45:47 +0300 Subject: [PATCH] Split cmake thread detection into core thread and thread_mpi. This makes it possible to use core threading facilities (mutex/cond-var/affinity, etc) on builds that don't use thread_mpi. Change-Id: I0f0f43e86da642c4645fd7ac3c4796098cf9cd5e --- CMakeLists.txt | 5 +++++ cmake/ThreadMPI.cmake | 36 ++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e793631311..9d0fa8b30e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -570,7 +570,12 @@ endif(GMX_X11) include(ThreadMPI) set(THREAD_MPI_LIB thread_mpi) +# Enable core threading facilities +tmpi_enable_core("${CMAKE_SOURCE_DIR}/include") +# Enable tMPI C++ support +# tmpi_enable_cxx() if(GMX_THREAD_MPI) + # enable MPI functions tmpi_enable() set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI") set(GMX_MPI 1) diff --git a/cmake/ThreadMPI.cmake b/cmake/ThreadMPI.cmake index cc6822c748..84714196f0 100644 --- a/cmake/ThreadMPI.cmake +++ b/cmake/ThreadMPI.cmake @@ -38,21 +38,23 @@ include(CheckFunctionExists) include(CheckCSourceCompiles) # sets TMPI_ATOMICS to 1 if atomic operations are found, 0 otherwise -MACRO(TMPI_TEST_ATOMICS) +# Options: +# include directory for thread_mpi/atomic.h +MACRO(TMPI_TEST_ATOMICS INCDIR) if (NOT DEFINED TMPI_ATOMICS) try_compile(TEST_ATOMICS "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/cmake/TestAtomics.c" - COMPILE_DEFINITIONS "-I${CMAKE_SOURCE_DIR}/include" ) + COMPILE_DEFINITIONS "-I${INCDIR}") if (TEST_ATOMICS) message(STATUS "Atomic operations found") else (TEST_ATOMICS) message(STATUS "Atomic operations not found") endif(TEST_ATOMICS) set(TMPI_ATOMICS ${TEST_ATOMICS} CACHE INTERNAL "Whether atomic operations are found") + set(TMPI_ATOMICS_INCDIR ${INCDIR} CACHE INTERNAL "Atomic operations check include dir") endif(NOT DEFINED TMPI_ATOMICS) ENDMACRO(TMPI_TEST_ATOMICS VARIABLE) -TMPI_TEST_ATOMICS() include(FindThreads) if (CMAKE_USE_PTHREADS_INIT) @@ -66,32 +68,29 @@ else () message(FATAL_ERROR "Thread support required") endif (CMAKE_USE_PTHREADS_INIT) -# Turns on thread_mpi. -# options are: -# CXX: enable C++ library build. +# Turns on thread_mpi core threading functions. +MACRO(TMPI_ENABLE_CORE INCDIR) + TMPI_TEST_ATOMICS(${INCDIR}) +ENDMACRO(TMPI_ENABLE_CORE) + +# enable C++ library build. +MACRO(TMPI_ENABLE_CXX) + set(TMPI_CXX_LIB 1) +ENDMACRO(TMPI_ENABLE_CXX) + +# Turns on thread_mpi MPI functions. MACRO(TMPI_ENABLE) # first check whether threads and atomics are available. if(NOT TMPI_ATOMICS) # check again, to allow the user to fix this. unset(TMPI_ATOMICS CACHE) - TMPI_TEST_ATOMICS() + TMPI_TEST_ATOMICS(${TMPI_ATOMICS_INCDIR}) endif(NOT TMPI_ATOMICS) if(NOT TMPI_ATOMICS) message(WARNING "Atomic operations not found for this CPU+compiler combination. Thread support will be unbearably slow: disable threads. Atomic operations should work on all but the most obscure CPU+compiler combinations; if your system is not obscure -- like, for example, x86 with gcc -- please contact the developers.") endif(NOT TMPI_ATOMICS) set(TMPI_ENABLED 1) - foreach (_option IN ITEMS ${ARGN}) - if (_option STREQUAL "CXX") - set(TMPI_CXX_LIB 1) - #elseif (_option STREQUAL "NOMPI") - # set(TMPI_NO_MPI_LIB 1) - else () - message(FATAL_ERROR "Unknown thread_mpi option '${_option}'") - endif () - endforeach () - - #tmpi_test_atomics(TMPI_ATOMICS) # the spin-waiting option option(THREAD_MPI_WAIT_FOR_NO_ONE "Use busy waits without yielding to the OS scheduler. Turning this on might improve performance (very) slightly at the cost of very poor performance if the threads are competing for CPU time." OFF) @@ -166,6 +165,7 @@ MACRO(TMPI_ENABLE) #check_include_files(windows.h HAVE_WINDOWS_H) ENDMACRO(TMPI_ENABLE) + MACRO(TMPI_GET_SOURCE_LIST SRC_VARIABLE) set(${SRC_VARIABLE} thread_mpi/errhandler.c -- 2.11.4.GIT