Skip to content

Commit

Permalink
Fix bug in GMRES solver on CPU.
Browse files Browse the repository at this point in the history
  • Loading branch information
pelesh committed Mar 13, 2024
1 parent b8ec029 commit 7671e3a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion resolve/LinSolverIterativeFGMRES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
32 changes: 23 additions & 9 deletions tests/functionality/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,34 @@ if(RESOLVE_USE_KLU)
add_test(NAME klu_klu_test COMMAND $<TARGET_FILE:klu_klu_test.exe> "${test_data_dir}")
endif()

# Krylov solvers tests
add_test(NAME sys_rand_count_gmres_cgs2_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "cgs2" "-s" "count")
add_test(NAME sys_rand_count_gmres_mgs_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs" "-s" "count")
add_test(NAME sys_rand_count_gmres_mgs2sync_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs_two_synch" "-s" "count")
add_test(NAME sys_rand_count_gmres_mgspm_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs_pm" "-s" "count")
add_test(NAME sys_rand_fwht_gmres_cgs2_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "cgs2" "-s" "fwht")
add_test(NAME sys_rand_fwht_gmres_mgs_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs" "-s" "fwht")
add_test(NAME sys_rand_fwht_gmres_mgs2sync_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs_two_synch" "-s" "fwht")
add_test(NAME sys_rand_fwht_gmres_mgspm_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs_pm" "-s" "fwht")
# Krylov solvers tests (FGMRES)
add_test(NAME sys_rand_count_fgmres_cgs2_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "cgs2" "-s" "count")
add_test(NAME sys_rand_count_fgmres_mgs_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs" "-s" "count")
add_test(NAME sys_rand_count_fgmres_mgs2sync_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs_two_synch" "-s" "count")
add_test(NAME sys_rand_count_fgmres_mgspm_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs_pm" "-s" "count")
add_test(NAME sys_rand_fwht_fgmres_cgs2_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "cgs2" "-s" "fwht")
add_test(NAME sys_rand_fwht_fgmres_mgs_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs" "-s" "fwht")
add_test(NAME sys_rand_fwht_fgmres_mgs2sync_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs_two_synch" "-s" "fwht")
add_test(NAME sys_rand_fwht_fgmres_mgspm_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "randgmres" "-g" "mgs_pm" "-s" "fwht")
add_test(NAME sys_fgmres_cgs2_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "fgmres" "-g" "cgs2")
add_test(NAME sys_fgmres_mgs_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "fgmres" "-g" "mgs")
add_test(NAME sys_fgmres_mgs2sync_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "fgmres" "-g" "mgs_two_synch")
add_test(NAME sys_fgmres_mgspm_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-i" "fgmres" "-g" "mgs_pm")

# Krylov solvers tests (GMRES)
add_test(NAME sys_rand_count_gmres_cgs2_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "randgmres" "-g" "cgs2" "-s" "count")
add_test(NAME sys_rand_count_gmres_mgs_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "randgmres" "-g" "mgs" "-s" "count")
add_test(NAME sys_rand_count_gmres_mgs2sync_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "randgmres" "-g" "mgs_two_synch" "-s" "count")
add_test(NAME sys_rand_count_gmres_mgspm_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "randgmres" "-g" "mgs_pm" "-s" "count")
add_test(NAME sys_rand_fwht_gmres_cgs2_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "randgmres" "-g" "cgs2" "-s" "fwht")
add_test(NAME sys_rand_fwht_gmres_mgs_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "randgmres" "-g" "mgs" "-s" "fwht")
add_test(NAME sys_rand_fwht_gmres_mgs2sync_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "randgmres" "-g" "mgs_two_synch" "-s" "fwht")
add_test(NAME sys_rand_fwht_gmres_mgspm_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "randgmres" "-g" "mgs_pm" "-s" "fwht")
add_test(NAME sys_gmres_cgs2_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "fgmres" "-g" "cgs2")
add_test(NAME sys_gmres_mgs_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "fgmres" "-g" "mgs")
add_test(NAME sys_gmres_mgs2sync_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "fgmres" "-g" "mgs_two_synch")
add_test(NAME sys_gmres_mgspm_test COMMAND $<TARGET_FILE:sys_rand_gmres_test.exe> "-x" "no" "-i" "fgmres" "-g" "mgs_pm")

if(RESOLVE_USE_CUDA)
if(RESOLVE_USE_KLU)
add_test(NAME klu_rf_test COMMAND $<TARGET_FILE:klu_rf_test.exe> "${test_data_dir}")
Expand Down
20 changes: 15 additions & 5 deletions tests/functionality/testSysRandGMRES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using vector_type = ReSolve::vector::Vector;
template <class T>
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);

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -204,19 +211,22 @@ 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";
} else if (sketch == "fwht") {
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";
}
Expand Down

0 comments on commit 7671e3a

Please sign in to comment.