1 #ifndef PARGEMSLR_SOLVER_H
2 #define PARGEMSLR_SOLVER_H
9 #include "../utils/utils.hpp"
10 #include "../vectors/vector.hpp"
11 #include "../vectors/sequential_vector.hpp"
12 #include "../vectors/parallel_vector.hpp"
13 #include "../matrices/matrix.hpp"
14 #include "../matrices/csr_matrix.hpp"
15 #include "../matrices/dense_matrix.hpp"
16 #include "../matrices/parallel_csr_matrix.hpp"
27 kSolverUndefined = -1,
45 template <
class MatrixType,
class VectorType,
typename DataType>
126 snprintf( str1, 1024,
"Change setup %s after preconditioner is built is invalid.", str );
127 PARGEMSLR_ERROR(str1);
128 return PARGEMSLR_ERROR_FUNCTION_CALL_ERR;
130 return PARGEMSLR_SUCCESS;
141 this->_solver_precision = kUnknownPrecision;
142 this->_solver_type = kSolverUndefined;
145 this->_matrix = NULL;
146 this->_own_matrix =
false;
147 this->_preconditioner = NULL;
148 this->_own_preconditioner =
false;
149 this->_solution = NULL;
150 this->_right_hand_side = NULL;
151 this->_ready =
false;
152 this->_print_option = 0;
165 this->_matrix = solver.
_matrix;
166 this->_own_matrix =
false;
168 this->_own_preconditioner =
false;
170 this->_ready = solver.
_ready;
181 this->_solver_precision = solver._solver_precision;
182 solver._solver_precision = kUnknownPrecision;
183 this->_solver_type = solver._solver_type;
184 solver._solver_type = kSolverUndefined;
185 this->_is_mixed = solver._is_mixed;
186 this->_matrix = solver._matrix;
187 solver._matrix = NULL;
188 this->_own_matrix = solver._own_matrix;
189 solver._own_matrix =
false;
191 solver._preconditioner = NULL;
192 this->_own_preconditioner = solver._own_preconditioner;
193 solver._own_preconditioner =
false;
194 this->_solution = solver._solution;
195 solver._solution = NULL;
196 this->_right_hand_side = solver._right_hand_side;
197 solver._right_hand_side = NULL;
198 this->_ready = solver._ready;
199 solver._ready =
false;
200 this->_print_option = solver._print_option;
201 solver._print_option = 0;
216 this->_own_matrix =
false;
218 this->_own_preconditioner =
false;
221 this->_ready = solver.
_ready;
235 this->_solver_precision = solver._solver_precision;
236 solver._solver_precision = kUnknownPrecision;
237 this->_solver_type = solver._solver_type;
238 solver._solver_type = kSolverUndefined;
239 this->_is_mixed = solver._is_mixed;
240 this->_matrix = solver._matrix;
241 solver._matrix = NULL;
242 this->_own_matrix = solver._own_matrix;
243 solver._own_matrix =
false;
245 solver._preconditioner = NULL;
246 this->_own_preconditioner = solver._own_preconditioner;
247 solver._own_preconditioner =
false;
248 this->_solution = solver._solution;
249 solver._solution = NULL;
250 this->_right_hand_side = solver._right_hand_side;
251 solver._right_hand_side = NULL;
252 this->_ready = solver._ready;
253 solver._ready =
false;
254 this->_print_option = solver._print_option;
255 solver._print_option = 0;
267 this->_solver_precision = kUnknownPrecision;
268 this->_solver_type = kSolverUndefined;
270 if(this->_matrix && this->_own_matrix)
272 this->_matrix->Clear();
275 this->_matrix = NULL;
277 if(this->_preconditioner && this->_own_preconditioner)
279 this->_preconditioner->
Clear();
282 this->_preconditioner = NULL;
283 this->_solution = NULL;
284 this->_right_hand_side = NULL;
286 this->_own_matrix =
false;
287 this->_own_preconditioner =
false;
288 this->_ready =
false;
289 this->_print_option = 0;
291 return PARGEMSLR_SUCCESS;
311 virtual int Setup( VectorType &x, VectorType &rhs) = 0;
320 virtual int Solve( VectorType &x, VectorType &rhs) = 0;
331 PARGEMSLR_ERROR(
"Error: Solve with multiple right-hand-side unimplemented for this class");
332 return PARGEMSLR_ERROR_FUNCTION_CALL_ERR;
342 PARGEMSLR_ERROR(
"Error: GetNumNonzeros unimplemented for this class");
343 return PARGEMSLR_ERROR_FUNCTION_CALL_ERR;
374 PARGEMSLR_ERROR(
"Error: SetWithParameterArray unimplemented for this class");
375 return PARGEMSLR_ERROR_FUNCTION_CALL_ERR;
405 if(matrix == this->_matrix)
408 return PARGEMSLR_SUCCESS;
411 if(this->_matrix && this->_own_matrix)
413 this->_matrix->Clear();
418 this->_matrix = matrix;
420 if(this->_preconditioner && this->_own_preconditioner)
422 this->_preconditioner->
Clear();
427 this->_preconditioner = NULL;
428 this->_solution = NULL;
429 this->_right_hand_side = NULL;
431 this->_ready =
false;
433 this->_own_matrix =
false;
434 this->_own_preconditioner =
false;
436 return PARGEMSLR_SUCCESS;
458 if(this->_preconditioner && this->_own_preconditioner)
460 this->_preconditioner->
Clear();
463 this->_preconditioner = precond;
464 this->_own_preconditioner =
false;
465 return PARGEMSLR_SUCCESS;
486 this->_own_matrix = own_matrix;
487 return PARGEMSLR_SUCCESS;
498 this->_own_preconditioner = own_preconditioner;
499 return PARGEMSLR_SUCCESS;
510 this->_print_option = print_option;
511 return PARGEMSLR_SUCCESS;
536 typedef SolverClass<CsrMatrixClass<float>, SequentialVectorClass<float>,
float> solver_csr_seq_float;
537 typedef SolverClass<CsrMatrixClass<double>, SequentialVectorClass<double>,
float> solver_csr_seq_mix;
538 typedef SolverClass<CsrMatrixClass<double>, SequentialVectorClass<double>,
double> solver_csr_seq_double;
539 typedef SolverClass<CsrMatrixClass<complexs>, SequentialVectorClass<complexs>, complexs> solver_csr_seq_complexs;
540 typedef SolverClass<CsrMatrixClass<complexd>, SequentialVectorClass<complexd>, complexs> solver_csr_seq_complexmix;
541 typedef SolverClass<CsrMatrixClass<complexd>, SequentialVectorClass<complexd>, complexd> solver_csr_seq_complexd;
543 typedef SolverClass<ParallelCsrMatrixClass<float>, ParallelVectorClass<float>,
float> solver_csr_par_float;
544 typedef SolverClass<ParallelCsrMatrixClass<double>, ParallelVectorClass<double>,
double> solver_csr_par_double;
545 typedef SolverClass<ParallelCsrMatrixClass<double>, ParallelVectorClass<double>,
double> solver_csr_par_double;
546 typedef SolverClass<ParallelCsrMatrixClass<complexs>, ParallelVectorClass<complexs>, complexs> solver_csr_par_complexs;
547 typedef SolverClass<ParallelCsrMatrixClass<complexd>, ParallelVectorClass<complexd>, complexs> solver_csr_par_complexmix;
548 typedef SolverClass<ParallelCsrMatrixClass<complexd>, ParallelVectorClass<complexd>, complexd> solver_csr_par_complexd;