From bbe540eaf4c1535e0dfc027544204e7db44bd2db Mon Sep 17 00:00:00 2001 From: congyu711 Date: Tue, 26 Mar 2024 18:22:43 +0800 Subject: [PATCH] replace system_clock with high_resolution_clock --- include/ode_solvers/implicit_midpoint.hpp | 12 ++++---- include/preprocess/crhmc/crhmc_problem.h | 36 +++++++++++------------ include/random_walks/crhmc/crhmc_walk.hpp | 4 +-- test/benchmarks_crhmc.cpp | 8 ++--- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/ode_solvers/implicit_midpoint.hpp b/include/ode_solvers/implicit_midpoint.hpp index 786734d84..7efba90ec 100644 --- a/include/ode_solvers/implicit_midpoint.hpp +++ b/include/ode_solvers/implicit_midpoint.hpp @@ -104,11 +104,11 @@ struct ImplicitMidpointODESolver { num_runs++; pts partialDerivatives; #ifdef TIME_KEEPING - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif partialDerivatives = ham.DU(xs); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); DU_duration += end - start; #endif xs = xs + partialDerivatives * (eta / 2); @@ -119,12 +119,12 @@ struct ImplicitMidpointODESolver { pts xs_old = xs; pts xmid = (xs_prev + xs) / 2.0; #ifdef TIME_KEEPING - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif partialDerivatives = ham.approxDK(xmid, nu); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); approxDK_duration += end - start; #endif xs = xs_prev + partialDerivatives * (eta); @@ -144,11 +144,11 @@ struct ImplicitMidpointODESolver { } } #ifdef TIME_KEEPING - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif partialDerivatives = ham.DU(xs); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); DU_duration += end - start; #endif xs = xs + partialDerivatives * (eta / 2); diff --git a/include/preprocess/crhmc/crhmc_problem.h b/include/preprocess/crhmc/crhmc_problem.h index c501bce62..641b5c615 100644 --- a/include/preprocess/crhmc/crhmc_problem.h +++ b/include/preprocess/crhmc/crhmc_problem.h @@ -330,23 +330,23 @@ class crhmc_problem { void simplify() { #ifdef TIME_KEEPING std::chrono::time_point start, end; - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif rescale(); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); rescale_duration += end - start; - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif splitDenseCols(options.maxNZ); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); sparsify_duration += end - start; - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif reorder(); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); reordering_duration += end - start; #endif int changed = 1; @@ -354,32 +354,32 @@ class crhmc_problem { while (changed) { changed = 0; #ifdef TIME_KEEPING - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif changed += remove_dependent_rows(); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); rm_rows_duration += end - start; - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif changed += remove_fixed_variables(); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); rm_fixed_vars_duration += end - start; - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif reorder(); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); reordering_duration += end - start; #endif } #ifdef TIME_KEEPING - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif changed += extract_collapsed_variables(); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); ex_collapsed_vars_duration += end - start; #endif } @@ -546,7 +546,7 @@ class crhmc_problem { simplify(); #ifdef TIME_KEEPING std::chrono::time_point start, end; - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif if (isempty_center) { std::tie(center, std::ignore, std::ignore) = @@ -555,7 +555,7 @@ class crhmc_problem { } shift_barrier(center); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); shift_barrier_duration += end - start; #endif reorder(); @@ -564,7 +564,7 @@ class crhmc_problem { // Recenter again and make sure it is feasible VT hess; #ifdef TIME_KEEPING - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif std::tie(center, std::ignore, std::ignore, w_center) = lewis_center(Asp, b, *this, options, center); @@ -578,7 +578,7 @@ class crhmc_problem { solver.solve((Tx *)input.data(), (Tx *)out.data()); center = center + (Asp.transpose() * out).cwiseProduct(Hinv); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); lewis_center_duration += end - start; #endif if ((center.array() > barrier.ub.array()).any() || diff --git a/include/random_walks/crhmc/crhmc_walk.hpp b/include/random_walks/crhmc/crhmc_walk.hpp index 21ed8d6bb..f40fe5979 100644 --- a/include/random_walks/crhmc/crhmc_walk.hpp +++ b/include/random_walks/crhmc/crhmc_walk.hpp @@ -179,7 +179,7 @@ struct CRHMCWalk { v_tilde = solver->get_state(1); if (metropolis_filter) { #ifdef TIME_KEEPING - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); #endif // Calculate initial Hamiltonian H = solver->ham.hamiltonian(x, v); @@ -188,7 +188,7 @@ struct CRHMCWalk { H_tilde = solver->ham.hamiltonian(x_tilde, -v_tilde); #ifdef TIME_KEEPING - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); H_duration += end - start; #endif VT feasible = solver->ham.feasible(x_tilde, diff --git a/test/benchmarks_crhmc.cpp b/test/benchmarks_crhmc.cpp index 3088cb656..2354a4964 100644 --- a/test/benchmarks_crhmc.cpp +++ b/test/benchmarks_crhmc.cpp @@ -51,9 +51,9 @@ double benchmark(std::string fileName) { std::chrono::time_point start, end; std::cout << "CRHMC polytope preparation for " << fileName << std::endl; - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); CrhmcProblem P = CrhmcProblem(input); - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); std::cout << "Preparation completed in time, "; std::chrono::duration elapsed_seconds = end - start; @@ -80,9 +80,9 @@ int main() { std::cout << "CRHMC polytope preparation 100000 dimensional Cube " << std::endl; - start = std::chrono::system_clock::now(); + start = std::chrono::high_resolution_clock::now(); CrhmcProblem P = CrhmcProblem(input); - end = std::chrono::system_clock::now(); + end = std::chrono::high_resolution_clock::now(); std::cout << "Preparation completed in time, "; std::chrono::duration elapsed_seconds = end - start;