Skip to content

Commit 571d13b

Browse files
authored
Parameter management utilities (#163)
* Separate files for iterative and direct linear solvers base classes. * Implement set/get CLI parameters methods. * Fixed parameter management bugs in RandFGMRES and FGMRES classes. * Add unit test for setting/getting solver params. * Check if parameters exist before setting/getting them. * Move GMRES specific methods out of iterative solver base class. * Remove dead code from LinSolver class.
1 parent 4a5fab4 commit 571d13b

27 files changed

+964
-327
lines changed

resolve/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ add_subdirectory(utilities)
1111
# C++ files
1212
set(ReSolve_SRC
1313
LinSolver.cpp
14+
LinSolverDirect.cpp
15+
LinSolverIterative.cpp
1416
GramSchmidt.cpp
1517
LinSolverIterativeFGMRES.cpp
1618
LinSolverDirectCpuILU0.cpp
@@ -36,23 +38,25 @@ set(ReSolve_CUDASDK_SRC
3638

3739
# C++ code that links to ROCm libraries
3840
set(ReSolve_ROCM_SRC
39-
LinSolverDirectRocSolverRf.cpp
40-
LinSolverDirectRocSparseILU0.cpp
41+
LinSolverDirectRocSolverRf.cpp
42+
LinSolverDirectRocSparseILU0.cpp
4143
)
4244

4345
# Header files to be installed
4446
set(ReSolve_HEADER_INSTALL
4547
Common.hpp
4648
cusolver_defs.hpp
4749
LinSolver.hpp
50+
LinSolverDirect.hpp
51+
LinSolverIterative.hpp
4852
LinSolverIterativeFGMRES.hpp
4953
LinSolverDirectCpuILU0.hpp
5054
SystemSolver.hpp
5155
GramSchmidt.hpp
5256
MemoryUtils.hpp)
5357

5458
set(ReSolve_KLU_HEADER_INSTALL
55-
LinSolverDirectKLU.hpp
59+
LinSolverDirectKLU.hpp
5660
)
5761

5862
set(ReSolve_LUSOL_HEADER_INSTALL

resolve/Common.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ namespace ReSolve {
1313
constexpr double EPSMAC = 1.0e-16;
1414

1515

16-
// TODO: let cmake manage these. combined with the todo above relating to cstdint
17-
// this is related to resolve/lusol/lusol_precision.f90. whatever is here should
18-
// have an equivalent there
19-
20-
// NOTE: i'd love to make this std::float64_t but we're not on c++23
16+
/// @todo Provide CMake option to se these types at config time
2117
using real_type = double;
2218
using index_type = std::int32_t;
2319

resolve/LinSolver.cpp

Lines changed: 14 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* @file LinSolverIterative.cpp
3+
* @author Kasia Swirydowicz (kasia.swirydowicz@pnnl.gov)
4+
* @author Slaven Peles (peless@ornl.gov)
5+
* @brief Implementation of linear solver base class.
6+
*
7+
*/
8+
19
#include <resolve/matrix/Sparse.hpp>
210
#include <resolve/utilities/logger/Logger.hpp>
311

@@ -23,173 +31,14 @@ namespace ReSolve
2331
return 1.0;
2432
}
2533

26-
//
27-
// Direct solver methods implementations
28-
//
29-
30-
LinSolverDirect::LinSolverDirect()
31-
{
32-
L_ = nullptr;
33-
U_ = nullptr;
34-
P_ = nullptr;
35-
Q_ = nullptr;
36-
}
37-
38-
LinSolverDirect::~LinSolverDirect()
34+
int LinSolver::getParamId(std::string id) const
3935
{
40-
}
41-
42-
int LinSolverDirect::setup(matrix::Sparse* A,
43-
matrix::Sparse* /* L */,
44-
matrix::Sparse* /* U */,
45-
index_type* /* P */,
46-
index_type* /* Q */,
47-
vector_type* /* rhs */)
48-
{
49-
if (A == nullptr) {
50-
return 1;
36+
auto it = params_list_.find(id);
37+
if (it == params_list_.end()) {
38+
out::error() << "Unknown parameter " << id << ".\n";
39+
return 999;
5140
}
52-
this->A_ = A;
53-
return 0;
54-
}
55-
56-
int LinSolverDirect::analyze()
57-
{
58-
return 1;
59-
} //the same as symbolic factorization
60-
61-
int LinSolverDirect::factorize()
62-
{
63-
return 1;
64-
}
65-
66-
int LinSolverDirect::refactorize()
67-
{
68-
return 1;
69-
}
70-
71-
matrix::Sparse* LinSolverDirect::getLFactor()
72-
{
73-
return nullptr;
74-
}
75-
76-
matrix::Sparse* LinSolverDirect::getUFactor()
77-
{
78-
return nullptr;
79-
}
80-
81-
index_type* LinSolverDirect::getPOrdering()
82-
{
83-
return nullptr;
84-
}
85-
86-
index_type* LinSolverDirect::getQOrdering()
87-
{
88-
return nullptr;
89-
}
90-
91-
void LinSolverDirect::setPivotThreshold(real_type tol)
92-
{
93-
pivot_threshold_tol_ = tol;
94-
}
95-
96-
void LinSolverDirect::setOrdering(int ordering)
97-
{
98-
ordering_ = ordering;
99-
}
100-
101-
void LinSolverDirect::setHaltIfSingular(bool is_halt)
102-
{
103-
halt_if_singular_ = is_halt;
104-
}
105-
106-
real_type LinSolverDirect::getMatrixConditionNumber()
107-
{
108-
out::error() << "Solver does not implement returning system matrix condition number.\n";
109-
return -1.0;
110-
}
111-
112-
//
113-
// Iterative solver methods implementations
114-
//
115-
116-
LinSolverIterative::LinSolverIterative()
117-
{
118-
}
119-
120-
LinSolverIterative::~LinSolverIterative()
121-
{
122-
}
123-
124-
int LinSolverIterative::setup(matrix::Sparse* A)
125-
{
126-
if (A == nullptr) {
127-
return 1;
128-
}
129-
this->A_ = A;
130-
return 0;
131-
}
132-
133-
real_type LinSolverIterative::getFinalResidualNorm() const
134-
{
135-
return final_residual_norm_;
136-
}
137-
138-
real_type LinSolverIterative::getInitResidualNorm() const
139-
{
140-
return initial_residual_norm_;
141-
}
142-
143-
index_type LinSolverIterative::getNumIter() const
144-
{
145-
return total_iters_;
146-
}
147-
148-
149-
real_type LinSolverIterative::getTol()
150-
{
151-
return tol_;
152-
}
153-
154-
index_type LinSolverIterative::getMaxit()
155-
{
156-
return maxit_;
157-
}
158-
159-
index_type LinSolverIterative::getRestart()
160-
{
161-
return restart_;
162-
}
163-
164-
index_type LinSolverIterative::getConvCond()
165-
{
166-
return conv_cond_;
167-
}
168-
169-
bool LinSolverIterative::getFlexible()
170-
{
171-
return flexible_;
172-
}
173-
174-
int LinSolverIterative::setOrthogonalization(GramSchmidt* /* gs */)
175-
{
176-
out::error() << "Solver does not implement setting orthogonalization.\n";
177-
return 1;
178-
}
179-
180-
void LinSolverIterative::setTol(real_type new_tol)
181-
{
182-
this->tol_ = new_tol;
183-
}
184-
185-
void LinSolverIterative::setMaxit(index_type new_maxit)
186-
{
187-
this->maxit_ = new_maxit;
188-
}
189-
190-
void LinSolverIterative::setConvCond(index_type new_conv_cond)
191-
{
192-
this->conv_cond_ = new_conv_cond;
41+
return (*it).second;
19342
}
19443
}
19544

0 commit comments

Comments
 (0)