Skip to content

Commit 11507f6

Browse files
authored
Merge pull request #182 from Bruno02468/use_superlu_mt
Multithreaded SuperLU support
2 parents 0a4b04f + 3bb874a commit 11507f6

16 files changed

Lines changed: 1532 additions & 365 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# previously here:
22
*.pdfx
33

4+
# profiler output
5+
gmon.out
6+
47
# CMake output directories:
58
Binaries/*
69

.gitmodules

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@
44
ignore = all
55
update = checkout
66
branch = master
7+
8+
[submodule "superlu_mt"]
9+
path = superlu_mt
10+
url = https://github.com/xiaoyeli/superlu_mt
11+
ignore = all
12+
update = checkout
13+
branch = master

CMakeLists.txt

Lines changed: 123 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ include(CheckFunctionExists)
99
project(Mystran)
1010
enable_language(Fortran)
1111

12+
if(WIN32)
13+
enable_language(RC)
14+
endif()
15+
1216
# basic compiler and output options
1317
set(CMAKE_SOURCE_DIR "${PROJECT_SOURCE_DIR}/Source")
1418
set(BLAS_SOURCE_DIR "${PROJECT_SOURCE_DIR}/BLAS")
@@ -25,6 +29,26 @@ include_directories("${CMAKE_SOURCE_DIR}/INCLUDE")
2529
# uncomment this to debug
2630
# set(CMAKE_VERBOSE_MAKEFILE true)
2731

32+
# a new build type for profiling
33+
set(CMAKE_PROFILING_FLAGS "-O2 -g -fno-omit-frame-pointer -fno-inline-functions")
34+
35+
set(CMAKE_C_FLAGS_PROFILING "${CMAKE_PROFILING_FLAGS}")
36+
set(CMAKE_CXX_FLAGS_PROFILING "${CMAKE_PROFILING_FLAGS}")
37+
set(CMAKE_Fortran_FLAGS_PROFILING "${CMAKE_PROFILING_FLAGS}")
38+
39+
set(CMAKE_EXE_LINKER_FLAGS_PROFILING "")
40+
set(CMAKE_SHARED_LINKER_FLAGS_PROFILING "")
41+
42+
# register the Profile build type, just in case
43+
set(CMAKE_CONFIGURATION_TYPES
44+
Debug
45+
Release
46+
RelWithDebInfo
47+
MinSizeRel
48+
Profiling
49+
CACHE STRING "" FORCE
50+
)
51+
2852
# suppress cmake warnings for superlu
2953
if(NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
3054
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE INTERNAL "No dev warnings")
@@ -60,25 +84,83 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
6084
endif()
6185
endif()
6286

63-
# check for SuperLU
6487
set(SUPERLU_DIR "${PROJECT_SOURCE_DIR}/superlu")
88+
set(SUPERLU_MT_DIR "${PROJECT_SOURCE_DIR}/superlu_mt")
89+
set(SUPERLU_PATCHES_DIR "${PROJECT_SOURCE_DIR}/superlu_mt_patches")
6590

66-
if(NOT EXISTS "${SUPERLU_DIR}/CMakeLists.txt")
67-
message(
68-
FATAL_ERROR
69-
"The submodules were not downloaded. You have to do it manually!"
70-
)
71-
endif()
91+
set(enable_examples OFF FORCE)
92+
set(enable_tests OFF FORCE)
93+
set(enable_doc OFF FORCE)
94+
95+
if(USE_SUPERLU_MT)
96+
message(STATUS "Will link against faster SuperLU_MT.")
97+
set(PLAT "_OPENMP" CACHE STRING "threading flavor _PTHREAD/_OPENMP" FORCE)
98+
message(STATUS "Applying patches to SuperLU_MT...")
99+
file(GLOB_RECURSE PATCH_FILES RELATIVE "${SUPERLU_PATCHES_DIR}" "${SUPERLU_PATCHES_DIR}/*")
100+
101+
foreach(file IN LISTS PATCH_FILES)
102+
set(src "${SUPERLU_PATCHES_DIR}/${file}")
103+
set(dst "${SUPERLU_MT_DIR}/${file}")
104+
105+
# ensure the destination directory exists
106+
get_filename_component(dst_dir "${dst}" DIRECTORY)
107+
file(MAKE_DIRECTORY "${dst_dir}")
108+
109+
# print the file being copied
110+
message(STATUS " Patching: ${file}")
111+
112+
# copy the file
113+
file(COPY "${src}" DESTINATION "${dst_dir}")
114+
endforeach()
115+
116+
message(STATUS "SuperLU_MT patched.")
117+
118+
if(NOT EXISTS "${SUPERLU_MT_DIR}/CMakeLists.txt")
119+
message(
120+
FATAL_ERROR
121+
"The SuperLU_MT submodule was not downloaded. You have to do it manually!"
122+
)
123+
endif()
72124

73-
# set some SuperLU settings
74-
set(enable_examples OFF)
75-
set(enable_tests OFF)
125+
if(WIN32)
126+
# force static linking to OpenMP library
127+
# temporarily set CMAKE_FIND_LIBRARY_SUFFIXES to prefer .a over .dll.a
128+
set(CMAKE_FIND_LIBRARY_SUFFIXES_BACKUP ${CMAKE_FIND_LIBRARY_SUFFIXES})
129+
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
76130

77-
# set(enable_internal_blaslib "yes")
131+
set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "" FORCE)
132+
set(OpenMP_C_LIB_NAMES "gomp" CACHE STRING "" FORCE)
78133

79-
# include & build it
80-
include_directories("${SUPERLU_DIR}/SRC")
81-
add_subdirectory(${SUPERLU_DIR})
134+
# find the static gomp library explicitly
135+
find_library(GOMP_STATIC_LIB NAMES libgomp.a gomp PATHS /mingw64/lib NO_DEFAULT_PATH)
136+
137+
if(GOMP_STATIC_LIB)
138+
set(OpenMP_gomp_LIBRARY "${GOMP_STATIC_LIB}" CACHE FILEPATH "" FORCE)
139+
endif()
140+
141+
find_package(OpenMP REQUIRED)
142+
143+
# restore original library suffixes
144+
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BACKUP})
145+
endif()
146+
147+
include_directories("${SUPERLU_MT_DIR}/SRC")
148+
add_subdirectory(${SUPERLU_MT_DIR})
149+
set(SLU_DRIVER "${SUPERLU_MT_DIR}/SRC/c_fortran_pdgssv.c")
150+
else()
151+
message(STATUS "Will link against regular SuperLU.")
152+
153+
if(NOT EXISTS "${SUPERLU_DIR}/CMakeLists.txt")
154+
message(
155+
FATAL_ERROR
156+
"The SuperLU submodule was not downloaded. You have to do it manually!"
157+
)
158+
endif()
159+
160+
include_directories("${SUPERLU_DIR}/SRC")
161+
add_subdirectory(${SUPERLU_DIR})
162+
set(SLU_DRIVER "${SUPERLU_DIR}/FORTRAN/c_fortran_dgssv.c")
163+
endif()
82164

83165
# f2c stuff
84166
set(F2C_DIR "${PROJECT_SOURCE_DIR}/f2c")
@@ -154,11 +236,18 @@ endif()
154236

155237
# set some extra vars for MSYS builds to make the binary portable
156238
if(WIN32)
157-
set(CMAKE_EXE_LINKER_FLAGS "-static")
239+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libgcc -static-libstdc++")
158240
endif()
159241

160242
# collect all fortran source files
161-
file(GLOB_RECURSE ALL_FORTRAN_FILES "${CMAKE_SOURCE_DIR}/*.f*")
243+
file(GLOB_RECURSE ALL_FORTRAN_FILES
244+
"${CMAKE_SOURCE_DIR}/*.f"
245+
"${CMAKE_SOURCE_DIR}/*.f90"
246+
"${CMAKE_SOURCE_DIR}/*.F90"
247+
"${CMAKE_SOURCE_DIR}/*.F"
248+
"${CMAKE_SOURCE_DIR}/*.F95"
249+
"${CMAKE_SOURCE_DIR}/*.f95"
250+
)
162251

163252
# same BLAS-finding subroutine as SuperLU
164253
if(NOT enable_internal_blaslib)
@@ -223,20 +312,32 @@ endif()
223312
add_executable(
224313
mystran
225314
${ALL_FORTRAN_FILES}
315+
${SLU_DRIVER}
226316
${missing_blas_src}
227-
"${SUPERLU_DIR}/FORTRAN/c_fortran_dgssv.c"
228317
)
229318

230-
# target_link_libraries(mystran MODULES ${modules_names})
231-
target_link_libraries(mystran superlu f2c)
319+
# determine which superlu variant to link against
320+
if(USE_SUPERLU_MT)
321+
if(PLAT STREQUAL "_PTHREAD")
322+
message(WARNING "We recommend using OpenMP, not pthread!")
323+
target_link_libraries(mystran superlu_mt_PTHREAD f2c)
324+
elseif(PLAT STREQUAL "_OPENMP")
325+
target_link_libraries(mystran superlu_mt_OPENMP f2c)
326+
endif()
327+
328+
target_compile_definitions(mystran PRIVATE USE_SUPERLU_MT)
329+
else()
330+
target_link_libraries(mystran superlu f2c)
331+
endif()
232332

233-
# if (MISSING_FNS_TOTAL GREATER 0)
234-
# target_link_libraries(mystran my_blas)
235-
# endif()
236333
set_target_properties(
237334
mystran PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
238335
)
239336

337+
if(WIN32)
338+
target_sources(mystran PRIVATE mystran.rc)
339+
endif()
340+
240341
if(CMAKE_COMPILER_IS_GNUCC)
241342
set(CMAKE_Fortran_FLAGS "-Wall -Wextra \
242343
-Wno-unused-variable -Wno-unused-label -Wno-unused-parameter -Wno-tabs \

0 commit comments

Comments
 (0)