2 include(CheckIncludeFiles)
3 include(CheckFunctionExists)
4 #include(CheckCSourceCompiles)
6 #option(THREAD_PTHREADS "Use posix threads" ON)
8 MACRO(TEST_TMPI_ATOMICS VARIABLE)
9 if (NOT DEFINED TMPI_ATOMICS)
10 try_compile(TEST_ATOMICS "${CMAKE_BINARY_DIR}"
11 "${CMAKE_SOURCE_DIR}/cmake/TestAtomics.c"
12 COMPILE_DEFINITIONS "-I${CMAKE_SOURCE_DIR}/include" )
15 message(STATUS "Atomics found")
16 set(${VARIABLE} CACHE INTERNAL 1)
18 message(WARNING "Atomics not found for this compiler+cpu combination. Thread support will be unbearably slow: disable threads. Atomics 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.")
19 set(${VARIABLE} CACHE INTERNAL 0)
21 endif(NOT DEFINED TMPI_ATOMICS)
22 ENDMACRO(TEST_TMPI_ATOMICS VARIABLE)
24 MACRO(TMPI_MAKE_CXX_LIB)
27 set(THREAD_MPI_CXX_SRC
28 thread_mpi/system_error.cpp )
29 ENDMACRO(TMPI_MAKE_CXX_LIB)
32 if (CMAKE_USE_PTHREADS_INIT)
33 check_include_files(pthread.h HAVE_PTHREAD_H)
34 set(THREAD_PTHREADS 1)
35 #add_definitions(-DTHREAD_PTHREADS)
37 thread_mpi/alltoall.c thread_mpi/p2p_protocol.c
38 thread_mpi/barrier.c thread_mpi/p2p_send_recv.c
39 thread_mpi/bcast.c thread_mpi/p2p_wait.c
40 thread_mpi/collective.c thread_mpi/profile.c
41 thread_mpi/comm.c thread_mpi/pthreads.c
42 thread_mpi/errhandler.c thread_mpi/reduce.c
43 thread_mpi/event.c thread_mpi/reduce_fast.c
44 thread_mpi/gather.c thread_mpi/scatter.c
45 thread_mpi/group.c thread_mpi/tmpi_init.c
46 thread_mpi/topology.c thread_mpi/list.c
47 thread_mpi/type.c thread_mpi/lock.c
48 thread_mpi/numa_malloc.c thread_mpi/once.c
49 thread_mpi/scan.c thread_mpi/tmpi_malloc.c)
50 set(THREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
51 else (CMAKE_USE_PTHREADS_INIT)
52 if (CMAKE_USE_WIN32_THREADS_INIT)
54 #add_definitions(-DTHREAD_WINDOWS)
56 thread_mpi/alltoall.c thread_mpi/p2p_protocol.c
57 thread_mpi/barrier.c thread_mpi/p2p_send_recv.c
58 thread_mpi/bcast.c thread_mpi/p2p_wait.c
59 thread_mpi/collective.c thread_mpi/profile.c
61 thread_mpi/errhandler.c thread_mpi/reduce.c
62 thread_mpi/event.c thread_mpi/reduce_fast.c
63 thread_mpi/gather.c thread_mpi/scatter.c
64 thread_mpi/group.c thread_mpi/tmpi_init.c
65 thread_mpi/topology.c thread_mpi/list.c
66 thread_mpi/type.c thread_mpi/lock.c
67 thread_mpi/winthreads.c thread_mpi/once.c
68 thread_mpi/numa_malloc.c
69 thread_mpi/scan.c thread_mpi/tmpi_malloc.c)
71 endif (CMAKE_USE_WIN32_THREADS_INIT)
72 endif (CMAKE_USE_PTHREADS_INIT)
75 # the spin-waiting option
76 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)
77 mark_as_advanced(THREAD_MPI_WAIT_FOR_NO_ONE)
78 if (THREAD_MPI_WAIT_FOR_NO_ONE)
79 add_definitions(-DTMPI_WAIT_FOR_NO_ONE)
80 else (THREAD_MPI_WAIT_FOR_NO_ONE)
82 endif (THREAD_MPI_WAIT_FOR_NO_ONE)
85 # the copy buffer option
86 option(THREAD_MPI_COPY_BUFFER "Use an intermediate copy buffer for small message sizes, to allow blocking sends to return quickly." ON)
87 mark_as_advanced(THREAD_MPI_COPY_BUFFER)
88 if (THREAD_MPI_COPY_BUFFER)
90 else (THREAD_MPI_COPY_BUFFER)
91 add_definitions(-DTMPI_NO_COPY_BUFFER)
92 endif (THREAD_MPI_COPY_BUFFER)
95 # the profiling option
96 option(THREAD_MPI_PROFILING "Turn on simple MPI profiling." OFF)
97 mark_as_advanced(THREAD_MPI_PROFILING)
98 if (THREAD_MPI_PROFILING)
99 add_definitions(-DTMPI_PROFILE)
100 else (THREAD_MPI_PROFILING)
102 endif (THREAD_MPI_PROFILING)
104 include(CheckCSourceCompiles)
106 # option to set affinity
107 option(THREAD_MPI_SET_AFFINITY "Set thread affinity to a core if number of threads equal to number of hardware threads." ON)
108 mark_as_advanced(THREAD_MPI_SET_AFFINITY)
109 if (THREAD_MPI_SET_AFFINITY)
110 add_definitions(-DTMPI_SET_AFFINITY)
111 else (THREAD_MPI_SET_AFFINITY)
113 endif (THREAD_MPI_SET_AFFINITY)
115 include(CheckFunctionExists)
117 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
118 # check for sched_setaffinity
119 check_c_source_compiles(
125 int main(void) { cpu_set_t set;
128 pthread_setaffinity_np(pthread_self(), sizeof(set), &set);
133 if (PTHREAD_SETAFFINITY)
134 set(HAVE_PTHREAD_SETAFFINITY 1)
135 endif (PTHREAD_SETAFFINITY)
136 endif (THREAD_PTHREADS)
139 # this runs on POSIX systems
140 check_include_files(unistd.h HAVE_UNISTD_H)
141 check_include_files(sched.h HAVE_SCHED_H)
142 check_include_files(sys/time.h HAVE_SYS_TIME_H)
143 check_function_exists(sysconf HAVE_SYSCONF)
144 # this runs on windows
145 #check_include_files(windows.h HAVE_WINDOWS_H)
148 test_tmpi_atomics(TMPI_ATOMICS)