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  real_t norm1() const override;
72 
73  void spmv(const DenseM_t& x, DenseM_t& y) const override;
74  void spmv(const scalar_t* x, scalar_t* y) const override;
75 
76  void spmv(Trans op, const DenseM_t& x, DenseM_t& y) const;
77 
78  Equil_t equilibration() const override;
79 
80  void equilibrate(const Equil_t& eq) override;
81 
82  void permute_columns(const std::vector<integer_t>& perm) override;
83 
84  real_t max_scaled_residual(const scalar_t* x, const scalar_t* b)
85  const override;
86  real_t max_scaled_residual(const DenseM_t& x, const DenseM_t& b)
87  const override;
88 
89  int read_matrix_market(const std::string& filename) override;
90  int read_binary(const std::string& filename);
91  void print_dense(const std::string& name) const override;
92  void print_matrix_market(const std::string& filename) const override;
93  void print_binary(const std::string& filename) const;
94 
96  extract_graph(int ordering_level,
97  integer_t lo, integer_t hi) const override;
99  extract_graph_sep_CB(int ordering_level, integer_t lo, integer_t hi,
100  const std::vector<integer_t>& upd) const override;
102  extract_graph_CB_sep(int ordering_level, integer_t lo, integer_t hi,
103  const std::vector<integer_t>& upd) const override;
105  extract_graph_CB(int ordering_level,
106  const std::vector<integer_t>& upd) const override;
107 
108 #ifndef DOXYGEN_SHOULD_SKIP_THIS
109  // TODO implement these outside of this class
110  void front_multiply(integer_t slo, integer_t shi,
111  const std::vector<integer_t>& upd,
112  const DenseM_t& R, DenseM_t& Sr, DenseM_t& Sc,
113  int depth) const override;
114  void extract_separator(integer_t sep_end,
115  const std::vector<std::size_t>& I,
116  const std::vector<std::size_t>& J,
117  DenseM_t& B, int depth) const override;
118  void extract_front(DenseM_t& F11, DenseM_t& F12, DenseM_t& F21,
119  integer_t sep_begin, integer_t sep_end,
120  const std::vector<integer_t>& upd,
121  int depth) const override;
122 
123  void push_front_elements(integer_t, integer_t,
124  const std::vector<integer_t>&,
125  std::vector<Triplet<scalar_t>>&,
126  std::vector<Triplet<scalar_t>>&,
127  std::vector<Triplet<scalar_t>>&) const override;
128  void set_front_elements(integer_t, integer_t,
129  const std::vector<integer_t>&,
130  Triplet<scalar_t>*, Triplet<scalar_t>*,
131  Triplet<scalar_t>*) const override;
132  void count_front_elements(integer_t, integer_t,
133  const std::vector<integer_t>&,
134  std::size_t&, std::size_t&, std::size_t&)
135  const override;
136 
137  void front_multiply_F11(Trans op, integer_t slo, integer_t shi,
138  const DenseM_t& R, DenseM_t& S,
139  int depth) const override;
140  void front_multiply_F12(Trans op, integer_t slo, integer_t shi,
141  const std::vector<integer_t>& upd,
142  const DenseM_t& R, DenseM_t& S,
143  int depth) const override;
144  void front_multiply_F21(Trans op, integer_t slo, integer_t shi,
145  const std::vector<integer_t>& upd,
146  const DenseM_t& R, DenseM_t& S,
147  int depth) const override;
148 
149 #if defined(STRUMPACK_USE_MPI)
150  void extract_F11_block(scalar_t* F, integer_t ldF,
151  integer_t row, integer_t nr_rows,
152  integer_t col, integer_t nr_cols) const override;
153  void extract_F12_block(scalar_t* F, integer_t ldF,
154  integer_t row, integer_t nr_rows,
155  integer_t col, integer_t nr_cols,
156  const integer_t* upd) const override;
157  void extract_F21_block(scalar_t* F, integer_t ldF,
158  integer_t row, integer_t nr_rows,
159  integer_t col, integer_t nr_cols,
160  const integer_t* upd) const override;
161  void extract_separator_2d(integer_t sep_end,
162  const std::vector<std::size_t>& I,
163  const std::vector<std::size_t>& J,
164  DistM_t& B) const override;
165  void front_multiply_2d(integer_t sep_begin, integer_t sep_end,
166  const std::vector<integer_t>& upd,
167  const DistM_t& R, DistM_t& Srow, DistM_t& Scol,
168  int depth) const override;
169  void front_multiply_2d(Trans op, integer_t sep_begin, integer_t sep_end,
170  const std::vector<integer_t>& upd,
171  const DistM_t& R, DistM_t& S,
172  int depth) const override;
173 #endif //defined(STRUMPACK_USE_MPI)
174 #endif //DOXYGEN_SHOULD_SKIP_THIS
175 
176  protected:
177  int strumpack_mc64(MatchingJob, Match_t&) override;
178 
179  void scale(const std::vector<scalar_t>& Dr,
180  const std::vector<scalar_t>& Dc) override;
181  void scale_real(const std::vector<real_t>& Dr,
182  const std::vector<real_t>& Dc) override;
183 
184  private:
185  using CSM_t::n_;
186  using CSM_t::nnz_;
187  using CSM_t::ptr_;
188  using CSM_t::ind_;
189  using CSM_t::val_;
190  using CSM_t::symm_sparse_;
191  };
192 
204  template<typename scalar_t, typename integer_t, typename cast_t>
207 
208 } // end namespace strumpack
209 
210 #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:54
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:150
integer_t nnz() const
Definition: CompressedSparseMatrix.hpp:177
const integer_t * ptr() const
Definition: CompressedSparseMatrix.hpp:188
const integer_t * ind() const
Definition: CompressedSparseMatrix.hpp:197
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: DistributedMatrix.hpp:52
Definition: CompressedSparseMatrix.hpp:97
Definition: CompressedSparseMatrix.hpp:56
Definition: StrumpackOptions.hpp:42
MatchingJob
Definition: StrumpackOptions.hpp:113
Trans
Definition: DenseMatrix.hpp:51
CSRMatrix< cast_t, integer_t > cast_matrix(const CSRMatrix< scalar_t, integer_t > &mat)