Skip to content

Commit eb0febe

Browse files
committed
made metis also work with superlu_mt
1 parent d96c4e5 commit eb0febe

4 files changed

Lines changed: 734 additions & 52 deletions

File tree

superlu_mt_patches/CMakeLists.txt

Lines changed: 92 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required (VERSION 3.13)
1+
cmake_minimum_required(VERSION 3.13)
22

33
# Project Version
44
project(SuperLU_MT C)
@@ -12,8 +12,8 @@ set(PROJECT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BugFix})
1212
set(USE_XSDK_DEFAULTS TRUE)
1313

1414
# The XSDK standard does not allow using internally built BLAS
15-
if (NOT "${enable_internal_blaslib}" STREQUAL "")
16-
if (USE_XSDK_DEFAULTS)
15+
if(NOT "${enable_internal_blaslib}" STREQUAL "")
16+
if(USE_XSDK_DEFAULTS)
1717
set(enable_blaslib_xSDK OFF)
1818
else()
1919
set(enable_blaslib_xSDK ON)
@@ -22,8 +22,8 @@ else()
2222
set(enable_blaslib_xSDK ${enable_internal_blaslib})
2323
endif()
2424

25-
if (NOT "${enable_fortran}" STREQUAL "")
26-
if (XSDK_ENABLE_Fortran)
25+
if(NOT "${enable_fortran}" STREQUAL "")
26+
if(XSDK_ENABLE_Fortran)
2727
set(enable_fortran_xSDK ON)
2828
else()
2929
set(enable_fortran_xSDK OFF)
@@ -32,42 +32,43 @@ else()
3232
set(enable_fortran_xSDK ${enable_fortran})
3333
endif()
3434

35-
set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
35+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
3636

3737
# set up options
38-
option(enable_internal_blaslib "Build the CBLAS library" ${enable_blaslib_xSDK})
39-
option(enable_single "Enable single precision library" ON)
40-
option(enable_double "Enable double precision library" ON)
41-
option(enable_complex "Enable complex precision library" ON)
38+
option(enable_internal_blaslib "Build the CBLAS library" ${enable_blaslib_xSDK})
39+
option(enable_single "Enable single precision library" ON)
40+
option(enable_double "Enable double precision library" ON)
41+
option(enable_complex "Enable complex precision library" ON)
4242
option(enable_complex16 "Enable complex16 precision library" ON)
4343
option(enable_matlabmex "Build the Matlab mex library" OFF)
44-
option(enable_doc "Add target 'doc' to build Doxygen documentation" OFF)
45-
option(enable_examples "Build examples" ON)
46-
option(enable_fortran "Build Fortran interface" ${enable_fortran_xSDK})
47-
option(enable_tests "Build tests" ON)
48-
option (BUILD_SHARED_LIBS "shared/static" OFF)
49-
50-
include (GNUInstallDirs)
51-
include (CheckLibraryExists)
44+
option(enable_doc "Add target 'doc' to build Doxygen documentation" OFF)
45+
option(enable_examples "Build examples" ON)
46+
option(enable_fortran "Build Fortran interface" ${enable_fortran_xSDK})
47+
option(enable_tests "Build tests" ON)
48+
option(BUILD_SHARED_LIBS "shared/static" OFF)
49+
50+
include(GNUInstallDirs)
51+
include(CheckLibraryExists)
5252
check_library_exists(m sin "" HAVE_LIB_M)
5353

54-
######################################################################
54+
# #####################################################################
5555
#
5656
# Find packages
5757
#
58-
######################################################################
58+
# #####################################################################
5959
#
60-
###find_package (BLAS REQUIRED)
61-
#-- BLAS
62-
option(TPL_ENABLE_INTERNAL_BLASLIB "Build the CBLAS library" ${enable_internal_blaslib})
60+
# ##find_package (BLAS REQUIRED)
61+
# -- BLAS
62+
option(TPL_ENABLE_INTERNAL_BLASLIB "Build the CBLAS library" ${enable_internal_blaslib})
6363
option(TPL_BLAS_LIBRARIES "List of absolute paths to blas libraries [].")
6464

6565
if(NOT enable_internal_blaslib)
66-
if (TPL_BLAS_LIBRARIES)
66+
if(TPL_BLAS_LIBRARIES)
6767
set(BLAS_FOUND TRUE)
6868
else()
6969
find_package(BLAS)
70-
if (BLAS_FOUND)
70+
71+
if(BLAS_FOUND)
7172
set(TPL_BLAS_LIBRARIES "${BLAS_LIBRARIES}" CACHE FILEPATH
7273
"Set from FindBLAS.cmake BLAS_LIBRARIES." FORCE)
7374
endif()
@@ -78,49 +79,96 @@ if(BLAS_FOUND)
7879
message("-- Using TPL_BLAS_LIBRARIES='${TPL_BLAS_LIBRARIES}'")
7980
set(CMAKE_C_FLAGS "-DUSE_VENDOR_BLAS ${CMAKE_C_FLAGS}")
8081
set(BLAS_LIB ${TPL_BLAS_LIBRARIES})
82+
8183
# fix up BLAS library name
82-
string (REPLACE ";" " " BLAS_LIB_STR "${BLAS_LIB}")
84+
string(REPLACE ";" " " BLAS_LIB_STR "${BLAS_LIB}")
8385
set(BLAS_LIB_EXPORT ${BLAS_LIB_STR})
8486
else()
8587
message("-- Did not find or specify BLAS so configure to build internal CBLAS ...")
8688
add_subdirectory(CBLAS)
8789
set(BLAS_LIB blas)
88-
if (BUILD_SHARED_LIBS) # export to be referenced by downstream makefile
89-
set(BLAS_LIB_EXPORT ${CMAKE_INSTALL_PREFIX}/CBLAS/libblas.so)
90+
91+
if(BUILD_SHARED_LIBS) # export to be referenced by downstream makefile
92+
set(BLAS_LIB_EXPORT ${CMAKE_INSTALL_PREFIX}/CBLAS/libblas.so)
9093
else()
91-
set(BLAS_LIB_EXPORT ${CMAKE_INSTALL_PREFIX}/CBLAS/libblas.a)
94+
set(BLAS_LIB_EXPORT ${CMAKE_INSTALL_PREFIX}/CBLAS/libblas.a)
95+
endif()
96+
endif()
97+
98+
# -- METIS
99+
option(TPL_ENABLE_METISLIB "Build the METIS library" OFF)
100+
option(TPL_METIS_LIBRARIES "List of absolute paths to METIS link libraries [].")
101+
option(TPL_METIS_INCLUDE_DIRS "List of absolute paths to METIS include directories [].")
102+
103+
# --------------------- METIS ---------------------
104+
if(TPL_ENABLE_METISLIB) # # want to use metis
105+
if(NOT TPL_METIS_LIBRARIES)
106+
message(FATAL_ERROR "TPL_METIS_LIBRARIES option should be set for METIS support to be enabled.")
107+
endif()
108+
109+
if(NOT TPL_METIS_INCLUDE_DIRS)
110+
message(FATAL_ERROR "TPL_METIS_INCLUDE_DIRS option be set for METIS support to be enabled.")
111+
endif()
112+
113+
foreach(dir ${TPL_METIS_INCLUDE_DIRS})
114+
if(NOT MINGW AND NOT EXISTS ${dir})
115+
message(FATAL_ERROR "METIS include directory not found: ${dir}")
116+
endif()
117+
118+
set(CMAKE_C_FLAGS "-I${dir} ${CMAKE_C_FLAGS}")
119+
endforeach()
120+
121+
message("-- Enabled support for METIS.")
122+
set(METIS_FOUND TRUE)
123+
124+
set(METIS_LIB ${TPL_METIS_LIBRARIES})
125+
126+
# fix up METIS library names
127+
string(REPLACE ";" " " METIS_LIB_STR "${METIS_LIB}")
128+
set(METIS_LIB_EXPORT ${METIS_LIB_STR})
129+
else()
130+
message("-- Will not link with METIS.")
131+
endif()
132+
133+
if(METIS_FOUND)
134+
set(HAVE_METIS TRUE)
135+
136+
if(TPL_METIS_INCLUDE_DIRS)
137+
include_directories(${TPL_METIS_INCLUDE_DIRS})
92138
endif()
93139
endif()
94140

141+
set(PLAT "_OPENMP" CACHE STRING "threading flavor _PTHREAD/_OPENMP")
95142

96-
set (PLAT "_OPENMP" CACHE STRING "threading flavor _PTHREAD/_OPENMP")
97-
if (PLAT STREQUAL "_PTHREAD")
98-
find_package (Threads REQUIRED)
99-
elseif (PLAT STREQUAL "_OPENMP")
100-
find_package (OpenMP REQUIRED)
101-
else ()
102-
message (SEND_ERROR "invalid PLAT setting")
103-
endif ()
143+
if(PLAT STREQUAL "_PTHREAD")
144+
find_package(Threads REQUIRED)
145+
elseif(PLAT STREQUAL "_OPENMP")
146+
find_package(OpenMP REQUIRED)
147+
else()
148+
message(SEND_ERROR "invalid PLAT setting")
149+
endif()
104150

105-
option (LONGINT "use 64-bit integers for indexing sparse matrices (default is 32-bit)" OFF)
151+
option(LONGINT "use 64-bit integers for indexing sparse matrices (default is 32-bit)" OFF)
106152

107153
enable_language(C)
108-
if (enable_fortran)
154+
155+
if(enable_fortran)
109156
enable_language(Fortran)
110157
endif()
111-
set(SUPERLU_MT_VERSION "${PROJECT_VERSION}")
112158

159+
set(SUPERLU_MT_VERSION "${PROJECT_VERSION}")
113160

114-
set (SUPERLUMT_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/superlu_mt CACHE STRING "include dir")
161+
set(SUPERLUMT_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/superlu_mt CACHE STRING "include dir")
115162

116163
add_subdirectory(SRC)
164+
117165
# add_subdirectory(EXAMPLE)
118166

119167
# if(enable_tests)
120-
# enable_testing()
121-
# add_subdirectory(TESTING)
168+
# enable_testing()
169+
# add_subdirectory(TESTING)
122170
# endif()
123171

124172
# if (enable_doc)
125-
# add_subdirectory(DOC)
173+
# add_subdirectory(DOC)
126174
# endif()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
file(GLOB sources "*.c")
3+
add_library(superlu_mt${PLAT} ${sources})
4+
set_target_properties(superlu_mt${PLAT} PROPERTIES POSITION_INDEPENDENT_CODE ON)
5+
6+
set_property(TARGET superlu_mt${PLAT} PROPERTY C_STANDARD 99)
7+
8+
if(HAVE_LIB_M)
9+
target_link_libraries(superlu_mt${PLAT} PRIVATE m)
10+
endif()
11+
12+
target_link_libraries(superlu_mt${PLAT} PRIVATE ${BLAS_LIB})
13+
target_compile_definitions(superlu_mt${PLAT} PRIVATE Add_)
14+
15+
if(PLAT STREQUAL "_PTHREAD")
16+
target_compile_definitions(superlu_mt${PLAT} PUBLIC __PTHREAD)
17+
target_link_libraries(superlu_mt${PLAT} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
18+
elseif(PLAT STREQUAL "_OPENMP")
19+
target_compile_definitions(superlu_mt${PLAT} PUBLIC __OPENMP)
20+
target_link_libraries(superlu_mt${PLAT} PRIVATE OpenMP::OpenMP_C)
21+
endif()
22+
23+
if(LONGINT)
24+
target_compile_definitions(superlu_mt${PLAT} PUBLIC _LONGINT)
25+
endif()
26+
27+
if(HAVE_METIS)
28+
target_compile_definitions(superlu_mt${PLAT} PRIVATE HAVE_METIS)
29+
target_link_libraries(superlu_mt${PLAT} PRIVATE ${METIS_LIB})
30+
endif()
31+
32+
target_include_directories(superlu_mt${PLAT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
33+
target_include_directories(superlu_mt${PLAT} INTERFACE $<INSTALL_INTERFACE:include>)
34+
install(TARGETS superlu_mt${PLAT} DESTINATION ${CMAKE_INSTALL_LIBDIR})
35+
36+
file(GLOB headers "*.h")
37+
install(FILES ${headers} DESTINATION ${SUPERLUMT_INSTALL_INCLUDEDIR})

superlu_mt_patches/SRC/c_fortran_pdgssv.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ void c_fortran_pdgssv_(int *iopt, int *n, int_t *nnz, int *nrhs, int *nprocs,
113113
* permc_spec = 2: minimum degree on structure of A'+A
114114
* permc_spec = 3: approximate minimum degree for unsymmetric matrices (COLAMD)
115115
*/
116+
#if (HAVE_METIS)
117+
printf("USING METIS ORDERING\r\n");
118+
permc_spec = 6; /* METIS_AT_PLUS_A in MT SuperLU enum */
119+
#else
116120
permc_spec = COLAMD;
121+
#endif
117122
get_perm_c(permc_spec, &A, perm_c);
118123

119124
/* Initialize the option structure and apply column permutation */
@@ -210,7 +215,6 @@ void c_fortran_pdgssv_(int *iopt, int *n, int_t *nnz, int *nrhs, int *nprocs,
210215

211216
int c_side_slu_nthr = 0;
212217

213-
214218
#if (MACH == OPENMP)
215219
#include <omp.h>
216220
int sys_nproc() { return omp_get_max_threads(); }
@@ -219,21 +223,22 @@ int sys_nproc() { return omp_get_max_threads(); }
219223
int sys_nproc() { return 1; }
220224
#endif
221225

222-
223226
/* this can also be called from Fortran, to set the number of threads via
224227
* the SLU_NTHR PARAM.
225228
*/
226-
void slu_set_nthr_(int *nthr) {
227-
if (*nthr > 0) {
229+
void slu_set_nthr_(int *nthr)
230+
{
231+
if (*nthr > 0)
232+
{
228233
c_side_slu_nthr = *nthr;
229-
} else {
234+
}
235+
else
236+
{
230237
c_side_slu_nthr = sys_nproc();
231238
}
232239
printf(" SuperLU_MT will use %d threads.\n", c_side_slu_nthr);
233240
}
234241

235-
236-
237242
/* follows the signature we're used to from the single-threaded driver. */
238243
void c_fortran_dgssv_(int *iopt, int *n, int_t *nnz, int *nrhs,
239244
double *values, int_t *rowind, int_t *colptr,
@@ -242,7 +247,8 @@ void c_fortran_dgssv_(int *iopt, int *n, int_t *nnz, int *nrhs,
242247
pointing to the factored matrices */
243248
int_t *info)
244249
{
245-
if (c_side_slu_nthr < 1) {
250+
if (c_side_slu_nthr < 1)
251+
{
246252
c_side_slu_nthr = 0;
247253
slu_set_nthr_(&c_side_slu_nthr);
248254
}

0 commit comments

Comments
 (0)