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;
148 template<
typename scalar_t,
typename integer_t>
151 using real_t =
typename RealType<scalar_t>::value_type;
152#if defined(STRUMPACK_USE_MPI)
169 integer_t
size()
const {
return n_; }
176 integer_t
nnz()
const {
return nnz_; }
187 const integer_t*
ptr()
const {
return ptr_.data(); }
196 const integer_t*
ind()
const {
return ind_.data(); }
205 const scalar_t*
val()
const {
return val_.data(); }
215 integer_t*
ptr() {
return ptr_.data(); }
224 integer_t*
ind() {
return ind_.data(); }
232 scalar_t*
val() {
return val_.data(); }
239 const integer_t&
ptr(integer_t i)
const { assert(i >= 0 && i <=
size());
return ptr_[i]; }
247 const integer_t&
ind(integer_t i)
const { assert(i >= 0 && i <
nnz());
return ind_[i]; }
254 const scalar_t&
val(integer_t i)
const { assert(i >= 0 && i <
nnz());
return val_[i]; }
261 integer_t&
ptr(integer_t i) { assert(i <=
size());
return ptr_[i]; }
269 integer_t&
ind(integer_t i) { assert(i <
nnz());
return ind_[i]; }
276 scalar_t&
val(integer_t i) { assert(i <
nnz());
return val_[i]; }
278 virtual real_t norm1()
const = 0;
324 virtual void spmv(
const scalar_t* x, scalar_t* y)
const = 0;
330 virtual void permute(
const integer_t* iorder,
const integer_t* order);
332 virtual void permute(
const std::vector<integer_t>& iorder,
333 const std::vector<integer_t>& order) {
334 permute(iorder.data(), order.data());
337 virtual void permute_columns(
const std::vector<integer_t>& perm) = 0;
339 virtual Equil_t equilibration()
const {
return Equil_t(this->
size()); }
341 virtual void equilibrate(
const Equil_t&) {}
343 virtual Match_t matching(
MatchingJob,
bool apply=
true);
345 virtual void apply_matching(
const Match_t&);
347 virtual void symmetrize_sparsity();
349 virtual void print()
const;
350 virtual void print_dense(
const std::string& name)
const {
351 std::cerr <<
"print_dense not implemented for this matrix type"
354 virtual void print_matrix_market(
const std::string& filename)
const {
355 std::cerr <<
"print_matrix_market not implemented for this matrix type"
359 virtual int read_matrix_market(
const std::string& filename) = 0;
361 virtual real_t max_scaled_residual(
const scalar_t* x,
362 const scalar_t* b)
const = 0;
363 virtual real_t max_scaled_residual(
const DenseM_t& x,
364 const DenseM_t& b)
const = 0;
366#ifndef DOXYGEN_SHOULD_SKIP_THIS
367 virtual CSRGraph<integer_t>
368 extract_graph(
int ordering_level, integer_t lo, integer_t hi)
const = 0;
369 virtual CSRGraph<integer_t>
370 extract_graph_sep_CB(
int ordering_level, integer_t lo, integer_t hi,
371 const std::vector<integer_t>& upd)
const = 0;
372 virtual CSRGraph<integer_t>
373 extract_graph_CB_sep(
int ordering_level, integer_t lo, integer_t hi,
374 const std::vector<integer_t>& upd)
const = 0;
375 virtual CSRGraph<integer_t>
376 extract_graph_CB(
int ordering_level,
377 const std::vector<integer_t>& upd)
const = 0;
380 extract_separator(integer_t sep_end,
const std::vector<std::size_t>& I,
381 const std::vector<std::size_t>& J, DenseM_t& B,
382 int depth)
const = 0;
384 extract_front(DenseM_t& F11, DenseM_t& F12, DenseM_t& F21,
385 integer_t slo, integer_t shi,
386 const std::vector<integer_t>& upd,
387 int depth)
const = 0;
389 push_front_elements(integer_t, integer_t,
const std::vector<integer_t>&,
390 std::vector<Triplet<scalar_t>>&,
391 std::vector<Triplet<scalar_t>>&,
392 std::vector<Triplet<scalar_t>>&)
const = 0;
394 set_front_elements(integer_t, integer_t,
const std::vector<integer_t>&,
395 Triplet<scalar_t>*, Triplet<scalar_t>*,
396 Triplet<scalar_t>*)
const = 0;
398 count_front_elements(integer_t, integer_t,
const std::vector<integer_t>&,
399 std::size_t&, std::size_t&, std::size_t&)
const = 0;
402 front_multiply(integer_t slo, integer_t shi,
403 const std::vector<integer_t>& upd,
404 const DenseM_t& R, DenseM_t& Sr, DenseM_t& Sc,
405 int depth)
const = 0;
408 front_multiply_F11(
Trans op, integer_t slo, integer_t shi,
409 const DenseM_t& R, DenseM_t& S,
int depth)
const = 0;
411 front_multiply_F12(
Trans op, integer_t slo, integer_t shi,
412 const std::vector<integer_t>& upd,
413 const DenseM_t& R, DenseM_t& S,
int depth)
const = 0;
415 front_multiply_F21(
Trans op, integer_t slo, integer_t shi,
416 const std::vector<integer_t>& upd,
417 const DenseM_t& R, DenseM_t& S,
int depth)
const = 0;
419#if defined(STRUMPACK_USE_MPI)
421 extract_F11_block(scalar_t* F, integer_t ldF,
422 integer_t row, integer_t nr_rows,
423 integer_t col, integer_t nr_cols)
const = 0;
425 extract_F12_block(scalar_t* F, integer_t ldF,
426 integer_t row, integer_t nr_rows,
427 integer_t col, integer_t nr_cols,
428 const integer_t* upd)
const = 0;
430 extract_F21_block(scalar_t* F, integer_t ldF,
431 integer_t row, integer_t nr_rows,
432 integer_t col, integer_t nr_cols,
433 const integer_t* upd)
const = 0;
435 extract_separator_2d(integer_t sep_end,
436 const std::vector<std::size_t>& I,
437 const std::vector<std::size_t>& J,
438 DistM_t& B)
const = 0;
440 front_multiply_2d(integer_t sep_begin, integer_t sep_end,
441 const std::vector<integer_t>& upd,
442 const DistM_t& R, DistM_t& Srow, DistM_t& Scol,
443 int depth)
const = 0;
445 front_multiply_2d(
Trans op, integer_t sep_begin, integer_t sep_end,
446 const std::vector<integer_t>& upd,
const DistM_t& R,
447 DistM_t& S,
int depth)
const = 0;
453 std::vector<integer_t> ptr_, ind_;
454 std::vector<scalar_t> val_;
457 enum MMsym {GENERAL, SYMMETRIC, SKEWSYMMETRIC, HERMITIAN};
459 CompressedSparseMatrix();
460 CompressedSparseMatrix(integer_t n, integer_t
nnz,
462 CompressedSparseMatrix(integer_t n,
463 const integer_t* row_ptr,
464 const integer_t* col_ind,
465 const scalar_t* values,
bool symm_sparsity);
467 std::vector<std::tuple<integer_t,integer_t,scalar_t>>
468 read_matrix_market_entries(
const std::string& filename);
470 virtual int strumpack_mc64(
MatchingJob, Match_t&) {
return 0; }
472 virtual void scale(
const std::vector<scalar_t>&,
473 const std::vector<scalar_t>&) = 0;
474 virtual void scale_real(
const std::vector<real_t>&,
475 const std::vector<real_t>&) = 0;
477 long long spmv_flops()
const;
478 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:149
const integer_t & ptr(integer_t i) const
Definition: CompressedSparseMatrix.hpp:239
bool symm_sparse() const
Definition: CompressedSparseMatrix.hpp:284
integer_t * ind()
Definition: CompressedSparseMatrix.hpp:224
scalar_t & val(integer_t i)
Definition: CompressedSparseMatrix.hpp:276
scalar_t * val()
Definition: CompressedSparseMatrix.hpp:232
integer_t nnz() const
Definition: CompressedSparseMatrix.hpp:176
virtual void spmv(const scalar_t *x, scalar_t *y) const =0
const integer_t * ptr() const
Definition: CompressedSparseMatrix.hpp:187
const scalar_t & val(integer_t i) const
Definition: CompressedSparseMatrix.hpp:254
const scalar_t * val() const
Definition: CompressedSparseMatrix.hpp:205
integer_t size() const
Definition: CompressedSparseMatrix.hpp:169
integer_t & ind(integer_t i)
Definition: CompressedSparseMatrix.hpp:269
integer_t & ptr(integer_t i)
Definition: CompressedSparseMatrix.hpp:261
virtual ~CompressedSparseMatrix()
Definition: CompressedSparseMatrix.hpp:162
virtual void permute(const integer_t *iorder, const integer_t *order)
virtual void spmv(const DenseM_t &x, DenseM_t &y) const =0
void set_symm_sparse(bool symm_sparse=true)
Definition: CompressedSparseMatrix.hpp:293
const integer_t & ind(integer_t i) const
Definition: CompressedSparseMatrix.hpp:247
const integer_t * ind() const
Definition: CompressedSparseMatrix.hpp:196
integer_t * ptr()
Definition: CompressedSparseMatrix.hpp:215
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
@ MAX_SMALLEST_DIAGONAL_2
@ MAX_DIAGONAL_PRODUCT_SCALING
Trans
Definition: DenseMatrix.hpp:51