From 7671e3a3f3f4895a5724b5a1f468542444f57413 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Tue, 12 Mar 2024 22:20:08 -0400 Subject: [PATCH] Fix bug in GMRES solver on CPU. --- resolve/LinSolverIterativeFGMRES.cpp | 2 +- tests/functionality/CMakeLists.txt | 32 +++++++++++++++++------- tests/functionality/testSysRandGMRES.cpp | 20 +++++++++++---- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/resolve/LinSolverIterativeFGMRES.cpp b/resolve/LinSolverIterativeFGMRES.cpp index 8eb28af0..44cf8e8e 100644 --- a/resolve/LinSolverIterativeFGMRES.cpp +++ b/resolve/LinSolverIterativeFGMRES.cpp @@ -241,7 +241,7 @@ namespace ReSolve vector_handler_->axpy(&h_rs_[j], vec_z, x, memspace_); } } else { - mem_.setZeroArrayOnDevice(d_Z_->getData(memspace_), d_Z_->getSize()); + d_Z_->setToZero(memspace_); vec_z->setData( d_Z_->getVectorData(0, memspace_), memspace_); for(j = 0; j <= i; j++) { vec_v->setData( d_V_->getVectorData(j, memspace_), memspace_); diff --git a/tests/functionality/CMakeLists.txt b/tests/functionality/CMakeLists.txt index 8f336614..bf9f292f 100644 --- a/tests/functionality/CMakeLists.txt +++ b/tests/functionality/CMakeLists.txt @@ -115,20 +115,34 @@ if(RESOLVE_USE_KLU) add_test(NAME klu_klu_test COMMAND $ "${test_data_dir}") endif() -# Krylov solvers tests -add_test(NAME sys_rand_count_gmres_cgs2_test COMMAND $ "-i" "randgmres" "-g" "cgs2" "-s" "count") -add_test(NAME sys_rand_count_gmres_mgs_test COMMAND $ "-i" "randgmres" "-g" "mgs" "-s" "count") -add_test(NAME sys_rand_count_gmres_mgs2sync_test COMMAND $ "-i" "randgmres" "-g" "mgs_two_synch" "-s" "count") -add_test(NAME sys_rand_count_gmres_mgspm_test COMMAND $ "-i" "randgmres" "-g" "mgs_pm" "-s" "count") -add_test(NAME sys_rand_fwht_gmres_cgs2_test COMMAND $ "-i" "randgmres" "-g" "cgs2" "-s" "fwht") -add_test(NAME sys_rand_fwht_gmres_mgs_test COMMAND $ "-i" "randgmres" "-g" "mgs" "-s" "fwht") -add_test(NAME sys_rand_fwht_gmres_mgs2sync_test COMMAND $ "-i" "randgmres" "-g" "mgs_two_synch" "-s" "fwht") -add_test(NAME sys_rand_fwht_gmres_mgspm_test COMMAND $ "-i" "randgmres" "-g" "mgs_pm" "-s" "fwht") +# Krylov solvers tests (FGMRES) +add_test(NAME sys_rand_count_fgmres_cgs2_test COMMAND $ "-i" "randgmres" "-g" "cgs2" "-s" "count") +add_test(NAME sys_rand_count_fgmres_mgs_test COMMAND $ "-i" "randgmres" "-g" "mgs" "-s" "count") +add_test(NAME sys_rand_count_fgmres_mgs2sync_test COMMAND $ "-i" "randgmres" "-g" "mgs_two_synch" "-s" "count") +add_test(NAME sys_rand_count_fgmres_mgspm_test COMMAND $ "-i" "randgmres" "-g" "mgs_pm" "-s" "count") +add_test(NAME sys_rand_fwht_fgmres_cgs2_test COMMAND $ "-i" "randgmres" "-g" "cgs2" "-s" "fwht") +add_test(NAME sys_rand_fwht_fgmres_mgs_test COMMAND $ "-i" "randgmres" "-g" "mgs" "-s" "fwht") +add_test(NAME sys_rand_fwht_fgmres_mgs2sync_test COMMAND $ "-i" "randgmres" "-g" "mgs_two_synch" "-s" "fwht") +add_test(NAME sys_rand_fwht_fgmres_mgspm_test COMMAND $ "-i" "randgmres" "-g" "mgs_pm" "-s" "fwht") add_test(NAME sys_fgmres_cgs2_test COMMAND $ "-i" "fgmres" "-g" "cgs2") add_test(NAME sys_fgmres_mgs_test COMMAND $ "-i" "fgmres" "-g" "mgs") add_test(NAME sys_fgmres_mgs2sync_test COMMAND $ "-i" "fgmres" "-g" "mgs_two_synch") add_test(NAME sys_fgmres_mgspm_test COMMAND $ "-i" "fgmres" "-g" "mgs_pm") +# Krylov solvers tests (GMRES) +add_test(NAME sys_rand_count_gmres_cgs2_test COMMAND $ "-x" "no" "-i" "randgmres" "-g" "cgs2" "-s" "count") +add_test(NAME sys_rand_count_gmres_mgs_test COMMAND $ "-x" "no" "-i" "randgmres" "-g" "mgs" "-s" "count") +add_test(NAME sys_rand_count_gmres_mgs2sync_test COMMAND $ "-x" "no" "-i" "randgmres" "-g" "mgs_two_synch" "-s" "count") +add_test(NAME sys_rand_count_gmres_mgspm_test COMMAND $ "-x" "no" "-i" "randgmres" "-g" "mgs_pm" "-s" "count") +add_test(NAME sys_rand_fwht_gmres_cgs2_test COMMAND $ "-x" "no" "-i" "randgmres" "-g" "cgs2" "-s" "fwht") +add_test(NAME sys_rand_fwht_gmres_mgs_test COMMAND $ "-x" "no" "-i" "randgmres" "-g" "mgs" "-s" "fwht") +add_test(NAME sys_rand_fwht_gmres_mgs2sync_test COMMAND $ "-x" "no" "-i" "randgmres" "-g" "mgs_two_synch" "-s" "fwht") +add_test(NAME sys_rand_fwht_gmres_mgspm_test COMMAND $ "-x" "no" "-i" "randgmres" "-g" "mgs_pm" "-s" "fwht") +add_test(NAME sys_gmres_cgs2_test COMMAND $ "-x" "no" "-i" "fgmres" "-g" "cgs2") +add_test(NAME sys_gmres_mgs_test COMMAND $ "-x" "no" "-i" "fgmres" "-g" "mgs") +add_test(NAME sys_gmres_mgs2sync_test COMMAND $ "-x" "no" "-i" "fgmres" "-g" "mgs_two_synch") +add_test(NAME sys_gmres_mgspm_test COMMAND $ "-x" "no" "-i" "fgmres" "-g" "mgs_pm") + if(RESOLVE_USE_CUDA) if(RESOLVE_USE_KLU) add_test(NAME klu_rf_test COMMAND $ "${test_data_dir}") diff --git a/tests/functionality/testSysRandGMRES.cpp b/tests/functionality/testSysRandGMRES.cpp index 7627b756..6b864987 100644 --- a/tests/functionality/testSysRandGMRES.cpp +++ b/tests/functionality/testSysRandGMRES.cpp @@ -36,7 +36,7 @@ using vector_type = ReSolve::vector::Vector; template static int test(int argc, char *argv[]); static void processInputs(std::string& method, std::string& gs, std::string& sketch); -static std::string headerInfo(const std::string& method, const std::string& gs, const std::string& sketch); +static std::string headerInfo(const std::string& method, const std::string& gs, const std::string& sketch, bool flexible); static ReSolve::matrix::Csr* generateMatrix(const index_type N, ReSolve::memory::MemorySpace memspace); static ReSolve::vector::Vector* generateRhs(const index_type N, ReSolve::memory::MemorySpace memspace); @@ -81,6 +81,12 @@ int test(int argc, char *argv[]) opt = options.getParamFromKey("-s"); std::string sketch = opt ? (*opt).second : "count"; + opt = options.getParamFromKey("-x"); + bool flexible = true; + if(opt) { + flexible = !((*opt).second == "no"); + } + processInputs(method, gs, sketch); // Create workspace and initialize its handles. @@ -130,6 +136,7 @@ int test(int argc, char *argv[]) solver.getIterativeSolver().setRestart(200); solver.getIterativeSolver().setMaxit(2500); solver.getIterativeSolver().setTol(tol); + solver.getIterativeSolver().setFlexible(flexible); matrix_handler.setValuesChanged(true, memspace); @@ -150,7 +157,7 @@ int test(int argc, char *argv[]) norm_b = std::sqrt(norm_b); real_type final_norm = solver.getIterativeSolver().getFinalResidualNorm(); std::cout << std::defaultfloat - << headerInfo(method, gs, sketch) + << headerInfo(method, gs, sketch, flexible) << "\t Hardware backend: " << hwbackend << "\n" << "\t Solver tolerance: " << tol << "\n" << std::scientific << std::setprecision(16) @@ -204,11 +211,13 @@ void processInputs(std::string& method, std::string& gs, std::string& sketch) } } -std::string headerInfo(const std::string& method, const std::string& gs, const std::string& sketch) +std::string headerInfo(const std::string& method, const std::string& gs, const std::string& sketch, bool flexible) { std::string header("Results for "); if (method == "randgmres") { - header += "randomized FGMRES solver\n"; + header += "randomized "; + header += flexible ? "FGMRES" : "GMRES"; + header += " solver\n"; header += "\t Sketching method: "; if (sketch == "count") { header += "count sketching\n"; @@ -216,7 +225,8 @@ std::string headerInfo(const std::string& method, const std::string& gs, const s header += "fast Walsh-Hadamard transform\n"; } } else if (method == "fgmres") { - header += "FGMRES solver\n"; + header += flexible ? "FGMRES" : "GMRES"; + header += " solver\n"; } else { return header + "unknown method\n"; }