Skip to content

Commit 415b81f

Browse files
committed
set convergence conditions
1 parent 9fa393b commit 415b81f

File tree

6 files changed

+40
-25
lines changed

6 files changed

+40
-25
lines changed

resolve/LinSolverIterative.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ namespace ReSolve
5757
return maxit_;
5858
}
5959

60+
int LinSolverIterative::setConvergenceCondition(index_type conv_cond)
61+
{
62+
if (conv_cond < 0 || conv_cond > 2)
63+
{
64+
out::error() << "Convergence condition must be 0, 1, or 2.\n";
65+
return 1;
66+
}
67+
this->conv_cond_ = conv_cond;
68+
return 0;
69+
}
70+
6071
int LinSolverIterative::setOrthogonalization(GramSchmidt* /* gs */)
6172
{
6273
out::error() << "Solver does not implement setting orthogonalization.\n";

resolve/LinSolverIterative.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ namespace ReSolve
3636
real_type getTol() const;
3737
index_type getMaxit() const;
3838

39+
int setConvergenceCondition(index_type conv_cond);
40+
3941
void setTol(real_type new_tol);
4042
void setMaxit(index_type new_maxit);
4143

4244
protected:
4345
real_type initial_residual_norm_;
4446
real_type final_residual_norm_;
4547
index_type total_iters_;
48+
index_type conv_cond_{0}; ///< Convergence condition (0: absolute, 1: relative to tol, 2: relative to rhs norm)
4649

4750
// Parameters common for all iterative solvers
4851
real_type tol_{1e-14}; ///< Solver tolerance

resolve/LinSolverIterativeFGMRES.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ namespace ReSolve
141141
initial_residual_norm_ = rnorm;
142142
while (outer_flag)
143143
{
144-
if (rnorm / bnorm <= ReSolve::constants::MACHINE_EPSILON) // addressed comment to check if residual is small enough
145-
{
146-
io::Logger::misc() << "Early exit, relative norm of residual "
147-
<< std::scientific << std::setprecision(16)
148-
<< rnorm / bnorm << "\n";
149-
outer_flag = 0;
150-
final_residual_norm_ = rnorm;
151-
initial_residual_norm_ = rnorm;
152-
total_iters_ = it;
153-
break;
154-
}
144+
// if (rnorm / bnorm <= ReSolve::constants::MACHINE_EPSILON) // addressed comment to check if residual is small enough
145+
// {
146+
// io::Logger::misc() << "Early exit, relative norm of residual "
147+
// << std::scientific << std::setprecision(16)
148+
// << rnorm / bnorm << "\n";
149+
// outer_flag = 0;
150+
// final_residual_norm_ = rnorm;
151+
// initial_residual_norm_ = rnorm;
152+
// total_iters_ = it;
153+
// break;
154+
// }
155155
if (it == 0)
156156
{
157157
tolrel = tol_ * rnorm;

resolve/LinSolverIterativeRandFGMRES.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,17 @@ namespace ReSolve
184184
initial_residual_norm_ = rnorm;
185185
while (outer_flag)
186186
{
187-
if (rnorm / bnorm <= ReSolve::constants::MACHINE_EPSILON) // addressed comment to check if residual is small enough
188-
{
189-
io::Logger::misc() << "Early exit, relative norm of residual "
190-
<< std::scientific << std::setprecision(16)
191-
<< rnorm / bnorm << "\n";
192-
outer_flag = 0;
193-
final_residual_norm_ = rnorm;
194-
initial_residual_norm_ = rnorm;
195-
total_iters_ = it;
196-
break;
197-
}
187+
// if (rnorm / bnorm <= ReSolve::constants::MACHINE_EPSILON) // addressed comment to check if residual is small enough
188+
// {
189+
// io::Logger::misc() << "Early exit, relative norm of residual "
190+
// << std::scientific << std::setprecision(16)
191+
// << rnorm / bnorm << "\n";
192+
// outer_flag = 0;
193+
// final_residual_norm_ = rnorm;
194+
// initial_residual_norm_ = rnorm;
195+
// total_iters_ = it;
196+
// break;
197+
// }
198198
if (it == 0)
199199
{
200200
tolrel = tol_ * rnorm;

tests/functionality/testKlu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ int runTest(int argc, char* argv[], std::string& solver_name)
152152

153153
status = FGMRES.setupPreconditioner("LU", &KLU);
154154
error_sum += status;
155-
155+
FGMRES.setConvergenceCondition(2); // set convergence condition to 2 to look at relative residual
156156
status = FGMRES.solve(&vec_rhs, &vec_x);
157157
error_sum += status;
158158
}
@@ -200,7 +200,7 @@ int runTest(int argc, char* argv[], std::string& solver_name)
200200
FGMRES.resetMatrix(A);
201201
status = FGMRES.setupPreconditioner("LU", &KLU);
202202
error_sum += status;
203-
203+
FGMRES.setConvergenceCondition(2); // set convergence condition to 2 to look at relative residual
204204
status = FGMRES.solve(&vec_rhs, &vec_x);
205205
error_sum += status;
206206
}

tests/functionality/testSysRefactor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,15 @@ static int runTest(int argc, char* argv[], std::string backend)
139139
// settings than HIP-based one)
140140
solver.setRefinementMethod("fgmres", "cgs2");
141141
solver.getIterativeSolver().setCliParam("restart", "100");
142+
solver.getIterativeSolver().setTol(ReSolve::constants::MACHINE_EPSILON);
143+
solver.getIterativeSolver().setConvergenceCondition(2); // relative residual norm
142144
if (backend == "hip")
143145
{
144146
solver.getIterativeSolver().setMaxit(200);
145147
}
146148
if (backend == "cuda")
147149
{
148150
solver.getIterativeSolver().setMaxit(400);
149-
solver.getIterativeSolver().setTol(1e-17);
150151
}
151152

152153
// Read first matrix

0 commit comments

Comments
 (0)