CSRMatrix.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  *
28  */
33 #ifndef STRUMPACK_CSR_MATRIX_HPP
34 #define STRUMPACK_CSR_MATRIX_HPP
35 
36 #include <vector>
37 
39 #include "CSRGraph.hpp"
40 
41 namespace strumpack {
42 
53  template<typename scalar_t,typename integer_t> class CSRMatrix
54  : public CompressedSparseMatrix<scalar_t,integer_t> {
55 #if defined(STRUMPACK_USE_MPI)
57 #endif
61  using real_t = typename RealType<scalar_t>::value_type;
64 
65  public:
66  CSRMatrix();
67  CSRMatrix(integer_t n, integer_t nnz);
68  CSRMatrix(integer_t n, const integer_t* ptr, const integer_t* ind,
69  const scalar_t* values, bool symm_sparsity=false);
70 
71  void spmv(const DenseM_t& x, DenseM_t& y) const override;
72  void spmv(const scalar_t* x, scalar_t* y) const override;
73 
74  void spmv(Trans op, const DenseM_t& x, DenseM_t& y) const;
75 
76  Equil_t equilibration() const override;
77 
78  void equilibrate(const Equil_t& eq) override;
79 
80  void permute_columns(const std::vector<integer_t>& perm) override;
81 
82  real_t max_scaled_residual(const scalar_t* x, const scalar_t* b)
83  const override;
84  real_t max_scaled_residual(const DenseM_t& x, const DenseM_t& b)
85  const override;
86 
87  int read_matrix_market(const std::string& filename) override;
88  int read_binary(const std::string& filename);
89  void print_dense(const std::string& name) const override;
90  void print_matrix_market(const std::string& filename) const override;
91  void print_binary(const std::string& filename) const;
92 
93  CSRGraph<integer_t> extract_graph
94  (int ordering_level, integer_t lo, integer_t hi) const override;
95  CSRGraph<integer_t> extract_graph_sep_CB
96  (int ordering_level, integer_t lo, integer_t hi,
97  const std::vector<integer_t>& upd) const override;
98  CSRGraph<integer_t> extract_graph_CB_sep
99  (int ordering_level, integer_t lo, integer_t hi,
100  const std::vector<integer_t>& upd) const override;
101  CSRGraph<integer_t> extract_graph_CB
102  (int ordering_level, const std::vector<integer_t>& upd) const override;
103 
104 #ifndef DOXYGEN_SHOULD_SKIP_THIS
105  // TODO implement these outside of this class
106  void front_multiply
107  (integer_t slo, integer_t shi, const std::vector<integer_t>& upd,
108  const DenseM_t& R, DenseM_t& Sr, DenseM_t& Sc, int depth) const override;
109  void extract_separator
110  (integer_t sep_end, const std::vector<std::size_t>& I,
111  const std::vector<std::size_t>& J,
112  DenseM_t& B, int depth) const override;
113  void extract_front
114  (DenseM_t& F11, DenseM_t& F12, DenseM_t& F21, integer_t sep_begin,
115  integer_t sep_end, const std::vector<integer_t>& upd,
116  int depth) const override;
117 
118  void push_front_elements
119  (integer_t, integer_t, const std::vector<integer_t>&,
120  std::vector<Triplet<scalar_t>>&,
121  std::vector<Triplet<scalar_t>>&,
122  std::vector<Triplet<scalar_t>>&) const override;
123 
124  void front_multiply_F11
125  (Trans op, integer_t slo, integer_t shi,
126  const DenseM_t& R, DenseM_t& S, int depth) const override;
127  void front_multiply_F12
128  (Trans op, integer_t slo, integer_t shi, const std::vector<integer_t>& upd,
129  const DenseM_t& R, DenseM_t& S, int depth) const override;
130  void front_multiply_F21
131  (Trans op, integer_t slo, integer_t shi, const std::vector<integer_t>& upd,
132  const DenseM_t& R, DenseM_t& S, int depth) const override;
133 
134 #if defined(STRUMPACK_USE_MPI)
135  void extract_F11_block
136  (scalar_t* F, integer_t ldF, integer_t row, integer_t nr_rows,
137  integer_t col, integer_t nr_cols) const override;
138  void extract_F12_block
139  (scalar_t* F, integer_t ldF, integer_t row,
140  integer_t nr_rows, integer_t col, integer_t nr_cols,
141  const integer_t* upd) const override;
142  void extract_F21_block
143  (scalar_t* F, integer_t ldF, integer_t row,
144  integer_t nr_rows, integer_t col, integer_t nr_cols,
145  const integer_t* upd) const override;
146  void extract_separator_2d
147  (integer_t sep_end, const std::vector<std::size_t>& I,
148  const std::vector<std::size_t>& J, DistM_t& B) const override;
149  void front_multiply_2d
150  (integer_t sep_begin, integer_t sep_end,
151  const std::vector<integer_t>& upd, const DistM_t& R,
152  DistM_t& Srow, DistM_t& Scol, int depth) const override;
153  void front_multiply_2d
154  (Trans op, integer_t sep_begin, integer_t sep_end,
155  const std::vector<integer_t>& upd, const DistM_t& R,
156  DistM_t& S, int depth) const override;
157 #endif //defined(STRUMPACK_USE_MPI)
158 #endif //DOXYGEN_SHOULD_SKIP_THIS
159 
160  protected:
161  int strumpack_mc64(MatchingJob, Match_t&) override;
162 
163  void scale(const std::vector<scalar_t>& Dr,
164  const std::vector<scalar_t>& Dc) override;
165  void scale_real(const std::vector<real_t>& Dr,
166  const std::vector<real_t>& Dc) override;
167 
168  private:
169  using CSM_t::n_;
170  using CSM_t::nnz_;
171  using CSM_t::ptr_;
172  using CSM_t::ind_;
173  using CSM_t::val_;
174  using CSM_t::symm_sparse_;
175  };
176 
177 } // end namespace strumpack
178 
179 #endif // STRUMPACK_CSR_MATRIX_HPP
strumpack::Equilibration< scalar_t >
strumpack::CSRMatrix
Class for storing a compressed sparse row matrix (single node).
Definition: CSRMatrix.hpp:53
strumpack::Side::R
@ R
strumpack
Definition: StrumpackOptions.hpp:42
strumpack::DistributedMatrix
Definition: CompressedSparseMatrix.hpp:58
strumpack::DenseMatrixWrapper
Like DenseMatrix, this class represents a matrix, stored in column major format, to allow direct use ...
Definition: DenseMatrix.hpp:990
CompressedSparseMatrix.hpp
Contains the CompressedSparseMatrix class, a base class for compressed sparse storage.
strumpack::DenseMatrix< scalar_t >
strumpack::CompressedSparseMatrix::ind
const integer_t * ind() const
Definition: CompressedSparseMatrix.hpp:210
strumpack::CompressedSparseMatrix::ptr
const integer_t * ptr() const
Definition: CompressedSparseMatrix.hpp:201
strumpack::CompressedSparseMatrix::nnz
integer_t nnz() const
Definition: CompressedSparseMatrix.hpp:190
strumpack::CSRMatrix::spmv
void spmv(const DenseM_t &x, DenseM_t &y) const override
strumpack::CompressedSparseMatrix
Abstract base class for compressed sparse matrix storage.
Definition: CompressedSparseMatrix.hpp:163
strumpack::Trans
Trans
Definition: DenseMatrix.hpp:50
strumpack::MatchingData
Definition: CompressedSparseMatrix.hpp:69
strumpack::CSRGraph
Definition: CompressedSparseMatrix.hpp:56
strumpack::MatchingJob
MatchingJob
Definition: StrumpackOptions.hpp:95