mirror of
https://github.com/sfilippone/psblas3.git
synced 2026-10-07 07:04:57 +00:00
fix metis real type and IPK/LPK interaction
This commit is contained in:
+70
-11
@@ -427,6 +427,7 @@ find_package(METIS)
|
||||
|
||||
|
||||
if(METIS_FOUND)
|
||||
include(CheckTypeSize)
|
||||
message(STATUS "METIS PATH ${METIS_INCLUDES} and metis libraries ${METIS_LIBRARIES}")
|
||||
# Make sure this path is correct
|
||||
# set(METISINCFILE "metis.h") # Adjust this to your actual path
|
||||
@@ -444,6 +445,9 @@ if(METIS_FOUND)
|
||||
# Check for real sizes using try_compile
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
|
||||
|
||||
#[=====[
|
||||
# Function to check the size of a type
|
||||
function(check_metis_real_type type_name)
|
||||
set(source_code "
|
||||
@@ -455,25 +459,42 @@ if(METIS_FOUND)
|
||||
}")
|
||||
|
||||
# Create a temporary source file
|
||||
file(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/test_size.c" "${source_code}")
|
||||
#file(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/test_size.c" "${source_code}")
|
||||
|
||||
# Try to compile it
|
||||
try_compile(COMPILER_RESULT "${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp"
|
||||
"${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/test_size.c")
|
||||
#try_compile(COMPILER_RESULT "${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp"
|
||||
# "${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/test_size.c")
|
||||
|
||||
# Check the result and read the output
|
||||
if (COMPILER_RESULT)
|
||||
|
||||
set(test_file "${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/test_metis_size.c")
|
||||
file(WRITE "${test_file}" "${source_code}")
|
||||
|
||||
# Use try_run to compile AND execute
|
||||
try_run(RUN_RESULT COMPILE_RESULT
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${test_file}"
|
||||
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${METIS_INCLUDES}"
|
||||
RUN_OUTPUT_VARIABLE type_size
|
||||
COMPILE_OUTPUT_VARIABLE compile_log
|
||||
)
|
||||
|
||||
if(COMPILE_RESULT AND (RUN_RESULT EQUAL 0))
|
||||
# if (COMPILER_RESULT)
|
||||
execute_process(COMMAND "${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/test_size"
|
||||
OUTPUT_VARIABLE type_size)
|
||||
string(STRIP "${type_size}" type_size)
|
||||
message(STATUS "Metis ?: ${type_size};")
|
||||
if (type_name STREQUAL "float")
|
||||
set(PSB_METIS_REAL_32 "${type_size}" PARENT_SCOPE)
|
||||
message(STATUS "Metis 32: ${type_size}")
|
||||
# add_definitions(-DPSB_METIS_REAL_32)
|
||||
set(CREALMETIS "#define PSB_METIS_REAL_32" PARENT_SCOPE)
|
||||
elseif (type_name STREQUAL "double")
|
||||
set(PSB_METIS_REAL_64 "${type_size}" PARENT_SCOPE)
|
||||
#add_definitions(-DPSB_METIS_REAL_64)
|
||||
set(CREALMETIS "#define PSB_METIS_REAL_64" PARENT_SCOPE)
|
||||
set(CREALMETIS "#define PSB_METIS_REAL_64" PARENT_SCOPE)
|
||||
message(STATUS "Metis 64: ${type_size}")
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "Failed to compile test for type size: ${type_name}")
|
||||
@@ -483,26 +504,64 @@ if(METIS_FOUND)
|
||||
# Check for both float and double
|
||||
check_metis_real_type(float)
|
||||
check_metis_real_type(double)
|
||||
|
||||
#]=====]
|
||||
# Set HAVE_METIS if METIS is found
|
||||
#add_compile_options(-DPSB_HAVE_METIS)
|
||||
# set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DPSB_HAVE_METIS")
|
||||
|
||||
|
||||
# 1. Tell CMake where to find metis.h for the check
|
||||
set(CMAKE_EXTRA_INCLUDE_FILES "${METIS_INCLUDES}/metis.h")
|
||||
|
||||
# 2. Check the size of Metis's own type: real_t
|
||||
# This replaces checking 'float' and 'double' separately
|
||||
check_type_size("real_t" METIS_REAL_SIZE)
|
||||
|
||||
# 3. Handle the result
|
||||
if(METIS_REAL_SIZE)
|
||||
if(METIS_REAL_SIZE EQUAL 4)
|
||||
set(METIS_INDEX 32)
|
||||
set(CREALMETIS "#define PSB_METIS_REAL_32")
|
||||
message(STATUS "Metis detected as 32-bit (real_t is 4 bytes)")
|
||||
elseif(METIS_REAL_SIZE EQUAL 8)
|
||||
set(METIS_INDEX 64)
|
||||
set(CREALMETIS "#define PSB_METIS_REAL_64")
|
||||
message(STATUS "Metis detected as 64-bit (real_t is 8 bytes)")
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "Could not determine size of real_t from metis.h. Check METIS_INCLUDES.")
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
|
||||
# clean the variable
|
||||
set(CMAKE_EXTRA_INCLUDE_FILES "")
|
||||
|
||||
# Mismatch Logic Below
|
||||
if(LPK_SIZE STREQUAL "4" AND METIS_INDEX EQUAL 64)
|
||||
message(WARNING "Mismatch: Metis is 64-bit but PSBLAS LPK is 32-bit")
|
||||
set(METIS_FOUND FALSE)
|
||||
set(CREALMETIS "")
|
||||
endif()
|
||||
|
||||
if(LPK_SIZE STREQUAL "8" AND METIS_INDEX EQUAL 32)
|
||||
set(METIS_FOUND FALSE)
|
||||
set(CREALMETIS "")
|
||||
message(WARNING "Mismatch: Metis is 32-bit but PSBLAS LPK is 64-bit")
|
||||
endif()
|
||||
|
||||
#[=====[
|
||||
# Determine METIS_INDEX based on real type sizes
|
||||
if(DEFINED PSB_METIS_REAL_32)
|
||||
set(METIS_INDEX 32)
|
||||
message(WARNING "Metis 32: ${METIS_INDEX}")
|
||||
elseif(DEFINED PSB_METIS_REAL_64)
|
||||
set(METIS_INDEX 64)
|
||||
message(STATUS "Metis 64: ${METIS_INDEX}")
|
||||
else()
|
||||
message(WARNING "Neither METIS_REAL_32 nor METIS_REAL_64 is defined.")
|
||||
message(STATUS "Neither METIS_REAL_32 nor METIS_REAL_64 is defined.")
|
||||
set(METIS_INDEX 64) # Default to 64 if not defined
|
||||
endif()
|
||||
|
||||
|
||||
# Check conditions for LPK_SIZE and METIS_INDEX
|
||||
if(LPK_SIZE STREQUAL "4")
|
||||
if(METIS_INDEX STREQUAL "64")
|
||||
@@ -519,7 +578,7 @@ if(METIS_FOUND)
|
||||
set(METIS_FOUND FALSE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#]=====]
|
||||
if(METIS_FOUND)
|
||||
|
||||
# Make sure this path is correct
|
||||
|
||||
Reference in New Issue
Block a user