diff --git a/lapack/CMakeLists.txt b/lapack/CMakeLists.txt index 8d6d75401..1babd136a 100644 --- a/lapack/CMakeLists.txt +++ b/lapack/CMakeLists.txt @@ -22,7 +22,7 @@ add_custom_target(lapack) include_directories(../blas) set(EigenLapack_SRCS -single.cpp double.cpp complex_single.cpp complex_double.cpp ../blas/xerbla.cpp + dsecnd_INT_CPU_TIME.cpp second_INT_CPU_TIME.cpp single.cpp double.cpp complex_single.cpp complex_double.cpp ../blas/xerbla.cpp ) if(EIGEN_Fortran_COMPILER_WORKS) @@ -38,7 +38,6 @@ set(EigenLapack_SRCS ${EigenLapack_SRCS} dlapy2.f dlapy3.f slapy2.f slapy3.f clacgv.f zlacgv.f slamch.f dlamch.f - second_NONE.f dsecnd_NONE.f ) option(EIGEN_ENABLE_LAPACK_TESTS OFF "Enable the Lapack unit tests") diff --git a/lapack/dsecnd_INT_CPU_TIME.cpp b/lapack/dsecnd_INT_CPU_TIME.cpp new file mode 100644 index 000000000..50521366c --- /dev/null +++ b/lapack/dsecnd_INT_CPU_TIME.cpp @@ -0,0 +1,36 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2024 The Eigen Authors +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifdef _WIN32 +#include +#define WIN32_LEAN_AND_MEAN +#include +#else +#include +#endif + +extern "C" { +double dsecnd_(); +} + +// Elapsed CPU Time in seconds. +double dsecnd_() { +#ifdef _WIN32 + // GetProcessTimes() uses 100-nanosecond time units. + FILETIME creation_time, exit_time, kernel_time, user_time; + GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time, &kernel_time, &user_time); + ULARGE_INTEGER user; + user.HighPart = user_time.dwHighDateTime; + user.LowPart = user_time.dwLowDateTime; + uint64_t time_100ns = user.QuadPart; + return static_cast(time_100ns) / 10000000.0; +#else + return static_cast(std::clock()) / static_cast(CLOCKS_PER_SEC); +#endif +} diff --git a/lapack/second_INT_CPU_TIME.cpp b/lapack/second_INT_CPU_TIME.cpp new file mode 100644 index 000000000..07231a34e --- /dev/null +++ b/lapack/second_INT_CPU_TIME.cpp @@ -0,0 +1,36 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2024 The Eigen Authors +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifdef _WIN32 +#include +#define WIN32_LEAN_AND_MEAN +#include +#else +#include +#endif + +extern "C" { +float second_(); +} + +// Elapsed CPU Time in seconds. +float second_() { +#ifdef _WIN32 + // GetProcessTimes() uses 100-nanosecond time units. + FILETIME creation_time, exit_time, kernel_time, user_time; + GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time, &kernel_time, &user_time); + ULARGE_INTEGER user; + user.HighPart = user_time.dwHighDateTime; + user.LowPart = user_time.dwLowDateTime; + uint64_t time_100ns = user.QuadPart; + return static_cast(time_100ns) / 10000000.0f; +#else + return static_cast(std::clock()) / static_cast(CLOCKS_PER_SEC); +#endif +}