34 #ifndef COMPRESSED_SPARSE_MATRIX_HPP
35 #define COMPRESSED_SPARSE_MATRIX_HPP
41 #include "misc/Tools.hpp"
42 #include "misc/Triplet.hpp"
54 template<
typename scalar_t,
typename integer_t,
55 typename real_t =
typename RealType<scalar_t>::value_type>
69 std::vector<integer_t> Q;
70 std::vector<real_t> R, C;
72 integer_t mc64_work_int(std::size_t n, std::size_t nnz)
const {
83 integer_t mc64_work_double(std::size_t n, std::size_t nnz)
const {
90 default:
return 3*n + nnz;
95 template<
typename scalar_t,
96 typename real_t =
typename RealType<scalar_t>::value_type>
103 Equilibration(std::size_t rows, std::size_t cols) : R(rows), C(cols) {}
106 EquilibrationType type = EquilibrationType::NONE;
107 real_t rcond = 1, ccond = 1, Amax = 0;
108 std::vector<real_t> R, C;
111 const real_t thres = 0.1;
112 const real_t small = blas::lamch<real_t>(
'S') / blas::lamch<real_t>(
'P');
113 const real_t large = 1. / small;
114 if (rcond >= thres && Amax >= small && Amax <= large) {
116 if (ccond >= thres) {
117 type = EquilibrationType::NONE;
119 }
else type = EquilibrationType::COLUMN;
121 if (ccond >= thres) {
122 type = EquilibrationType::ROW;
124 }
else type = EquilibrationType::BOTH;
149 template<
typename scalar_t,
typename integer_t>
152 using real_t =
typename RealType<scalar_t>::value_type;
153 #if defined(STRUMPACK_USE_MPI)
170 integer_t
size()
const {
return n_; }
177 integer_t
nnz()
const {
return nnz_; }
188 const integer_t*
ptr()
const {
return ptr_.data(); }
197 const integer_t*
ind()
const {
return ind_.data(); }
206 const scalar_t*
val()
const {
return val_.data(); }
216 integer_t*
ptr() {
return ptr_.data(); }
225 integer_t*
ind() {
return ind_.data(); }
233 scalar_t*
val() {
return val_.data(); }
240 const integer_t&
ptr(integer_t i)
const { assert(i >= 0 && i <=
size());
return ptr_[i]; }
248 const integer_t&
ind(integer_t i)
const { assert(i >= 0 && i <
nnz());
return ind_[i]; }
255 const scalar_t&
val(integer_t i)
const { assert(i >= 0 && i <
nnz());
return val_[i]; }
262 integer_t&
ptr(integer_t i) { assert(i <=
size());
return ptr_[i]; }
270 integer_t&
ind(integer_t i) { assert(i <
nnz());
return ind_[i]; }
277 scalar_t&
val(integer_t i) { assert(i <
nnz());
return val_[i]; }
279 virtual real_t norm1()
const = 0;
325 virtual void spmv(
const scalar_t* x, scalar_t* y)
const = 0;
331 virtual void permute(
const integer_t* iorder,
const integer_t* order);
333 virtual void permute(
const std::vector<integer_t>& iorder,
334 const std::vector<integer_t>& order) {
335 permute(iorder.data(), order.data());
338 virtual void permute_columns(
const std::vector<integer_t>& perm) = 0;
340 virtual Equil_t equilibration()
const {
return Equil_t(this->
size()); }
342 virtual void equilibrate(
const Equil_t&) {}
344 virtual Match_t matching(
MatchingJob,
bool apply=
true);
346 virtual void apply_matching(
const Match_t&);
348 virtual void symmetrize_sparsity();
350 virtual void print()
const;
351 virtual void print_dense(
const std::string& name)
const {
352 std::cerr <<
"print_dense not implemented for this matrix type"
355 virtual void print_matrix_market(
const std::string& filename)
const {
356 std::cerr <<
"print_matrix_market not implemented for this matrix type"
360 virtual int read_matrix_market(
const std::string& filename) = 0;
362 virtual real_t max_scaled_residual(
const scalar_t* x,
363 const scalar_t* b)
const = 0;
364 virtual real_t max_scaled_residual(
const DenseM_t& x,
365 const DenseM_t& b)
const = 0;
368 #ifndef DOXYGEN_SHOULD_SKIP_THIS
369 virtual CSRGraph<integer_t>
370 extract_graph(
int ordering_level, integer_t lo, integer_t hi)
const = 0;
371 virtual CSRGraph<integer_t>
372 extract_graph_sep_CB(
int ordering_level, integer_t lo, integer_t hi,
373 const std::vector<integer_t>& upd)
const = 0;
374 virtual CSRGraph<integer_t>
375 extract_graph_CB_sep(
int ordering_level, integer_t lo, integer_t hi,
376 const std::vector<integer_t>& upd)
const = 0;
377 virtual CSRGraph<integer_t>
378 extract_graph_CB(
int ordering_level,
379 const std::vector<integer_t>& upd)
const = 0;
382 extract_separator(integer_t sep_end,
const std::vector<std::size_t>& I,
383 const std::vector<std::size_t>& J, DenseM_t& B,
384 int depth)
const = 0;
386 extract_front(DenseM_t& F11, DenseM_t& F12, DenseM_t& F21,
387 integer_t slo, integer_t shi,
388 const std::vector<integer_t>& upd,
389 int depth)
const = 0;
391 push_front_elements(integer_t, integer_t,
const std::vector<integer_t>&,
392 std::vector<Triplet<scalar_t>>&,
393 std::vector<Triplet<scalar_t>>&,
394 std::vector<Triplet<scalar_t>>&)
const = 0;
396 set_front_elements(integer_t, integer_t,
const std::vector<integer_t>&,
397 Triplet<scalar_t>*, Triplet<scalar_t>*,
398 Triplet<scalar_t>*)
const = 0;
400 count_front_elements(integer_t, integer_t,
const std::vector<integer_t>&,
401 std::size_t&, std::size_t&, std::size_t&)
const = 0;
404 front_multiply(integer_t slo, integer_t shi,
405 const std::vector<integer_t>& upd,
406 const DenseM_t& R, DenseM_t& Sr, DenseM_t& Sc,
407 int depth)
const = 0;
410 front_multiply_F11(
Trans op, integer_t slo, integer_t shi,
411 const DenseM_t& R, DenseM_t& S,
int depth)
const = 0;
413 front_multiply_F12(
Trans op, integer_t slo, integer_t shi,
414 const std::vector<integer_t>& upd,
415 const DenseM_t& R, DenseM_t& S,
int depth)
const = 0;
417 front_multiply_F21(
Trans op, integer_t slo, integer_t shi,
418 const std::vector<integer_t>& upd,
419 const DenseM_t& R, DenseM_t& S,
int depth)
const = 0;
421 #if defined(STRUMPACK_USE_MPI)
423 extract_F11_block(scalar_t* F, integer_t ldF,
424 integer_t row, integer_t nr_rows,
425 integer_t col, integer_t nr_cols)
const = 0;
427 extract_F12_block(scalar_t* F, integer_t ldF,
428 integer_t row, integer_t nr_rows,
429 integer_t col, integer_t nr_cols,
430 const integer_t* upd)
const = 0;
432 extract_F21_block(scalar_t* F, integer_t ldF,
433 integer_t row, integer_t nr_rows,
434 integer_t col, integer_t nr_cols,
435 const integer_t* upd)
const = 0;
437 extract_separator_2d(integer_t sep_end,
438 const std::vector<std::size_t>& I,
439 const std::vector<std::size_t>& J,
440 DistM_t& B)
const = 0;
442 front_multiply_2d(integer_t sep_begin, integer_t sep_end,
443 const std::vector<integer_t>& upd,
444 const DistM_t& R, DistM_t& Srow, DistM_t& Scol,
445 int depth)
const = 0;
447 front_multiply_2d(
Trans op, integer_t sep_begin, integer_t sep_end,
448 const std::vector<integer_t>& upd,
const DistM_t& R,
449 DistM_t& S,
int depth)
const = 0;
455 std::vector<integer_t> ptr_, ind_;
456 std::vector<scalar_t> val_;
459 enum MMsym {GENERAL, SYMMETRIC, SKEWSYMMETRIC, HERMITIAN};
461 CompressedSparseMatrix();
462 CompressedSparseMatrix(integer_t n, integer_t
nnz,
464 CompressedSparseMatrix(integer_t n,
465 const integer_t* row_ptr,
466 const integer_t* col_ind,
467 const scalar_t* values,
bool symm_sparsity);
469 std::vector<std::tuple<integer_t,integer_t,scalar_t>>
470 read_matrix_market_entries(
const std::string& filename);
472 virtual int strumpack_mc64(
MatchingJob, Match_t&) {
return 0; }
474 virtual void scale(
const std::vector<scalar_t>&,
475 const std::vector<scalar_t>&) = 0;
476 virtual void scale_real(
const std::vector<real_t>&,
477 const std::vector<real_t>&) = 0;
479 long long spmv_flops()
const;
480 long long spmv_bytes()
const;
Contains the DenseMatrix and DenseMatrixWrapper classes, simple wrappers around BLAS/LAPACK style den...
Holds options for the sparse solver.
Definition: CompressedSparseMatrix.hpp:49
Abstract base class for compressed sparse matrix storage.
Definition: CompressedSparseMatrix.hpp:150
const integer_t & ind(integer_t i) const
Definition: CompressedSparseMatrix.hpp:248
const scalar_t * val() const
Definition: CompressedSparseMatrix.hpp:206
bool symm_sparse() const
Definition: CompressedSparseMatrix.hpp:285
const integer_t & ptr(integer_t i) const
Definition: CompressedSparseMatrix.hpp:240
integer_t * ptr()
Definition: CompressedSparseMatrix.hpp:216
integer_t nnz() const
Definition: CompressedSparseMatrix.hpp:177
virtual void spmv(const scalar_t *x, scalar_t *y) const =0
integer_t size() const
Definition: CompressedSparseMatrix.hpp:170
scalar_t & val(integer_t i)
Definition: CompressedSparseMatrix.hpp:277
integer_t & ind(integer_t i)
Definition: CompressedSparseMatrix.hpp:270
integer_t & ptr(integer_t i)
Definition: CompressedSparseMatrix.hpp:262
scalar_t * val()
Definition: CompressedSparseMatrix.hpp:233
virtual ~CompressedSparseMatrix()
Definition: CompressedSparseMatrix.hpp:163
virtual void permute(const integer_t *iorder, const integer_t *order)
virtual void spmv(const DenseM_t &x, DenseM_t &y) const =0
integer_t * ind()
Definition: CompressedSparseMatrix.hpp:225
const integer_t * ptr() const
Definition: CompressedSparseMatrix.hpp:188
const scalar_t & val(integer_t i) const
Definition: CompressedSparseMatrix.hpp:255
void set_symm_sparse(bool symm_sparse=true)
Definition: CompressedSparseMatrix.hpp:294
const integer_t * ind() const
Definition: CompressedSparseMatrix.hpp:197
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
@ MAX_SMALLEST_DIAGONAL_2
@ MAX_DIAGONAL_PRODUCT_SCALING
Trans
Definition: DenseMatrix.hpp:51