From fe9cde9106ca7149b14cf811e25880cc3586dc59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Mon, 3 Jun 2024 23:20:36 +0200 Subject: [PATCH] SuiteSparse_config: Record in header if timer functions are available Record in "SuiteSparse_config.h" if working timer functions are available in libsuitesparse_config. Always indirect to `SuiteSparse_time` when dependent libraries use `SUITESPARSE_TIME`. Add new preprocessor macro `SUITESPARSE_CONFIG_TIMER` which records the function that is used by libsuitesparse_config for its timer functions. Use that new preprocessor macro in the reports of UMFPACK. --- SuiteSparse_config/CMakeLists.txt | 9 ++++++++- SuiteSparse_config/Config/SuiteSparse_config.h.in | 8 +++----- SuiteSparse_config/SuiteSparse_config.h | 8 +++----- UMFPACK/Source/umfpack_report_control.c | 2 +- UMFPACK/Source/umfpack_report_info.c | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/SuiteSparse_config/CMakeLists.txt b/SuiteSparse_config/CMakeLists.txt index eb3c85dea..96c3a7c7b 100644 --- a/SuiteSparse_config/CMakeLists.txt +++ b/SuiteSparse_config/CMakeLists.txt @@ -112,7 +112,14 @@ else ( ) endif ( ) endif ( ) -if ( NOT SUITESPARSE_CONFIG_USE_OPENMP AND NOT SUITESPARSE_HAVE_CLOCK_GETTIME ) +if ( SUITESPARSE_CONFIG_USE_OPENMP OR SUITESPARSE_HAVE_CLOCK_GETTIME ) + set ( SUITESPARSE_TIMER_ENABLED ON ) + if ( SUITESPARSE_CONFIG_USE_OPENMP ) + set ( SUITESPARSE_CONFIG_TIMER "omp_get_wtime" ) + else ( ) + set ( SUITESPARSE_CONFIG_TIMER "clock_gettime" ) + endif ( ) +else ( ) message ( STATUS "No OpenMP and no clock_gettime available. Timing functions won't work." ) endif ( ) diff --git a/SuiteSparse_config/Config/SuiteSparse_config.h.in b/SuiteSparse_config/Config/SuiteSparse_config.h.in index 147f51db1..5a7c0994e 100644 --- a/SuiteSparse_config/Config/SuiteSparse_config.h.in +++ b/SuiteSparse_config/Config/SuiteSparse_config.h.in @@ -372,12 +372,10 @@ int SuiteSparse_divcomplex // but other packages can themselves use OpenMP. In this case, // those packages should use omp_get_wtime() directly. This can // be done via the SUITESPARSE_TIME macro, defined below: + #cmakedefine SUITESPARSE_TIMER_ENABLED #cmakedefine SUITESPARSE_HAVE_CLOCK_GETTIME - #if defined ( _OPENMP ) - #define SUITESPARSE_TIMER_ENABLED - #define SUITESPARSE_TIME (omp_get_wtime ( )) - #elif defined ( SUITESPARSE_HAVE_CLOCK_GETTIME ) - #define SUITESPARSE_TIMER_ENABLED + #cmakedefine SUITESPARSE_CONFIG_TIMER @SUITESPARSE_CONFIG_TIMER@ + #if defined ( SUITESPARSE_TIMER_ENABLED ) #define SUITESPARSE_TIME (SuiteSparse_time ( )) #else // No timer is available diff --git a/SuiteSparse_config/SuiteSparse_config.h b/SuiteSparse_config/SuiteSparse_config.h index ea74cea25..b2c5a993a 100644 --- a/SuiteSparse_config/SuiteSparse_config.h +++ b/SuiteSparse_config/SuiteSparse_config.h @@ -372,12 +372,10 @@ int SuiteSparse_divcomplex // but other packages can themselves use OpenMP. In this case, // those packages should use omp_get_wtime() directly. This can // be done via the SUITESPARSE_TIME macro, defined below: + #define SUITESPARSE_TIMER_ENABLED #define SUITESPARSE_HAVE_CLOCK_GETTIME - #if defined ( _OPENMP ) - #define SUITESPARSE_TIMER_ENABLED - #define SUITESPARSE_TIME (omp_get_wtime ( )) - #elif defined ( SUITESPARSE_HAVE_CLOCK_GETTIME ) - #define SUITESPARSE_TIMER_ENABLED + #define SUITESPARSE_CONFIG_TIMER omp_get_wtime + #if defined ( SUITESPARSE_TIMER_ENABLED ) #define SUITESPARSE_TIME (SuiteSparse_time ( )) #else // No timer is available diff --git a/UMFPACK/Source/umfpack_report_control.c b/UMFPACK/Source/umfpack_report_control.c index eaa49e01d..3e92049ae 100644 --- a/UMFPACK/Source/umfpack_report_control.c +++ b/UMFPACK/Source/umfpack_report_control.c @@ -384,7 +384,7 @@ void UMFPACK_report_control PRINTF ((" CPU timer: ")) ; #ifdef SUITESPARSE_TIMER_ENABLED - PRINTF (( xstr( SUITESPARSE_TIME ) "\n")) ; + PRINTF (( xstr( SUITESPARSE_CONFIG_TIMER ) "\n")) ; #else PRINTF (("no timer used.\n")) ; #endif diff --git a/UMFPACK/Source/umfpack_report_info.c b/UMFPACK/Source/umfpack_report_info.c index d9454e7c7..9cd8a5551 100644 --- a/UMFPACK/Source/umfpack_report_info.c +++ b/UMFPACK/Source/umfpack_report_info.c @@ -163,7 +163,7 @@ void UMFPACK_report_info PRINTF ((" CPU timer: ")) ; #ifdef SUITESPARSE_TIMER_ENABLED - PRINTF (( xstr( SUITESPARSE_TIME ) "\n")) ; + PRINTF (( xstr( SUITESPARSE_CONFIG_TIMER ) "\n")) ; #else PRINTF (("no timer used.\n")) ; #endif