Fixed a memory leak in parse_common_args.
[gromacs/qmmm-gamess-us.git] / cmake / ThreadMPI.cmake
blobb0197aca2ee8c3954b653f35a5320e4cdcb9e04a
2 include(CheckIncludeFiles)
3 include(CheckFunctionExists)
4 #include(CheckCSourceCompiles)
6 #option(THREAD_PTHREADS "Use posix threads" ON)
8 include(FindThreads)
9 if (CMAKE_USE_PTHREADS_INIT)
10     check_include_files(pthread.h    HAVE_PTHREAD_H)
11     #set(THREAD_PTHREADS 1)
12     add_definitions(-DTHREAD_PTHREADS)
13     set(THREAD_MPI_SRC 
14         thread_mpi/profile.c     thread_mpi/barrier.c 
15         thread_mpi/collective.c  thread_mpi/reduce_fast.c
16         thread_mpi/comm.c        thread_mpi/errhandler.c  
17         thread_mpi/p2p.c         thread_mpi/event.c       
18         thread_mpi/threads.c     thread_mpi/tmpi_init.c
19         thread_mpi/group.c       thread_mpi/list.c
20         thread_mpi/topology.c    thread_mpi/type.c
21         thread_mpi/once.c        thread_mpi/hwinfo.c)
22     set(THREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
23 else (CMAKE_USE_PTHREADS_INIT)
24     if (CMAKE_USE_WIN32_THREADS_INIT)
25         set(THREAD_WINDOWS 1)
26         add_definitions(-DTHREAD_WINDOWS)
27         set(THREAD_MPI_SRC 
28             thread_mpi/profile.c     thread_mpi/barrier.c 
29             thread_mpi/collective.c  thread_mpi/reduce_fast.c
30             thread_mpi/comm.c        thread_mpi/errhandler.c  
31             thread_mpi/p2p.c         thread_mpi/event.c       
32             thread_mpi/threads.c     thread_mpi/tmpi_init.c
33             thread_mpi/group.c       thread_mpi/list.c
34             thread_mpi/topology.c    thread_mpi/type.c
35             thread_mpi/once.c        thread_mpi/hwinfo.c)
36         set(THREAD_LIBRARY )
37     endif (CMAKE_USE_WIN32_THREADS_INIT)
38 endif (CMAKE_USE_PTHREADS_INIT)
40 # the spin-waiting option
41 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)
42 mark_as_advanced(THREAD_MPI_WAIT_FOR_NO_ONE)
43 if (THREAD_MPI_WAIT_FOR_NO_ONE)
44     add_definitions(-DTMPI_WAIT_FOR_NO_ONE)
45 else (THREAD_MPI_WAIT_FOR_NO_ONE)
46     add_definitions()
47 endif (THREAD_MPI_WAIT_FOR_NO_ONE)
50 # the copy buffer option
51 option(THREAD_MPI_COPY_BUFFER "Use an intermediate copy buffer for small message sizes, to allow blocking sends to return quickly." ON)
52 mark_as_advanced(THREAD_MPI_COPY_BUFFER)
53 if (THREAD_MPI_COPY_BUFFER)
54     add_definitions()
55 else (THREAD_MPI_COPY_BUFFER)
56     add_definitions(-DTMPI_NO_COPY_BUFFER)
57 endif (THREAD_MPI_COPY_BUFFER)
60 # the profiling option
61 option(THREAD_MPI_PROFILING "Turn on simple MPI profiling." OFF)
62 mark_as_advanced(THREAD_MPI_PROFILING)
63 if (THREAD_MPI_PROFILING)
64     add_definitions(-DTMPI_PROFILE)
65 else (THREAD_MPI_PROFILING)
66     add_definitions()
67 endif (THREAD_MPI_PROFILING)
70 # this runs on POSIX systems
71 check_include_files(unistd.h        HAVE_UNISTD_H)
72 check_include_files(sched.h         HAVE_SCHED_H)
73 check_include_files(sys/time.h      HAVE_SYS_TIME_H)
74 check_function_exists(sysconf       HAVE_SYSCONF)
75 # this runs on windows
76 #check_include_files(windows.h          HAVE_WINDOWS_H)
77 #check_function_exists(GetSystemInfo HAVE_SYSTEM_INFO)
79 try_compile(TEST_ATOMICS "${CMAKE_BINARY_DIR}"
80             "${CMAKE_SOURCE_DIR}/cmake/TestAtomics.c"
81             COMPILE_DEFINITIONS "-I${CMAKE_SOURCE_DIR}/include" )
83 if (TEST_ATOMICS)
84     message(STATUS "Atomics found")
85     set(TMPI_ATOMICS 1)
86 else (TEST_ATOMICS)
87     message(WARNING "Atomics not found for this compiler+cpu combination. Thread support will be unbearably slow: disable threads.
88 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.
90     set(TMPI_ATOMICS 0)
91 endif(TEST_ATOMICS)