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 // #include "ordering/Graph.hpp"
41 
42 namespace strumpack {
43 
54  template<typename scalar_t,typename integer_t> class CSRMatrix
55  : public CompressedSparseMatrix<scalar_t,integer_t> {
56 #if defined(STRUMPACK_USE_MPI)
58 #endif
62  using real_t = typename RealType<scalar_t>::value_type;
65 
66  public:
67  CSRMatrix();
68  CSRMatrix(integer_t n, integer_t nnz);
69  CSRMatrix(integer_t n, const integer_t* ptr, const integer_t* ind,
70  const scalar_t* values, bool symm_sparsity=false);
71 
72  real_t norm1() const override;
73 
74  void spmv(const DenseM_t& x, DenseM_t& y) const override;
75  void spmv(const scalar_t* x, scalar_t* y) const override;
76 
77  void spmv(Trans op, const DenseM_t& x, DenseM_t& y) const;
78 
79  Equil_t equilibration() const override;
80 
81  void equilibrate(const Equil_t& eq) override;
82 
83  void permute_columns(const std::vector<integer_t>& perm) override;
84 
85  real_t max_scaled_residual(const scalar_t* x, const scalar_t* b)
86  const override;
87  real_t max_scaled_residual(const DenseM_t& x, const DenseM_t& b)
88  const override;
89 
90  std::unique_ptr<CSRMatrix<scalar_t,integer_t>>
91  add_missing_diagonal(const scalar_t& s) const;
92 
93  int read_matrix_market(const std::string& filename) override;
94  int read_binary(const std::string& filename);
95  void print_dense(const std::string& name) const override;
96  void print_matrix_market(const std::string& filename) const override;
97  void print_binary(const std::string& filename) const;
98 
100  extract_graph(int ordering_level,
101  integer_t lo, integer_t hi) const override;
103  extract_graph_sep_CB(int ordering_level, integer_t lo, integer_t hi,
104  const std::vector<integer_t>& upd) const override;
106  extract_graph_CB_sep(int ordering_level, integer_t lo, integer_t hi,
107  const std::vector<integer_t>& upd) const override;
109  extract_graph_CB(int ordering_level,
110  const std::vector<integer_t>& upd) const override;
111 
112  // ordering::Graph<integer_t> graph() const;
113 
114 #ifndef DOXYGEN_SHOULD_SKIP_THIS
115  // TODO implement these outside of this class
116  void front_multiply(integer_t slo, integer_t shi,
117  const std::vector<integer_t>& upd,
118  const DenseM_t& R, DenseM_t& Sr, DenseM_t& Sc,
119  int depth) const override;
120  void extract_separator(integer_t sep_end,
121  const std::vector<std::size_t>& I,
122  const std::vector<std::size_t>& J,
123  DenseM_t& B, int depth) const override;
124  void extract_front(DenseM_t& F11, DenseM_t& F12, DenseM_t& F21,
125  integer_t sep_begin, integer_t sep_end,
126  const std::vector<integer_t>& upd,
127  int depth) const override;
128 
129  void push_front_elements(integer_t, integer_t,
130  const std::vector<integer_t>&,
131  std::vector<Triplet<scalar_t>>&,
132  std::vector<Triplet<scalar_t>>&,
133  std::vector<Triplet<scalar_t>>&) const override;
134  void set_front_elements(integer_t, integer_t,
135  const std::vector<integer_t>&,
136  Triplet<scalar_t>*, Triplet<scalar_t>*,
137  Triplet<scalar_t>*) const override;
138  void count_front_elements(integer_t, integer_t,
139  const std::vector<integer_t>&,
140  std::size_t&, std::size_t&, std::size_t&)
141  const override;
142 
143  void front_multiply_F11(Trans op, integer_t slo, integer_t shi,
144  const DenseM_t& R, DenseM_t& S,
145  int depth) const override;
146  void front_multiply_F12(Trans op, integer_t slo, integer_t shi,
147  const std::vector<integer_t>& upd,
148  const DenseM_t& R, DenseM_t& S,
149  int depth) const override;
150  void front_multiply_F21(Trans op, integer_t slo, integer_t shi,
151  const std::vector<integer_t>& upd,
152  const DenseM_t& R, DenseM_t& S,
153  int depth) const override;
154 
155 #if defined(STRUMPACK_USE_MPI)
156  void extract_F11_block(scalar_t* F, integer_t ldF,
157  integer_t row, integer_t nr_rows,
158  integer_t col, integer_t nr_cols) const override;
159  void extract_F12_block(scalar_t* F, integer_t ldF,
160  integer_t row, integer_t nr_rows,
161  integer_t col, integer_t nr_cols,
162  const integer_t* upd) const override;
163  void extract_F21_block(scalar_t* F, integer_t ldF,
164  integer_t row, integer_t nr_rows,
165  integer_t col, integer_t nr_cols,
166  const integer_t* upd) const override;
167  void extract_separator_2d(integer_t sep_end,
168  const std::vector<std::size_t>& I,
169  const std::vector<std::size_t>& J,
170  DistM_t& B) const override;
171  void front_multiply_2d(integer_t sep_begin, integer_t sep_end,
172  const std::vector<integer_t>& upd,
173  const DistM_t& R, DistM_t& Srow, DistM_t& Scol,
174  int depth) const override;
175  void front_multiply_2d(Trans op, integer_t sep_begin, integer_t sep_end,
176  const std::vector<integer_t>& upd,
177  const DistM_t& R, DistM_t& S,
178  int depth) const override;
179 #endif //defined(STRUMPACK_USE_MPI)
180 #endif //DOXYGEN_SHOULD_SKIP_THIS
181 
182  protected:
183  int strumpack_mc64(MatchingJob, Match_t&) override;
184 
185  void scale(const std::vector<scalar_t>& Dr,
186  const std::vector<scalar_t>& Dc) override;
187  void scale_real(const std::vector<real_t>& Dr,
188  const std::vector<real_t>& Dc) override;
189  void sort_rows();
190 
191  private:
192  using CSM_t::n_;
193  using CSM_t::nnz_;
194  using CSM_t::ptr_;
195  using CSM_t::ind_;
196  using CSM_t::val_;
197  using CSM_t::symm_sparse_;
198  };
199 
211  template<typename scalar_t, typename integer_t, typename cast_t>
214 
215 } // end namespace strumpack
216 
217 #endif // STRUMPACK_CSR_MATRIX_HPP
Contains the CompressedSparseMatrix class, a base class for compressed sparse storage.
Definition: CompressedSparseMatrix.hpp:49
Class for storing a compressed sparse row matrix (single node).
Definition: CSRMatrix.hpp:55
void spmv(const scalar_t *x, scalar_t *y) const override
void spmv(const DenseM_t &x, DenseM_t &y) const override
Abstract base class for compressed sparse matrix storage.
Definition: CompressedSparseMatrix.hpp:149
integer_t nnz() const
Definition: CompressedSparseMatrix.hpp:176
const integer_t * ptr() const
Definition: CompressedSparseMatrix.hpp:187
const integer_t * ind() const
Definition: CompressedSparseMatrix.hpp:196
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
2D block cyclicly distributed matrix, as used by ScaLAPACK.
Definition: DistributedMatrix.hpp:84
Definition: CompressedSparseMatrix.hpp:97
Definition: CompressedSparseMatrix.hpp:56
Definition: StrumpackOptions.hpp:43
MatchingJob
Definition: StrumpackOptions.hpp:119
Trans
Definition: DenseMatrix.hpp:51
CSRMatrix< cast_t, integer_t > cast_matrix(const CSRMatrix< scalar_t, integer_t > &mat)