Merge branch 'cmake' of github.com:sfilippone/psblas3 into cmake

newmatdist
sfilippone 1 year ago
commit b47dd764eb

@ -112,12 +112,12 @@ if(TRUE)#NOT ${WIN32})
message( STATUS "System appears to be little endian.")
add_compile_options(-DLittleEndian)
endif()
include(CheckTypeSize)
CHECK_TYPE_SIZE("void *" VOID_P_SIZE LANGUAGE C)
if(${VOID_P_SIZE} EQUAL 8)
add_compile_options(-DPtr64Bits)
endif()
message(STATUS "Have 64bit pointers")
# include(CheckTypeSize)
# CHECK_TYPE_SIZE("void *" VOID_P_SIZE LANGUAGE C)
# if(${VOID_P_SIZE} EQUAL 8)
# add_compile_options(-DPtr64Bits)
# endif()
# message(STATUS "Have 64bit pointers")
endif()
@ -141,12 +141,12 @@ endif()
set(IPK_SIZE ${CMAKE_PSB_IPK})
set(LPK_SIZE ${CMAKE_PSB_LPK})
# Define IPKDEF and LPKDEF based on the sizes
set(IPKDEF "#define PSB_IPK${IPK_SIZE}")
set(LPKDEF "#define PSB_LPK${LPK_SIZE}")
set(PSB_IPKDEF "#define PSB_IPK${IPK_SIZE}")
set(PSB_LPKDEF "#define PSB_LPK${LPK_SIZE}")
# Output the definitions for verification
message(STATUS "Using IPKDEF: ${IPKDEF}")
message(STATUS "Using LPKDEF: ${LPKDEF}")
message(STATUS "Using IPKDEF: ${PSB_IPKDEF}")
message(STATUS "Using LPKDEF: ${PSB_LPKDEF}")
add_compile_options(-DPSB_IPK${IPK_SIZE})
add_compile_options(-DPSB_LPK${LPK_SIZE})
@ -180,8 +180,8 @@ CHECK_Fortran_SOURCE_COMPILES(
SRC_EXT f90
)
if(HAVE_VOLATILE)
add_compile_options(-DHAVE_VOLATILE)
message(STATUS "-DHAVE_VOLATILE")
add_compile_options(-DPSB_HAVE_VOLATILE)
message(STATUS "-DPSB_HAVE_VOLATILE")
endif()
CHECK_Fortran_SOURCE_COMPILES(
"use ISO_FORTRAN_ENV ; end"
@ -189,8 +189,8 @@ CHECK_Fortran_SOURCE_COMPILES(
SRC_EXT f90
)
if(HAVE_ISO_FORTRAN_ENV)
add_compile_options(-DHAVE_ISO_FORTRAN_ENV)
message(STATUS "-DHAVE_ISO_FORTRAN_ENV")
add_compile_options(-DPSB_HAVE_ISO_FORTRAN_ENV)
message(STATUS "-DPSB_HAVE_ISO_FORTRAN_ENV")
endif()
CHECK_Fortran_SOURCE_COMPILES(
"flush(5); end"
@ -198,8 +198,8 @@ CHECK_Fortran_SOURCE_COMPILES(
SRC_EXT f90
)
if(HAVE_FLUSH_STMT)
add_compile_options(-DHAVE_FLUSH_STMT)
message(STATUS "-DHAVE_FLUSH_STMT")
add_compile_options(-DPSB_HAVE_FLUSH_STMT)
message(STATUS "-DPSB_HAVE_FLUSH_STMT")
endif()
CHECK_Fortran_SOURCE_COMPILES(
"
@ -224,8 +224,8 @@ end program"
SRC_EXT f90
)
if(HAVE_FINAL)
add_compile_options(-DHAVE_FINAL)
message(STATUS "-DHAVE_FINAL")
add_compile_options(-DPSB_HAVE_FINAL)
message(STATUS "-DPSB_HAVE_FINAL")
endif()
CHECK_Fortran_SOURCE_COMPILES(
"
@ -334,13 +334,13 @@ message(STATUS "${MPI_C_INCLUDE_PATH}; ${MPI_Fortran_INCLUDE_PATH};; ${CMAKE_For
#add_compile_options(-DSERIAL_MPI) # Is it right??
#message(STATUS "-DSERIAL_MPI")
endif()
set(SERIAL_MPI OFF)
set(PSB_SERIAL_MPI OFF)
else()
message(STATUS "MPI not found, serial ahead")
add_compile_options(-DPSB_SERIAL_MPI)
add_compile_options(-DPSB_MPI_MOD)
set(SERIAL_MPI ON)
set(PSB_SERIAL_MPI ON)
set(CSERIALMPI "#define PSB_SERIAL_MPI")
endif()
@ -361,7 +361,7 @@ if(NOT APPLE)
endif()
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
add_compile_options(-DHAVE_LAPACK)
add_compile_options(-DPSB_HAVE_LAPACK)
#--------------------------------
@ -371,6 +371,106 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/FindMETIS.cmake)
find_package(METIS)
if(METIS_FOUND)
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
# Specify the configuration file
set(HEADER_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/util/psb_metis_int.h.in")
set(HEADER_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/psb_metis_int.h")
# Configure the header file
configure_file(${HEADER_TEMPLATE} ${HEADER_OUTPUT} @ONLY)
# 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 "
#include <metis.h>
#include <stdio.h>
int main() {
printf(\"%zu\\n\", sizeof(${type_name}));
return 0;
}")
# Create a temporary source file
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")
# Check the result and read the output
if (COMPILER_RESULT)
execute_process(COMMAND "${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/test_size"
OUTPUT_VARIABLE type_size)
string(STRIP "${type_size}" type_size)
if (type_name STREQUAL "float")
set(PSB_METIS_REAL_32 "${type_size}" PARENT_SCOPE)
add_definitions(-DPSB_METIS_REAL_32)
elseif (type_name STREQUAL "double")
set(PSB_METIS_REAL_64 "${type_size}" PARENT_SCOPE)
add_definitions(-DPSB_METIS_REAL_64)
endif()
else()
message(WARNING "Failed to compile test for type size: ${type_name}")
endif()
endfunction()
# 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)
# Determine METIS_INDEX based on real type sizes
if(DEFINED PSB_METIS_REAL_32)
set(METIS_INDEX 32)
elseif(DEFINED PSB_METIS_REAL_64)
set(METIS_INDEX 64)
else()
message(WARNING "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")
# Mismatch between METIS size and PSBLAS LPK
message(FATAL " Mismatch between metis ${METIS_INDEX} size and psblas LPK size ${LPK_SIZE}")
endif()
endif()
if(LPK_SIZE STREQUAL "8")
if(METIS_INDEX STREQUAL "32")
# Mismatch between METIS size and PSBLAS LPK
message(FATAL " Mismatch between metis ${METIS_INDEX} size and psblas LPK size ${LPK_SIZE}")
endif()
endif()
set(CHAVEMETIS "#define PSB_HAVE_METIS")
set(CINTMETIS "#define PSB_METIS_${IPK_SIZE}")
set(CREALMETIS "#define PSB_METIS_REAL_${LPK_SIZE}")
endif()
#---------------------------------------------------
# Use standardized GNU install directory conventions
#---------------------------------------------------
@ -656,104 +756,9 @@ target_include_directories(util PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/modules>
$<INSTALL_INTERFACE:modules>)
target_link_libraries(util PUBLIC base prec)
if(METIS_FOUND)
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
# Specify the configuration file
set(HEADER_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/util/psb_metis_int.h.in")
set(HEADER_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/psb_metis_int.h")
# Configure the header file
configure_file(${HEADER_TEMPLATE} ${HEADER_OUTPUT} @ONLY)
# 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 "
#include <metis.h>
#include <stdio.h>
int main() {
printf(\"%zu\\n\", sizeof(${type_name}));
return 0;
}")
# Create a temporary source file
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")
# Check the result and read the output
if (COMPILER_RESULT)
execute_process(COMMAND "${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/test_size"
OUTPUT_VARIABLE type_size)
string(STRIP "${type_size}" type_size)
if (type_name STREQUAL "float")
set(METIS_REAL_32 "${type_size}" PARENT_SCOPE)
add_definitions(-DMETIS_REAL_32)
elseif (type_name STREQUAL "double")
set(METIS_REAL_64 "${type_size}" PARENT_SCOPE)
add_definitions(-DMETIS_REAL_64)
endif()
else()
message(WARNING "Failed to compile test for type size: ${type_name}")
endif()
endfunction()
# 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)
# Determine METIS_INDEX based on real type sizes
if(DEFINED METIS_REAL_32)
set(METIS_INDEX 32)
elseif(DEFINED METIS_REAL_64)
set(METIS_INDEX 64)
else()
message(WARNING "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")
# Mismatch between METIS size and PSBLAS LPK
message(FATAL " Mismatch between metis ${METIS_INDEX} size and psblas LPK size ${LPK_SIZE}")
endif()
endif()
if(LPK_SIZE STREQUAL "8")
if(METIS_INDEX STREQUAL "32")
# Mismatch between METIS size and PSBLAS LPK
message(FATAL " Mismatch between metis ${METIS_INDEX} size and psblas LPK size ${LPK_SIZE}")
endif()
endif()
set(CHAVEMETIS "#define PSB_HAVE_METIS")
set(CINTMETIS "#define PSB_METIS_${IPK_SIZE}")
set(CREALMETIS "#define PSB_METIS_REAL_${LPK_SIZE}")
if(METIS_FOUND)
target_include_directories(util
PUBLIC ${METIS_INCLUDES})
target_include_directories(psb_util_C
@ -761,9 +766,9 @@ if(METIS_FOUND)
target_link_libraries(util
PUBLIC ${METIS_LIBRARIES})
target_compile_definitions(psb_util_C
PUBLIC HAVE_METIS_) #TDDO: CHECK IF THAT _ IS CORRECT
PUBLIC PSB_HAVE_METIS) #TDDO: CHECK IF THAT _ IS CORRECT
target_compile_definitions(util
PUBLIC HAVE_METIS)
PUBLIC PSB_HAVE_METIS)
endif()

@ -631,9 +631,13 @@ endforeach()
list(APPEND PSB_base_source_C_files modules/cutil.c)
list(APPEND PSB_base_source_C_files modules/desc/psb_hashval.c)
if (SERIAL_MPI)
list(APPEND PSB_base_source_C_files modules/fakempi.c)
if (PSB_SERIAL_MPI)
list(APPEND PSB_base_source_C_files modules/psb_fakempi.c)
list(APPEND base_header_C_files ${CMAKE_CURRENT_LIST_DIR}/modules/psb_fakempi.h)
endif()
list(APPEND base_header_C_files ${CMAKE_CURRENT_LIST_DIR}/modules/psb_types.h)
foreach(file IN LISTS PSB_base_source_C_files)
list(APPEND base_source_C_files ${CMAKE_CURRENT_LIST_DIR}/${file})
endforeach()

@ -55,7 +55,7 @@ list(APPEND PSB_cbind_source_C_files
prec/psb_c_cprec.c
prec/psb_c_zprec.c
prec/psb_c_sprec.c
#test/pargen/ppdec.c
test/pdegen/pdegen3dc.c
)

Loading…
Cancel
Save