Debian Codegraph @

cmake/tribits/core/package_arch/TribitsSetupMPI.cmake

raw
1 # @HEADER
2 # *****************************************************************************
3 # TriBITS: Tribal Build, Integrate, and Test System
4 #
5 # Copyright 2013-2016 NTESS and the TriBITS contributors.
6 # SPDX-License-Identifier: BSD-3-Clause
7 # *****************************************************************************
8 # @HEADER
9
10 include(AdvancedSet)
11 include(MultilineSet)
12 include(PrintNonemptyVar)
13 include(FindProgramPlus)
14
15
16 function(tribits_extract_base_dir FILE_PATH BASE_DIR)
17 if (NOT ${BASE_DIR})
18 get_filename_component( ${BASE_DIR} ${FILE_PATH} PATH )
19 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
20 print_var(${BASE_DIR})
21 endif()
22 set(${BASE_DIR} ${${BASE_DIR}} PARENT_SCOPE)
23 endif()
24 endfunction()
25
26
27 macro(tribits_find_mpi_compiler LANG)
28 if (${PROJECT_NAME}_ENABLE_${LANG})
29 if (CMAKE_${LANG}_COMPILER)
30 message(STATUS "Leaving current CMAKE_${LANG}_COMPILER="
31 "${CMAKE_${LANG}_COMPILER} since it is already set!")
32 else()
33 find_program_plus(
34 MPI_${LANG}_COMPILER
35 NAMES ${ARGN}
36 PATHS ${MPI_BIN_DIR_PATHS}
37 )
38 tribits_extract_base_dir(${MPI_${LANG}_COMPILER} MPI_BASE_DIR)
39 message(STATUS "Setting CMAKE_${LANG}_COMPILER=\${MPI_${LANG}_COMPILER}")
40 set(CMAKE_${LANG}_COMPILER "${MPI_${LANG}_COMPILER}"
41 CACHE FILEPATH
42 "${LANG} compiler overridden by MPI_${LANG}_COMPILER")
43 print_var(CMAKE_${LANG}_COMPILER)
44 endif()
45 endif()
46 endmacro()
47
48
49 function(tribits_setup_mpi)
50
51 #
52 # A) Get the directory paths
53 #
54
55 multiline_set( DOC
56 "Base directory for the MPI implementation under which"
57 " the bin, include, and lib directories are found" )
58 advanced_set( MPI_BASE_DIR "" CACHE PATH ${DOC} )
59 print_nonempty_var(MPI_BASE_DIR)
60
61 if (MPI_BASE_DIR)
62 set(MPI_BIN_DIR_DEFAULT "${MPI_BASE_DIR}/bin")
63 else()
64 set(MPI_BIN_DIR_DEFAULT "")
65 endif()
66 multiline_set( DOC
67 "Path to the bin directory where the MPI compiler"
68 " and runtime executables are found" )
69 advanced_set( MPI_BIN_DIR ${MPI_BIN_DIR_DEFAULT} CACHE PATH ${DOC} )
70 print_nonempty_var(MPI_BIN_DIR)
71
72 multiline_set( DOC
73 "If set to 'ON', then the MPI compiler wrappers will be used."
74 " Set MPI_[C,CXX,Fortran]_COMPILER:FILEPATH=XXX to set compilers." )
75 advanced_set( MPI_USE_COMPILER_WRAPPERS ON CACHE BOOL ${DOC} )
76 print_var(MPI_USE_COMPILER_WRAPPERS)
77
78 file(TO_CMAKE_PATH "$ENV{ProgramFiles}" PROGRAM_FILES)
79 if(MPI_BIN_DIR)
80 set(MPI_BIN_DIR_PATHS ${MPI_BIN_DIR})
81 else()
82 set(MPI_BIN_DIR_PATHS
83 /usr/local/mpi/bin
84 /usr/local/bin
85 /usr/bin
86 "${PROGRAM_FILES}/Microsoft HPC Pack 2008 SDK/Bin"
87 "C:/Program Files/Microsoft HPC Pack 2008 SDK/Bin"
88 "${PROGRAM_FILES}/MPICH/SDK/Bin"
89 "${PROGRAM_FILES}/MPICH2/Bin"
90 "C:/Program Files/MPICH/SDK/Bin"
91 "C:/Program Files/MPICH2/Bin"
92 )
93 endif()
94
95 #
96 # B) Get the MPI compilers and/or just the raw include paths and libraries
97 #
98
99 if (MPI_USE_COMPILER_WRAPPERS)
100
101 # B.1) Set up to use the MPI wrappers
102
103 tribits_find_mpi_compiler(C mpicc)
104
105 tribits_find_mpi_compiler(CXX mpicxx mpic++ mpiCC)
106
107 tribits_find_mpi_compiler(Fortran mpif90 mpif77)
108
109 else()
110
111 # B.2) Set up to use raw configure options
112
113 advanced_set( MPI_COMPILE_FLAGS ""
114 CACHE STRING
115 "List of general compiler flags (excluding include directories)." )
116
117 advanced_set( MPI_LINK_FLAGS ""
118 CACHE STRING
119 "Link Flags for MPI executables." )
120
121 # NOTE: Test rest of the flags will be set up by the
122 # FindTPLMPI.cmake module!
123
124 endif()
125
126 #
127 # C) Get the MPI executable
128 #
129
130 find_program_plus( MPI_EXEC
131 NAMES mpiexec mpirun
132 PATHS ${MPI_BIN_DIR_PATHS}
133 DOC "MPI executable used to run MPI programs"
134 )
135 mark_as_advanced(MPI_EXEC)
136
137 if(MPI_EXEC)
138
139 get_filename_component( MPI_EXEC_NAME "${MPI_EXEC}" PATH )
140
141 if(MPI_EXEC_NAME STREQUAL mpiexec)
142 set(MPI_EXEC_NUMPROCS_FLAG_DEFAULT -n)
143 else()
144 set(MPI_EXEC_NUMPROCS_FLAG_DEFAULT -np)
145 endif()
146 advanced_set( MPI_EXEC_NUMPROCS_FLAG
147 ${MPI_EXEC_NUMPROCS_FLAG_DEFAULT}
148 CACHE STRING
149 "Flag setting the number of processors to use with MPI run command." )
150 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
151 print_nonempty_var(MPI_EXEC_NUMPROCS_FLAG)
152 endif()
153
154 advanced_set( MPI_EXEC_DEFAULT_NUMPROCS "4"
155 CACHE STRING
156 "The default number of processes to use when running MPI programs." )
157
158 if ( "${MPI_EXEC_MAX_NUMPROCS_DEFAULT}" STREQUAL "" )
159 set(MPI_EXEC_MAX_NUMPROCS_DEFAULT 4)
160 endif()
161 advanced_set( MPI_EXEC_MAX_NUMPROCS ${MPI_EXEC_MAX_NUMPROCS_DEFAULT}
162 CACHE STRING
163 "The maximum number of processes to use when running MPI programs. Tests with more procs are excluded." )
164
165 advanced_set( MPI_EXEC_PRE_NUMPROCS_FLAGS ""
166 CACHE STRING
167 "Extra command-line args to the MPI exec before num-procs args." )
168
169 advanced_set( MPI_EXEC_POST_NUMPROCS_FLAGS ""
170 CACHE STRING
171 "Extra command-line args to the MPI exec after num-procs args." )
172
173 endif()
174
175 #message(FATAL_ERROR "Stopping!")
176
177 endfunction()
178
179 # 2009/01/23: rabartl: ToDo: Above: create util find_program_path_first(...)
180 # in order to implement looking in the input path first and not last