Loading...
Searching...
No Matches
SparseSolverBase.hpp
Go to the documentation of this file.
1/*
2 * STRUMPACK -- STRUctured Matrices PACKage, Copyright (c) 2014, The
3 * Regents of the University of California, through Lawrence Berkeley
4 * National Laboratory (subject to receipt of any required approvals
5 * from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * If you have questions about your rights to use or distribute this
8 * software, please contact Berkeley Lab's Technology Transfer
9 * Department at TTD@lbl.gov.
10 *
11 * NOTICE. This software is owned by the U.S. Department of Energy. As
12 * such, the U.S. Government has been granted for itself and others
13 * acting on its behalf a paid-up, nonexclusive, irrevocable,
14 * worldwide license in the Software to reproduce, prepare derivative
15 * works, and perform publicly and display publicly. Beginning five
16 * (5) years after the date permission to assert copyright is obtained
17 * from the U.S. Department of Energy, and subject to any subsequent
18 * five (5) year renewals, the U.S. Government is granted for itself
19 * and others acting on its behalf a paid-up, nonexclusive,
20 * irrevocable, worldwide license in the Software to reproduce,
21 * prepare derivative works, distribute copies to the public, perform
22 * publicly and display publicly, and to permit others to do so.
23 *
24 * Developers: Pieter Ghysels, Francois-Henry Rouet, Xiaoye S. Li.
25 * (Lawrence Berkeley National Lab, Computational Research
26 * Division).
27 */
33#ifndef STRUMPACK_SPARSE_SOLVER_BASE_HPP
34#define STRUMPACK_SPARSE_SOLVER_BASE_HPP
35
36#include <new>
37#include <memory>
38#include <vector>
39#include <string>
40
41#include "StrumpackConfig.hpp"
42#include "StrumpackOptions.hpp"
43#include "sparse/CSRMatrix.hpp"
44#include "dense/DenseMatrix.hpp"
45
49namespace strumpack {
50
51 // forward declarations
52 template<typename scalar_t,typename integer_t> class MatrixReordering;
53 template<typename scalar_t,typename integer_t> class EliminationTree;
54 class TaskTimer;
55
77 template<typename scalar_t,typename integer_t=int>
79
85
86 public:
87
100 SparseSolverBase(int argc, char* argv[],
101 bool verbose=true, bool root=true);
102
111 SparseSolverBase(bool verbose=true, bool root=true);
112
117
156 ReturnCode reorder(int nx=1, int ny=1, int nz=1,
157 int components=1, int width=1);
158
168 ReturnCode reorder(const int* p, int base=0);
169
184
195
218 ReturnCode solve(const scalar_t* b, scalar_t* x,
219 bool use_initial_guess=false);
220
247 bool use_initial_guess=false);
248
277 ReturnCode solve(int nrhs, const scalar_t* b, int ldb,
278 scalar_t* x, int ldx,
279 bool use_initial_guess=false);
280
285
290
298
307 void set_from_options(int argc, char* argv[]);
308
316 int maximum_rank() const;
317
325 std::size_t factor_nonzeros() const;
326
336 std::size_t factor_memory() const;
337
342 int Krylov_iterations() const;
343
344
368 ReturnCode inertia(integer_t& neg, integer_t& zero, integer_t& pos);
369
370 ReturnCode subnormals(std::size_t& ns, std::size_t& nz);
371
372 ReturnCode pivot_growth(scalar_t& pg);
373
382 void draw(const std::string& name) const;
383
391
392 protected:
393 virtual void setup_tree() = 0;
394 virtual void setup_reordering() = 0;
395 virtual
396 int compute_reordering(const int* p, int base,
397 int nx, int ny, int nz,
398 int components, int width) = 0;
399 virtual void separator_reordering() = 0;
400
401 virtual SpMat_t* matrix() = 0;
402 virtual Reord_t* reordering() = 0;
403 virtual Tree_t* tree() = 0;
404 virtual const SpMat_t* matrix() const = 0;
405 virtual const Reord_t* reordering() const = 0;
406 virtual const Tree_t* tree() const = 0;
407
408 virtual void perf_counters_start();
409 virtual void perf_counters_stop(const std::string& s);
410
411 virtual void synchronize() {}
412 virtual void communicate_ordering() {}
413 virtual double max_peak_memory() const
414 { return double(params::peak_memory); }
415 virtual double min_peak_memory() const
416 { return double(params::peak_memory); }
417
418 void papi_initialize();
419 long long dense_factor_nonzeros() const;
420 void print_solve_stats(TaskTimer& t) const;
421
422 virtual void reduce_flop_counters() const {}
423 void print_flop_breakdown_HSS() const;
424 void print_flop_breakdown_HODLR() const;
425 void flop_breakdown_reset() const;
426
427 void print_wrong_sparsity_error();
428
429 // TODO do these all need to be virtual, can some be private?
430 virtual
431 ReturnCode solve_internal(const scalar_t* b, scalar_t* x,
432 bool use_initial_guess=false) = 0;
433 virtual
434 ReturnCode solve_internal(const DenseM_t& b, DenseM_t& x,
435 bool use_initial_guess=false) = 0;
436 virtual
437 ReturnCode solve_internal(int nrhs, const scalar_t* b, int ldb,
438 scalar_t* x, int ldx,
439 bool use_initial_guess=false);
440
441 SPOptions<scalar_t> opts_;
442 bool is_root_;
443
444 MatchingData<scalar_t,integer_t> matching_;
445 Equilibration<scalar_t> equil_;
446
447 std::new_handler old_handler_;
448 std::ostream* rank_out_ = nullptr;
449 bool factored_ = false;
450 bool reordered_ = false;
451 int Krylov_its_ = 0;
452
453#if defined(STRUMPACK_USE_PAPI)
454 float rtime_ = 0., ptime_ = 0.;
455 long_long _flpops = 0;
456#endif
457#if defined(STRUMPACK_COUNT_FLOPS)
458 long long int f0_ = 0, ftot_ = 0, fmin_ = 0, fmax_ = 0;
459 long long int b0_ = 0, btot_ = 0, bmin_ = 0, bmax_ = 0;
460 long long int m0_ = 0, mtot_ = 0, mmin_ = 0, mmax_ = 0;
461 long long int ptot_ = 0, pmin_ = 0, pmax_ = 0;
462 long long int dm0_ = 0, dmtot_ = 0, dmmin_ = 0, dmmax_ = 0;
463 long long int dptot_ = 0, dpmin_ = 0, dpmax_ = 0;
464#endif
465
466 private:
467 ReturnCode reorder_internal(const int* p, int base,
468 int nx, int ny, int nz,
469 int components, int width);
470
471 virtual void delete_factors_internal() = 0;
472 };
473
474 template<typename scalar_t,typename integer_t>
475 using StrumpackSparseSolverBase =
476 SparseSolverBase<scalar_t,integer_t>;
477
478} //end namespace strumpack
479
480#endif // STRUMPACK_SPARSE_SOLVER_BASE_HPP
Contains the compressed sparse row matrix storage class.
Contains the DenseMatrix and DenseMatrixWrapper classes, simple wrappers around BLAS/LAPACK style den...
Holds options for the sparse solver.
Abstract base class for compressed sparse matrix storage.
Definition CompressedSparseMatrix.hpp:149
Like DenseMatrix, this class represents a matrix, stored in column major format, to allow direct use ...
Definition DenseMatrix.hpp:1018
This class represents a matrix, stored in column major format, to allow direct use of BLAS/LAPACK rou...
Definition DenseMatrix.hpp:139
Definition SparseSolverBase.hpp:53
Definition SparseSolverBase.hpp:52
Options for the sparse solver.
Definition StrumpackOptions.hpp:217
SparseSolverBase is the virtual base for both the sequential/multithreaded and distributed sparse sol...
Definition SparseSolverBase.hpp:78
ReturnCode solve(int nrhs, const scalar_t *b, int ldb, scalar_t *x, int ldx, bool use_initial_guess=false)
SparseSolverBase(int argc, char *argv[], bool verbose=true, bool root=true)
void set_from_options(int argc, char *argv[])
const SPOptions< scalar_t > & options() const
ReturnCode solve(const DenseM_t &b, DenseM_t &x, bool use_initial_guess=false)
ReturnCode inertia(integer_t &neg, integer_t &zero, integer_t &pos)
ReturnCode solve(const scalar_t *b, scalar_t *x, bool use_initial_guess=false)
std::size_t factor_nonzeros() const
std::size_t factor_memory() const
void draw(const std::string &name) const
SPOptions< scalar_t > & options()
SparseSolverBase(bool verbose=true, bool root=true)
ReturnCode reorder(int nx=1, int ny=1, int nz=1, int components=1, int width=1)
ReturnCode reorder(const int *p, int base=0)
Definition StrumpackOptions.hpp:44
ReturnCode
Enumeration for the possible return codes.
Definition StrumpackParameters.hpp:50