Split cmake thread detection into core thread and thread_mpi.
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 26 May 2013 09:45:47 +0000 (12:45 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 4 Jun 2013 09:27:08 +0000 (11:27 +0200)
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
cmake/ThreadMPI.cmake

index e79363131121b14f0e1324678b0ad98c8858858f..9d0fa8b30e9dd974ed63b6d27d48ab3185070141 100644 (file)
@@ -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)
index cc6822c74839af8c31e22af3115cba5816b8b0c5..84714196f0f5f67b92f7714cd0670fc0419d2820 100644 (file)
@@ -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