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 
95  CSRGraph<integer_t> extract_graph
96  (int ordering_level, integer_t lo, integer_t hi) const override;
97  CSRGraph<integer_t> extract_graph_sep_CB
98  (int ordering_level, integer_t lo, integer_t hi,
99  const std::vector<integer_t>& upd) const override;
100  CSRGraph<integer_t> extract_graph_CB_sep
101  (int ordering_level, integer_t lo, integer_t hi,
102  const std::vector<integer_t>& upd) const override;
103  CSRGraph<integer_t> extract_graph_CB
104  (int ordering_level, const std::vector<integer_t>& upd) const override;
105 
106 #ifndef DOXYGEN_SHOULD_SKIP_THIS
107  // TODO implement these outside of this class
108  void front_multiply
109  (integer_t slo, integer_t shi, const std::vector<integer_t>& upd,
110  const DenseM_t& R, DenseM_t& Sr, DenseM_t& Sc, int depth) const override;
111  void extract_separator
112  (integer_t sep_end, const std::vector<std::size_t>& I,
113  const std::vector<std::size_t>& J,
114  DenseM_t& B, int depth) const override;
115  void extract_front
116  (DenseM_t& F11, DenseM_t& F12, DenseM_t& F21, integer_t sep_begin,
117  integer_t sep_end, const std::vector<integer_t>& upd,
118  int depth) const override;
119 
120  void push_front_elements
121  (integer_t, integer_t, const std::vector<integer_t>&,
122  std::vector<Triplet<scalar_t>>&,
123  std::vector<Triplet<scalar_t>>&,
124  std::vector<Triplet<scalar_t>>&) const override;
125 
126  void front_multiply_F11
127  (Trans op, integer_t slo, integer_t shi,
128  const DenseM_t& R, DenseM_t& S, int depth) const override;
129  void front_multiply_F12
130  (Trans op, integer_t slo, integer_t shi, const std::vector<integer_t>& upd,
131  const DenseM_t& R, DenseM_t& S, int depth) const override;
132  void front_multiply_F21
133  (Trans op, integer_t slo, integer_t shi, const std::vector<integer_t>& upd,
134  const DenseM_t& R, DenseM_t& S, int depth) const override;
135 
136 #if defined(STRUMPACK_USE_MPI)
137  void extract_F11_block
138  (scalar_t* F, integer_t ldF, integer_t row, integer_t nr_rows,
139  integer_t col, integer_t nr_cols) const override;
140  void extract_F12_block
141  (scalar_t* F, integer_t ldF, integer_t row,
142  integer_t nr_rows, integer_t col, integer_t nr_cols,
143  const integer_t* upd) const override;
144  void extract_F21_block
145  (scalar_t* F, integer_t ldF, integer_t row,
146  integer_t nr_rows, integer_t col, integer_t nr_cols,
147  const integer_t* upd) const override;
148  void extract_separator_2d
149  (integer_t sep_end, const std::vector<std::size_t>& I,
150  const std::vector<std::size_t>& J, DistM_t& B) const override;
151  void front_multiply_2d
152  (integer_t sep_begin, integer_t sep_end,
153  const std::vector<integer_t>& upd, const DistM_t& R,
154  DistM_t& Srow, DistM_t& Scol, int depth) const override;
155  void front_multiply_2d
156  (Trans op, integer_t sep_begin, integer_t sep_end,
157  const std::vector<integer_t>& upd, const DistM_t& R,
158  DistM_t& S, int depth) const override;
159 #endif //defined(STRUMPACK_USE_MPI)
160 #endif //DOXYGEN_SHOULD_SKIP_THIS
161 
162  protected:
163  int strumpack_mc64(MatchingJob, Match_t&) override;
164 
165  void scale(const std::vector<scalar_t>& Dr,
166  const std::vector<scalar_t>& Dc) override;
167  void scale_real(const std::vector<real_t>& Dr,
168  const std::vector<real_t>& Dc) override;
169 
170  private:
171  using CSM_t::n_;
172  using CSM_t::nnz_;
173  using CSM_t::ptr_;
174  using CSM_t::ind_;
175  using CSM_t::val_;
176  using CSM_t::symm_sparse_;
177  };
178 
190  template<typename scalar_t, typename integer_t, typename cast_t>
193 
194 } // end namespace strumpack
195 
196 #endif // STRUMPACK_CSR_MATRIX_HPP
strumpack::Equilibration
Definition: CompressedSparseMatrix.hpp:110
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:991
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::cast_matrix
CSRMatrix< cast_t, integer_t > cast_matrix(const CSRMatrix< scalar_t, integer_t > &mat)
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:98