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} TRUE CACHE INTERNAL "Whether atomic operations for thread-MPI were found")
18 if (TEST_TMPI_ATOMICS_ONLY)
19 message(WARNING "Atomic operations not found for this CPU+compiler combination. 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.")
20 else (TEST_TMPI_ATOMICS_ONLY)
21 message(WARNING "Atomic operations not found for this
22 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.")
23 endif (TEST_TMPI_ATOMICS_ONLY)
24 set(${VARIABLE} FALSE CACHE INTERNAL "Whether atomic operations for thread-MPI were found")
26 endif(NOT DEFINED TMPI_ATOMICS)
27 ENDMACRO(TEST_TMPI_ATOMICS VARIABLE)
29 MACRO(TMPI_MAKE_CXX_LIB)
32 set(THREAD_MPI_CXX_SRC
33 thread_mpi/system_error.cpp )
34 ENDMACRO(TMPI_MAKE_CXX_LIB)
36 test_tmpi_atomics(TMPI_ATOMICS)
38 # do we want to only the atomics of tMPI (with GPU + MPI)
39 if(NOT TEST_TMPI_ATOMICS_ONLY)
41 if (CMAKE_USE_PTHREADS_INIT)
42 check_include_files(pthread.h HAVE_PTHREAD_H)
43 set(THREAD_PTHREADS 1)
44 #add_definitions(-DTHREAD_PTHREADS)
46 thread_mpi/alltoall.c thread_mpi/p2p_protocol.c
47 thread_mpi/barrier.c thread_mpi/p2p_send_recv.c
48 thread_mpi/bcast.c thread_mpi/p2p_wait.c
49 thread_mpi/collective.c thread_mpi/profile.c
50 thread_mpi/comm.c thread_mpi/pthreads.c
51 thread_mpi/errhandler.c thread_mpi/reduce.c
52 thread_mpi/event.c thread_mpi/reduce_fast.c
53 thread_mpi/gather.c thread_mpi/scatter.c
54 thread_mpi/group.c thread_mpi/tmpi_init.c
55 thread_mpi/topology.c thread_mpi/list.c
56 thread_mpi/type.c thread_mpi/lock.c
57 thread_mpi/numa_malloc.c thread_mpi/once.c
58 thread_mpi/scan.c thread_mpi/tmpi_malloc.c)
59 set(THREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
60 else (CMAKE_USE_PTHREADS_INIT)
61 if (CMAKE_USE_WIN32_THREADS_INIT)
63 #add_definitions(-DTHREAD_WINDOWS)
65 thread_mpi/alltoall.c thread_mpi/p2p_protocol.c
66 thread_mpi/barrier.c thread_mpi/p2p_send_recv.c
67 thread_mpi/bcast.c thread_mpi/p2p_wait.c
68 thread_mpi/collective.c thread_mpi/profile.c
70 thread_mpi/errhandler.c thread_mpi/reduce.c
71 thread_mpi/event.c thread_mpi/reduce_fast.c
72 thread_mpi/gather.c thread_mpi/scatter.c
73 thread_mpi/group.c thread_mpi/tmpi_init.c
74 thread_mpi/topology.c thread_mpi/list.c
75 thread_mpi/type.c thread_mpi/lock.c
76 thread_mpi/winthreads.c thread_mpi/once.c
77 thread_mpi/numa_malloc.c
78 thread_mpi/scan.c thread_mpi/tmpi_malloc.c)
80 endif (CMAKE_USE_WIN32_THREADS_INIT)
81 endif (CMAKE_USE_PTHREADS_INIT)
84 # the spin-waiting option
85 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)
86 mark_as_advanced(THREAD_MPI_WAIT_FOR_NO_ONE)
87 if (THREAD_MPI_WAIT_FOR_NO_ONE)
88 add_definitions(-DTMPI_WAIT_FOR_NO_ONE)
89 else (THREAD_MPI_WAIT_FOR_NO_ONE)
91 endif (THREAD_MPI_WAIT_FOR_NO_ONE)
94 # the copy buffer option
95 option(THREAD_MPI_COPY_BUFFER "Use an intermediate copy buffer for small message sizes, to allow blocking sends to return quickly." ON)
96 mark_as_advanced(THREAD_MPI_COPY_BUFFER)
97 if (THREAD_MPI_COPY_BUFFER)
99 else (THREAD_MPI_COPY_BUFFER)
100 add_definitions(-DTMPI_NO_COPY_BUFFER)
101 endif (THREAD_MPI_COPY_BUFFER)
104 # the profiling option
105 option(THREAD_MPI_PROFILING "Turn on simple MPI profiling." OFF)
106 mark_as_advanced(THREAD_MPI_PROFILING)
107 if (THREAD_MPI_PROFILING)
108 add_definitions(-DTMPI_PROFILE)
109 else (THREAD_MPI_PROFILING)
111 endif (THREAD_MPI_PROFILING)
113 include(CheckCSourceCompiles)
115 # option to set affinity
116 option(THREAD_MPI_SET_AFFINITY "Set thread affinity to a core if number of threads equal to number of hardware threads." ON)
117 mark_as_advanced(THREAD_MPI_SET_AFFINITY)
118 if (THREAD_MPI_SET_AFFINITY)
119 add_definitions(-DTMPI_SET_AFFINITY)
120 else (THREAD_MPI_SET_AFFINITY)
122 endif (THREAD_MPI_SET_AFFINITY)
124 include(CheckFunctionExists)
126 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
127 # check for sched_setaffinity
128 check_c_source_compiles(
134 int main(void) { cpu_set_t set;
137 pthread_setaffinity_np(pthread_self(), sizeof(set), &set);
142 if (PTHREAD_SETAFFINITY)
143 set(HAVE_PTHREAD_SETAFFINITY 1)
144 endif (PTHREAD_SETAFFINITY)
145 endif (THREAD_PTHREADS)
148 # this runs on POSIX systems
149 check_include_files(unistd.h HAVE_UNISTD_H)
150 check_include_files(sched.h HAVE_SCHED_H)
151 check_include_files(sys/time.h HAVE_SYS_TIME_H)
152 check_function_exists(sysconf HAVE_SYSCONF)
153 # this runs on windows
154 #check_include_files(windows.h HAVE_WINDOWS_H)
156 endif(NOT TEST_TMPI_ATOMICS_ONLY)