2 include(CheckIncludeFiles)
3 include(CheckFunctionExists)
4 include(CheckCSourceCompiles)
6 # sets TMPI_ATOMICS to 1 if atomic operations are found, 0 otherwise
7 MACRO(TMPI_TEST_ATOMICS)
8 if (NOT DEFINED TMPI_ATOMICS)
9 try_compile(TEST_ATOMICS "${CMAKE_BINARY_DIR}"
10 "${CMAKE_SOURCE_DIR}/cmake/TestAtomics.c"
11 COMPILE_DEFINITIONS "-I${CMAKE_SOURCE_DIR}/src/gromacs/legacyheaders" )
14 message(STATUS "Atomic operations found")
16 message(STATUS "Atomic operations not found")
18 set(TMPI_ATOMICS ${TEST_ATOMICS} CACHE INTERNAL "Whether atomic operations are found")
19 endif(NOT DEFINED TMPI_ATOMICS)
20 ENDMACRO(TMPI_TEST_ATOMICS VARIABLE)
25 if (CMAKE_USE_PTHREADS_INIT)
26 check_include_files(pthread.h HAVE_PTHREAD_H)
27 set(THREAD_PTHREADS 1)
28 set(THREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
29 elseif (CMAKE_USE_WIN32_THREADS_INIT)
33 message(FATAL_ERROR "Thread support required")
34 endif (CMAKE_USE_PTHREADS_INIT)
36 # Turns on thread_mpi.
38 # CXX: enable C++ library build.
40 # first check whether threads and atomics are available.
42 # check again, to allow the user to fix this.
43 unset(TMPI_ATOMICS CACHE)
45 endif(NOT TMPI_ATOMICS)
47 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.")
48 endif(NOT TMPI_ATOMICS)
51 foreach (_option IN ITEMS ${ARGN})
52 if (_option STREQUAL "CXX")
54 elseif (_option STREQUAL "NOMPI")
55 set(TMPI_NO_MPI_LIB 1)
57 message(FATAL_ERROR "Unknown thread_mpi option '${_option}'")
61 #tmpi_test_atomics(TMPI_ATOMICS)
63 # the spin-waiting option
64 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)
65 mark_as_advanced(THREAD_MPI_WAIT_FOR_NO_ONE)
66 if (THREAD_MPI_WAIT_FOR_NO_ONE)
67 set(TMPI_WAIT_FOR_NO_ONE 1)
68 else (THREAD_MPI_WAIT_FOR_NO_ONE)
69 set(TMPI_WAIT_FOR_NO_ONE 0)
70 endif (THREAD_MPI_WAIT_FOR_NO_ONE)
72 # the copy buffer option
73 option(THREAD_MPI_COPY_BUFFER "Use an intermediate copy buffer for small message sizes, to allow blocking sends to return quickly. Only useful in programs with relatively uncoupled threads (infrequent MPI communication)" OFF)
74 mark_as_advanced(THREAD_MPI_COPY_BUFFER)
75 if (THREAD_MPI_COPY_BUFFER)
76 set(TMPI_COPY_BUFFER 1)
77 else (THREAD_MPI_COPY_BUFFER)
78 set(TMPI_COPY_BUFFER 0)
79 endif (THREAD_MPI_COPY_BUFFER)
81 # the profiling option
82 option(THREAD_MPI_PROFILING "Turn on simple MPI profiling." OFF)
83 mark_as_advanced(THREAD_MPI_PROFILING)
84 if (THREAD_MPI_PROFILING)
86 else (THREAD_MPI_PROFILING)
88 endif (THREAD_MPI_PROFILING)
90 # tmpi warnings for testing
91 option(THREAD_MPI_WARNINGS "Turn thread_mpi warnings for testing." OFF)
92 mark_as_advanced(THREAD_MPI_WARNINGS)
93 if (THREAD_MPI_WARNINGS)
95 else (THREAD_MPI_WARNINGS)
97 endif (THREAD_MPI_WARNINGS)
99 include(CheckCSourceCompiles)
102 include(CheckFunctionExists)
104 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
105 # check for sched_setaffinity
106 check_c_source_compiles(
112 int main(void) { cpu_set_t set;
115 pthread_setaffinity_np(pthread_self(), sizeof(set), &set);
120 if (PTHREAD_SETAFFINITY)
121 set(HAVE_PTHREAD_SETAFFINITY 1)
122 endif (PTHREAD_SETAFFINITY)
123 set(CMAKE_REQUIRED_LIBRARIES)
124 endif (THREAD_PTHREADS)
127 # this runs on POSIX systems
128 check_include_files(unistd.h HAVE_UNISTD_H)
129 check_include_files(sched.h HAVE_SCHED_H)
130 check_include_files(sys/time.h HAVE_SYS_TIME_H)
131 check_function_exists(sysconf HAVE_SYSCONF)
132 # this runs on windows
133 #check_include_files(windows.h HAVE_WINDOWS_H)
134 ENDMACRO(TMPI_ENABLE)
136 MACRO(TMPI_GET_SOURCE_LIST SRC_VARIABLE)
138 thread_mpi/errhandler.c
139 thread_mpi/tmpi_malloc.c
142 list(APPEND ${SRC_VARIABLE} thread_mpi/pthreads.c)
143 elseif (THREAD_WINDOWS)
144 list(APPEND ${SRC_VARIABLE} thread_mpi/winthreads.c)
145 endif (THREAD_PTHREADS)
147 list(APPEND ${SRC_VARIABLE} thread_mpi/system_error.cpp)
150 list(APPEND ${SRC_VARIABLE}
151 thread_mpi/alltoall.c thread_mpi/p2p_protocol.c
152 thread_mpi/barrier.c thread_mpi/p2p_send_recv.c
153 thread_mpi/bcast.c thread_mpi/p2p_wait.c
154 thread_mpi/collective.c thread_mpi/profile.c
155 thread_mpi/comm.c thread_mpi/reduce.c
156 thread_mpi/event.c thread_mpi/reduce_fast.c
157 thread_mpi/gather.c thread_mpi/scatter.c
158 thread_mpi/group.c thread_mpi/tmpi_init.c
159 thread_mpi/topology.c thread_mpi/list.c
160 thread_mpi/type.c thread_mpi/lock.c
161 thread_mpi/numa_malloc.c thread_mpi/once.c
164 ENDMACRO(TMPI_GET_SOURCE_LIST)