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
378 void draw(const std::string& name) const;
379
387
388 protected:
389 virtual void setup_tree() = 0;
390 virtual void setup_reordering() = 0;
391 virtual
392 int compute_reordering(const int* p, int base,
393 int nx, int ny, int nz,
394 int components, int width) = 0;
395 virtual void separator_reordering() = 0;
396
397 virtual SpMat_t* matrix() = 0;
398 virtual std::unique_ptr<SpMat_t> matrix_nonzero_diag() = 0;
399 virtual Reord_t* reordering() = 0;
400 virtual Tree_t* tree() = 0;
401 virtual const SpMat_t* matrix() const = 0;
402 virtual const Reord_t* reordering() const = 0;
403 virtual const Tree_t* tree() const = 0;
404
405 virtual void perf_counters_start();
406 virtual void perf_counters_stop(const std::string& s);
407
408 virtual void synchronize() {}
409 virtual void communicate_ordering() {}
410 virtual double max_peak_memory() const
411 { return double(params::peak_memory); }
412 virtual double min_peak_memory() const
413 { return double(params::peak_memory); }
414
415 void papi_initialize();
416 long long dense_factor_nonzeros() const;
417 void print_solve_stats(TaskTimer& t) const;
418
419 virtual void reduce_flop_counters() const {}
420 void print_flop_breakdown_HSS() const;
421 void print_flop_breakdown_HODLR() const;
422 void flop_breakdown_reset() const;
423
424 void print_wrong_sparsity_error();
425
426 SPOptions<scalar_t> opts_;
427 bool is_root_;
428
429 MatchingData<scalar_t,integer_t> matching_;
430 Equilibration<scalar_t> equil_;
431
432 std::new_handler old_handler_;
433 std::ostream* rank_out_ = nullptr;
434 bool factored_ = false;
435 bool reordered_ = false;
436 int Krylov_its_ = 0;
437
438#if defined(STRUMPACK_USE_PAPI)
439 float rtime_ = 0., ptime_ = 0.;
440 long_long _flpops = 0;
441#endif
442#if defined(STRUMPACK_COUNT_FLOPS)
443 long long int f0_ = 0, ftot_ = 0, fmin_ = 0, fmax_ = 0;
444 long long int b0_ = 0, btot_ = 0, bmin_ = 0, bmax_ = 0;
445 long long int m0_ = 0, mtot_ = 0, mmin_ = 0, mmax_ = 0;
446 long long int ptot_ = 0, pmin_ = 0, pmax_ = 0;
447 long long int dm0_ = 0, dmtot_ = 0, dmmin_ = 0, dmmax_ = 0;
448 long long int dptot_ = 0, dpmin_ = 0, dpmax_ = 0;
449#endif
450
451 private:
452 ReturnCode reorder_internal(const int* p, int base,
453 int nx, int ny, int nz,
454 int components, int width);
455
456 virtual
457 ReturnCode solve_internal(const scalar_t* b, scalar_t* x,
458 bool use_initial_guess=false) = 0;
459 virtual
460 ReturnCode solve_internal(const DenseM_t& b, DenseM_t& x,
461 bool use_initial_guess=false) = 0;
462
463 virtual
464 ReturnCode solve_internal(int nrhs, const scalar_t* b, int ldb,
465 scalar_t* x, int ldx,
466 bool use_initial_guess=false);
467
468 virtual void delete_factors_internal() = 0;
469 };
470
471 template<typename scalar_t,typename integer_t>
472 using StrumpackSparseSolverBase =
473 SparseSolverBase<scalar_t,integer_t>;
474
475} //end namespace strumpack
476
477#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:1015
This class represents a matrix, stored in column major format, to allow direct use of BLAS/LAPACK rou...
Definition: DenseMatrix.hpp:138
Definition: SparseSolverBase.hpp:53
Definition: SparseSolverBase.hpp:52
Options for the sparse solver.
Definition: StrumpackOptions.hpp:216
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:43
ReturnCode
Enumeration for the possible return codes.
Definition: StrumpackParameters.hpp:50