Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion examples/sysGmres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>

#include "ExampleHelper.hpp"
#include <resolve/Preconditioner.hpp>
#include <resolve/SystemSolver.hpp>
#include <resolve/matrix/Csr.hpp>
#include <resolve/matrix/io.hpp>
Expand Down Expand Up @@ -171,6 +172,11 @@ int sysGmres(int argc, char* argv[])

processInputs(method, gs, sketch, flexible, side);

// processInputs guarantees `side` is "left" or "right".
ReSolve::Preconditioner::Side prec_side =
(side == "left") ? ReSolve::Preconditioner::Side::LEFT
: ReSolve::Preconditioner::Side::RIGHT;

std::cout << "Matrix file: " << matrix_pathname << "\n"
<< "RHS file: " << rhs_pathname << "\n";

Expand Down Expand Up @@ -255,7 +261,7 @@ int sysGmres(int argc, char* argv[])
// Set up the preconditioner
if (return_code == 0)
{
status = solver.preconditionerSetup(side);
status = solver.preconditionerSetup(prec_side);
std::cout << "solver.preconditionerSetup returned status: " << status << "\n";
if (status != 0)
{
Expand Down
23 changes: 5 additions & 18 deletions resolve/SystemSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,12 @@ namespace ReSolve
*
* Initializes and attaches the preconditioner to the iterative solver.
*
* @param[in] side - preconditioning side (Preconditioner::Side::LEFT or
* Preconditioner::Side::RIGHT)
*
* @return int 0 if successful, 1 if it fails
*/
int SystemSolver::preconditionerSetup(std::string side)
int SystemSolver::preconditionerSetup(Preconditioner::Side side)
{
int status = 0;

Expand All @@ -642,23 +645,7 @@ namespace ReSolve
return status;
}

Preconditioner::Side prec_side;
if (side == "left")
{
prec_side = Preconditioner::LEFT;
}
else if (side == "right")
{
prec_side = Preconditioner::RIGHT;
}
else
{
out::error() << "Preconditioning side '" << side
<< "' not recognized. Use 'left' or 'right'.\n";
return 1;
}

status += preconditioner_->setSide(prec_side);
status += preconditioner_->setSide(side);
status += preconditioner_->setup(A_);

if (memspace_ != "cpu")
Expand Down
2 changes: 1 addition & 1 deletion resolve/SystemSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace ReSolve
int factorize(); // numeric part
int refactorize();
int refactorizationSetup();
int preconditionerSetup(std::string side);
int preconditionerSetup(Preconditioner::Side side);
int resetPreconditioner(matrix_type* A);
int solve(vector_type* rhs, vector_type* x); // for direct and iterative
int refine(vector_type* rhs, vector_type* x); // for iterative refinement
Expand Down
11 changes: 8 additions & 3 deletions tests/functionality/testSysGmres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ int test(int argc, char* argv[])

processInputs(method, gs, sketch, side);

// processInputs guarantees `side` is "left" or "right".
ReSolve::Preconditioner::Side prec_side =
(side == "left") ? ReSolve::Preconditioner::Side::LEFT
: ReSolve::Preconditioner::Side::RIGHT;

// Create workspace and initialize its handles.
workspace_type workspace;
workspace.initializeHandles();
Expand Down Expand Up @@ -170,7 +175,7 @@ int test(int argc, char* argv[])
solver.getIterativeSolver().setCliParam("restart", "200");

// Set preconditioner (default in this case ILU0)
status = solver.preconditionerSetup(side);
status = solver.preconditionerSetup(prec_side);
error_sum += status;

// Solve system
Expand Down Expand Up @@ -207,7 +212,7 @@ int test(int argc, char* argv[])
bad_guess_solver.getIterativeSolver().setCliParam("flexible", flexible);
bad_guess_solver.getIterativeSolver().setCliParam("restart", "200");

status = bad_guess_solver.preconditionerSetup(side);
status = bad_guess_solver.preconditionerSetup(prec_side);
error_sum += status;

const real_type bad_guess_rnorm = bad_guess_solver.getResidualNorm(vec_rhs, &bad_guess_x);
Expand Down Expand Up @@ -265,7 +270,7 @@ int test(int argc, char* argv[])
accepted_guess_solver.getIterativeSolver().setCliParam("flexible", flexible);
accepted_guess_solver.getIterativeSolver().setCliParam("restart", "200");

status = accepted_guess_solver.preconditionerSetup(side);
status = accepted_guess_solver.preconditionerSetup(prec_side);
error_sum += status;

const real_type initial_guess_rnorm = accepted_guess_solver.getResidualNorm(vec_rhs, &vec_x_guess);
Expand Down