Skip to content

Commit b37ac18

Browse files
authored
Merge pull request #219 from Bruno02468/metis_fixes
METIS/MT fixes
2 parents 090b5ae + 3b39e7f commit b37ac18

8 files changed

Lines changed: 777 additions & 75 deletions

File tree

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ set(METIS_PATCHES_DIR "${PROJECT_SOURCE_DIR}/metis/metis_patches")
8989
if(NOT DEFINED TPL_ENABLE_METISLIB)
9090
set(TPL_ENABLE_METISLIB ON CACHE BOOL "Enable METIS for SuperLU")
9191
endif()
92+
9293
if(TPL_ENABLE_METISLIB)
9394
if(NOT EXISTS "${GKLIB_DIR}/CMakeLists.txt")
9495
message(FATAL_ERROR "The GKlib submodule was not downloaded.")
9596
endif()
97+
9698
if(NOT EXISTS "${METIS_DIR}/CMakeLists.txt")
9799
message(FATAL_ERROR "The METIS submodule was not downloaded.")
98100
endif()
@@ -199,6 +201,15 @@ if(USE_SUPERLU_MT)
199201

200202
include_directories("${SUPERLU_MT_DIR}/SRC")
201203
add_subdirectory(${SUPERLU_MT_DIR})
204+
205+
if(TPL_ENABLE_METISLIB)
206+
if(PLAT STREQUAL "_PTHREAD")
207+
add_dependencies(superlu_mt_PTHREAD metis GKlib)
208+
elseif(PLAT STREQUAL "_OPENMP")
209+
add_dependencies(superlu_mt_OPENMP metis GKlib)
210+
endif()
211+
endif()
212+
202213
set(SLU_DRIVER "${SUPERLU_MT_DIR}/SRC/c_fortran_pdgssv.c")
203214
else()
204215
message(STATUS "Will link against regular SuperLU.")
@@ -212,9 +223,11 @@ else()
212223

213224
include_directories("${SUPERLU_DIR}/SRC")
214225
add_subdirectory(${SUPERLU_DIR})
226+
215227
if(TPL_ENABLE_METISLIB)
216228
add_dependencies(superlu metis GKlib)
217229
endif()
230+
218231
set(SLU_DRIVER "${SUPERLU_DIR}/FORTRAN/c_fortran_dgssv.c")
219232
endif()
220233

@@ -384,6 +397,10 @@ if(USE_SUPERLU_MT)
384397
endif()
385398

386399
target_compile_definitions(mystran PRIVATE USE_SUPERLU_MT)
400+
401+
if(TPL_ENABLE_METISLIB)
402+
target_compile_definitions(mystran PRIVATE HAVE_METIS)
403+
endif()
387404
else()
388405
target_link_libraries(mystran superlu f2c)
389406
endif()

Source/Modules/PARAMS.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,9 @@ MODULE PARAMS
504504
INTEGER(LONG) :: F06_COL_START = 0 ! 1st col in F06 file for output data to begin. If it is not > 2, then
505505
! output will be written with each main header centered on one another
506506

507-
INTEGER(LONG) :: SPIENV6 = 100 ! Memory growth factor for SuperLU_MT -- corresponds to -sp_ienv(6)
508-
INTEGER(LONG) :: SPIENV7 = 100 ! Memory growth factor for SuperLU_MT -- corresponds to -sp_ienv(7)
509-
INTEGER(LONG) :: SPIENV8 = 50 ! Memory growth factor for SuperLU_MT -- corresponds to -sp_ienv(8)
507+
INTEGER(LONG) :: SPIENV6 = 50 ! Memory growth factor for SuperLU_MT -- corresponds to -sp_ienv(6)
508+
INTEGER(LONG) :: SPIENV7 = 50 ! Memory growth factor for SuperLU_MT -- corresponds to -sp_ienv(7)
509+
INTEGER(LONG) :: SPIENV8 = 30 ! Memory growth factor for SuperLU_MT -- corresponds to -sp_ienv(8)
510510

511511
INTEGER(LONG) :: SLU_NTHR = 0 ! Number of threads for SuperLU_MT.
512512
! Using 0 will use as many threads as the system has.

metis/metis_patches/CMakeLists.txt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(METIS C)
3+
set(CMAKE_C_STANDARD 99)
34

45
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
56
set(SHARED FALSE CACHE BOOL "build a shared library")
@@ -21,27 +22,28 @@ endif(SHARED)
2122
include(./conf/gkbuild.cmake)
2223

2324
# METIS' custom options
24-
#option(IDX64 "enable 64 bit ints" OFF)
25-
#option(REAL64 "enable 64 bit floats (i.e., double)" OFF)
26-
#if(IDX64)
27-
# set(METIS_COPTIONS "${METIS_COPTIONS} -DIDXTYPEWIDTH=64")
28-
#else()
29-
# set(METIS_COPTIONS "${METIS_COPTIONS} -DIDXTYPEWIDTH=32")
30-
#endif(IDX64)
31-
#if(REAL64)
32-
# set(METIS_COPTIONS "${METIS_COPTIONS} -DREALTYPEWIDTH=64")
33-
#else()
34-
# set(METIS_COPTIONS "${METIS_COPTIONS} -DREALTYPEWIDTH=32")
35-
#endif(REAL64)
36-
#
37-
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${METIS_COPTIONS}")
25+
option(IDX64 "enable 64 bit ints" OFF)
26+
option(REAL64 "enable 64 bit floats (i.e., double)" ON)
3827

28+
if(IDX64)
29+
set(_metis_idxwidth 64)
30+
else()
31+
set(_metis_idxwidth 32)
32+
endif()
33+
34+
if(REAL64)
35+
set(_metis_realwidth 64)
36+
else()
37+
set(_metis_realwidth 32)
38+
endif()
3939

40+
# Generate a metis.h in the build tree that prepends the width defines.
41+
# Read the source header FIRST so an in-source build cannot corrupt the original.
4042
set(METIS_GENERATED_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
4143
file(MAKE_DIRECTORY "${METIS_GENERATED_INCLUDE_DIR}")
42-
file(WRITE "${METIS_GENERATED_INCLUDE_DIR}/metis.h" "#define IDXTYPEWIDTH 32\n#define REALTYPEWIDTH 32\n")
43-
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/metis.h" METIS_PUBLIC_HEADER)
44-
file(APPEND "${METIS_GENERATED_INCLUDE_DIR}/metis.h" "${METIS_PUBLIC_HEADER}")
44+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/metis.h" _metis_public_header)
45+
file(WRITE "${METIS_GENERATED_INCLUDE_DIR}/metis.h"
46+
"#define IDXTYPEWIDTH ${_metis_idxwidth}\n#define REALTYPEWIDTH ${_metis_realwidth}\n${_metis_public_header}")
4547

4648
# Add include directories.
4749
# i.e., the -I equivalent
@@ -56,6 +58,7 @@ link_directories(${CMAKE_INSTALL_PREFIX}/lib)
5658

5759
# Recursively look for CMakeLists.txt in subdirs.
5860
add_subdirectory("libmetis")
61+
5962
if(METIS_BUILD_PROGRAMS)
6063
add_subdirectory("programs")
6164
endif()

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})

0 commit comments

Comments
 (0)