diff --git a/SuiteSparse_config/CMakeLists.txt b/SuiteSparse_config/CMakeLists.txt index eb3c85dead..96c3a7c7bc 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 147f51db17..000c056ad6 100644 --- a/SuiteSparse_config/Config/SuiteSparse_config.h.in +++ b/SuiteSparse_config/Config/SuiteSparse_config.h.in @@ -372,13 +372,17 @@ 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 - #define SUITESPARSE_TIME (SuiteSparse_time ( )) + #cmakedefine SUITESPARSE_CONFIG_TIMER @SUITESPARSE_CONFIG_TIMER@ + #if defined ( SUITESPARSE_TIMER_ENABLED ) + #if defined ( _OPENMP ) + // Avoid indirection through the library if the compilation unit + // including this header happens to use OpenMP. + #define SUITESPARSE_TIME (omp_get_wtime ( )) + #else + #define SUITESPARSE_TIME (SuiteSparse_time ( )) + #endif #else // No timer is available #define SUITESPARSE_TIME (0) diff --git a/SuiteSparse_config/SuiteSparse_config.h b/SuiteSparse_config/SuiteSparse_config.h index ea74cea254..064fadac37 100644 --- a/SuiteSparse_config/SuiteSparse_config.h +++ b/SuiteSparse_config/SuiteSparse_config.h @@ -372,13 +372,17 @@ 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_TIME (SuiteSparse_time ( )) + #define SUITESPARSE_CONFIG_TIMER omp_get_wtime + #if defined ( SUITESPARSE_TIMER_ENABLED ) + #if defined ( _OPENMP ) + // Avoid indirection through the library if the compilation unit + // including this header happens to use OpenMP. + #define SUITESPARSE_TIME (omp_get_wtime ( )) + #else + #define SUITESPARSE_TIME (SuiteSparse_time ( )) + #endif #else // No timer is available #define SUITESPARSE_TIME (0) diff --git a/UMFPACK/Source/umfpack_report_control.c b/UMFPACK/Source/umfpack_report_control.c index dbf6babd0f..3e92049ae9 100644 --- a/UMFPACK/Source/umfpack_report_control.c +++ b/UMFPACK/Source/umfpack_report_control.c @@ -14,6 +14,9 @@ #include "umf_internal.h" +#define xstr(s) str(s) +#define str(s) #s + void UMFPACK_report_control ( const double Control [UMFPACK_CONTROL] @@ -381,11 +384,7 @@ void UMFPACK_report_control PRINTF ((" CPU timer: ")) ; #ifdef SUITESPARSE_TIMER_ENABLED - #ifdef _OPENMP - PRINTF (("omp_get_wtime ( )\n")) ; - #else - PRINTF (("SuiteSparse_time ( )\n")) ; - #endif + 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 cc4791d1d9..9cd8a5551f 100644 --- a/UMFPACK/Source/umfpack_report_info.c +++ b/UMFPACK/Source/umfpack_report_info.c @@ -22,6 +22,9 @@ } \ } +#define xstr(s) str(s) +#define str(s) #s + /* RATIO macro uses a double relop, but ignore NaN case: */ #define RATIO(a,b,c) (((b) == 0) ? (c) : (((double) a)/((double) b))) @@ -160,11 +163,7 @@ void UMFPACK_report_info PRINTF ((" CPU timer: ")) ; #ifdef SUITESPARSE_TIMER_ENABLED - #ifdef _OPENMP - PRINTF (("omp_get_wtime ( )\n")) ; - #else - PRINTF (("SuiteSparse_time ( )\n")) ; - #endif + PRINTF (( xstr( SUITESPARSE_CONFIG_TIMER ) "\n")) ; #else PRINTF (("no timer used.\n")) ; #endif