SparseMatrix.h
Go to the documentation of this file.
/*****************************************************************************
*
* Copyright (c) 2003-2020 by The University of Queensland
* http://www.uq.edu.au
*
* Primary Business: Queensland, Australia
* Licensed under the Apache License, version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
* Development 2012-2013 by School of Earth Sciences
* Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
* Development from 2019 by School of Earth and Environmental Sciences
**
*****************************************************************************/
/****************************************************************************/
/* Paso: SparseMatrix */
/****************************************************************************/
/* Author: lgross@uq.edu.au */
/****************************************************************************/
#ifndef __PASO_SPARSEMATRIX_H__
#define __PASO_SPARSEMATRIX_H__
#include "Pattern.h"
namespace paso {
struct SparseMatrix;
typedef boost::shared_ptr<SparseMatrix> SparseMatrix_ptr;
typedef boost::shared_ptr<const SparseMatrix> const_SparseMatrix_ptr;
typedef int SparseMatrixType;
// this struct holds a sparse matrix
struct SparseMatrix : boost::enable_shared_from_this<SparseMatrix>
{
SparseMatrix(SparseMatrixType type, Pattern_ptr pattern,
dim_t rowBlockSize, dim_t colBlockSize,
bool patternIsUnrolled);
~SparseMatrix();
void setValues(double value);
void copyFromMainDiagonal(double* out) const;
void copyToMainDiagonal(const double* in);
void copyBlockFromMainDiagonal(double* out) const;
void copyBlockToMainDiagonal(const double* in);
void applyBlockMatrix(double* block_diag, index_t* pivot, double* x,
const double* b) const;
void invMain(double* inv_diag, index_t* pivot) const;
SparseMatrix_ptr unroll(SparseMatrixType type) const;
SparseMatrix_ptr getSubmatrix(dim_t n_row_sub,
dim_t n_col_sub,
const index_t* row_list,
const index_t* new_col_index) const;
SparseMatrix_ptr getBlock(int blockid) const;
SparseMatrix_ptr getTranspose() const;
void saveHB_CSC(const char* filename) const;
void saveMM(const char* filename) const;
inline index_t* borrowMainDiagonalPointer() const
{
return pattern->borrowMainDiagonalPointer();
}
inline index_t* borrowColoringPointer() const
{
return pattern->borrowColoringPointer();
}
inline dim_t getNumColors() const
{
return pattern->getNumColors();
}
inline dim_t maxDeg() const
{
return pattern->maxDeg();
}
inline dim_t getTotalNumRows() const
{
return numRows * row_block_size;
}
inline dim_t getTotalNumCols() const
{
return numCols * col_block_size;
}
inline dim_t getNumRows() const
{
return numRows;
}
inline dim_t getNumCols() const
{
return numCols;
}
inline double getSize() const
{
return (double)len;
}
inline double getSparsity() const
{
return getSize() / ((double)getTotalNumRows()*getTotalNumCols());
}
static SparseMatrix_ptr loadMM_toCSR(const char* filename);
void nullifyRowsAndCols_CSC_BLK1(const double* mask_row,
const double* mask_col,
double main_diagonal_value);
void nullifyRowsAndCols_CSR_BLK1(const double* mask_row,
const double* mask_col,
double main_diagonal_value);
void nullifyRowsAndCols_CSC(const double* mask_row, const double* mask_col,
double main_diagonal_value);
void nullifyRowsAndCols_CSR(const double* mask_row, const double* mask_col,
double main_diagonal_value);
void nullifyRows_CSR_BLK1(const double* mask_row,
double main_diagonal_value);
void nullifyRows_CSR(const double* mask_row, double main_diagonal_value);
void maxAbsRow_CSR_OFFSET0(double* array) const;
void addAbsRow_CSR_OFFSET0(double* array) const;
void addRow_CSR_OFFSET0(double* array) const;
void applyDiagonal_CSR_OFFSET0(const double* left, const double* right);
SparseMatrixType type;
dim_t row_block_size;
dim_t col_block_size;
dim_t block_size;
dim_t numRows;
dim_t numCols;
Pattern_ptr pattern;
dim_t len;
double *val;
index_t solver_package;
void* solver_p;
};
// interfaces:
void SparseMatrix_MatrixVector_CSC_OFFSET0(const double alpha,
const_SparseMatrix_ptr A,
const double* in,
const double beta, double* out);
void SparseMatrix_MatrixVector_CSC_OFFSET1(const double alpha,
const_SparseMatrix_ptr A,
const double* in,
const double beta, double* out);
void SparseMatrix_MatrixVector_CSR_OFFSET0(const double alpha,
const_SparseMatrix_ptr A,
const double* in,
const double beta, double* out);
void SparseMatrix_MatrixVector_CSR_OFFSET1(const double alpha,
const_SparseMatrix_ptr A,
const double* in,
const double beta, double* out);
void SparseMatrix_MatrixVector_CSR_OFFSET0_DIAG(const double alpha,
const_SparseMatrix_ptr A,
const double* in,
const double beta, double* out);
SparseMatrix_ptr SparseMatrix_MatrixMatrix(const_SparseMatrix_ptr A,
const_SparseMatrix_ptr B);
SparseMatrix_ptr SparseMatrix_MatrixMatrixTranspose(const_SparseMatrix_ptr A,
const_SparseMatrix_ptr B,
const_SparseMatrix_ptr T);
} // namespace paso
#endif // __PASO_SPARSEMATRIX_H__
BlockOps.h
MATRIX_FORMAT_BLK1
#define MATRIX_FORMAT_BLK1
Definition: Paso.h:64
paso::SparseMatrix_MatrixVector_CSC_OFFSET1
void SparseMatrix_MatrixVector_CSC_OFFSET1(const double alpha, const_SparseMatrix_ptr A, const double *in, const double beta, double *out)
Definition: SparseMatrix_MatrixVector.cpp:138
paso::UMFPACK_free
void UMFPACK_free(SparseMatrix *A)
frees any UMFPACK related data from the matrix
Definition: UMFPACK.cpp:50
paso::SparseMatrix::getTotalNumRows
dim_t getTotalNumRows() const
Definition: SparseMatrix.h:114
MKL.h
mm_read_mtx_crd_size
int mm_read_mtx_crd_size(std::istream &f, int *M, int *N, int *nz)
Definition: mmio.cpp:182
paso::SparseMatrix::nullifyRowsAndCols_CSR_BLK1
void nullifyRowsAndCols_CSR_BLK1(const double *mask_row, const double *mask_col, double main_diagonal_value)
Definition: SparseMatrix_nullifyRowsAndCols.cpp:73
paso::N
static dim_t N
Definition: SparseMatrix_saveHB.cpp:52
paso::SparseMatrix::numCols
dim_t numCols
Definition: SparseMatrix.h:179
paso::SparseMatrix::addAbsRow_CSR_OFFSET0
void addAbsRow_CSR_OFFSET0(double *array) const
Definition: SparseMatrix.cpp:358
mm_write_mtx_crd_size
int mm_write_mtx_crd_size(std::ostream &f, int M, int N, int nz)
Definition: mmio.cpp:174
paso::SparseMatrix::block_size
dim_t block_size
Definition: SparseMatrix.h:177
paso::SparseMatrix::copyBlockFromMainDiagonal
void copyBlockFromMainDiagonal(double *out) const
Definition: SparseMatrix.cpp:426
paso::SparseMatrix::row_block_size
dim_t row_block_size
Definition: SparseMatrix.h:175
MATRIX_FORMAT_CSC
#define MATRIX_FORMAT_CSC
Definition: Paso.h:63
paso::SparseMatrix::loadMM_toCSR
static SparseMatrix_ptr loadMM_toCSR(const char *filename)
Definition: SparseMatrix.cpp:217
paso::SparseMatrix::getTotalNumCols
dim_t getTotalNumCols() const
Definition: SparseMatrix.h:119
paso::SparseMatrix::pattern
Pattern_ptr pattern
Definition: SparseMatrix.h:180
paso::SparseMatrix::getNumColors
dim_t getNumColors() const
Definition: SparseMatrix.h:104
paso::SparseMatrix::solver_p
void * solver_p
pointer to data needed by a solver
Definition: SparseMatrix.h:190
mm_set_real
#define mm_set_real(typecode)
Definition: mmio.h:79
paso::BlockOps_invM_2
void BlockOps_invM_2(double *invA, const double *A, int *failed)
Definition: BlockOps.h:113
paso::SparseMatrix::nullifyRowsAndCols_CSR
void nullifyRowsAndCols_CSR(const double *mask_row, const double *mask_col, double main_diagonal_value)
Definition: SparseMatrix_nullifyRowsAndCols.cpp:115
mmio.h
UMFPACK.h
paso::SparseMatrix::getBlock
SparseMatrix_ptr getBlock(int blockid) const
Definition: SparseMatrix_getSubmatrix.cpp:94
paso::SparseMatrix::maxDeg
dim_t maxDeg() const
Definition: SparseMatrix.h:109
paso::SparseMatrix::SparseMatrix
SparseMatrix(SparseMatrixType type, Pattern_ptr pattern, dim_t rowBlockSize, dim_t colBlockSize, bool patternIsUnrolled)
Definition: SparseMatrix.cpp:122
mm_is_general
#define mm_is_general(typecode)
Definition: mmio.h:63
paso::SparseMatrix::setValues
void setValues(double value)
Definition: SparseMatrix.cpp:491
paso::BlockOps_invM_N
void BlockOps_invM_N(dim_t N, double *mat, index_t *pivot, int *failed)
LU factorization of NxN matrix mat with partial pivoting.
Definition: BlockOps.h:162
paso::SparseMatrix::invMain
void invMain(double *inv_diag, index_t *pivot) const
Definition: SparseMatrix.cpp:506
PASO_MKL
#define PASO_MKL
Definition: Options.h:50
paso::SparseMatrix_MatrixVector_CSR_OFFSET1
void SparseMatrix_MatrixVector_CSR_OFFSET1(const double alpha, const_SparseMatrix_ptr A, const double *in, const double beta, double *out)
Definition: SparseMatrix_MatrixVector.cpp:210
MATRIX_FORMAT_OFFSET1
#define MATRIX_FORMAT_OFFSET1
Definition: Paso.h:65
SparseMatrix.h
Options.h
paso::SparseMatrix_MatrixVector_CSR_OFFSET0_DIAG
void SparseMatrix_MatrixVector_CSR_OFFSET0_DIAG(const double alpha, const_SparseMatrix_ptr A, const double *in, const double beta, double *out)
Definition: SparseMatrix_MatrixVector.cpp:445
paso::BlockOps_solveAll
void BlockOps_solveAll(dim_t n_block, dim_t n, double *D, index_t *pivot, double *x)
Definition: BlockOps.h:233
paso::util::copy
void copy(dim_t N, double *out, const double *in)
out = in
Definition: PasoUtil.h:116
paso::Preconditioner_LocalSmoother_free
void Preconditioner_LocalSmoother_free(Preconditioner_LocalSmoother *in)
Definition: Smoother.cpp:57
paso::SparseMatrix::copyBlockToMainDiagonal
void copyBlockToMainDiagonal(const double *in)
Definition: SparseMatrix.cpp:414
paso::SparseMatrix::type
SparseMatrixType type
Definition: SparseMatrix.h:174
paso::nz
static dim_t nz
Definition: SparseMatrix_saveHB.cpp:52
paso::util::comparIndex
int comparIndex(const void *index1, const void *index2)
this int-comparison function is used by qsort/bsearch in various places
Definition: PasoUtil.cpp:54
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:93
paso::SparseMatrix::saveMM
void saveMM(const char *filename) const
Definition: SparseMatrix.cpp:295
paso::SparseMatrix::maxAbsRow_CSR_OFFSET0
void maxAbsRow_CSR_OFFSET0(double *array) const
Definition: SparseMatrix.cpp:377
paso::const_SparseMatrix_ptr
boost::shared_ptr< const SparseMatrix > const_SparseMatrix_ptr
Definition: SparseMatrix.h:52
paso::BlockOps_invM_3
void BlockOps_invM_3(double *invA, const double *A, int *failed)
Definition: BlockOps.h:131
paso::SparseMatrix::nullifyRows_CSR_BLK1
void nullifyRows_CSR_BLK1(const double *mask_row, double main_diagonal_value)
Definition: SparseMatrix_nullifyRowsAndCols.cpp:139
paso::SparseMatrix::getSparsity
double getSparsity() const
Definition: SparseMatrix.h:139
paso::SparseMatrix::getNumCols
dim_t getNumCols() const
Definition: SparseMatrix.h:129
mm_set_matrix
#define mm_set_matrix(typecode)
Definition: mmio.h:72
MM_typecode
char MM_typecode[4]
Definition: mmio.h:35
paso::swap
void swap(index_t *r, index_t *c, double *v, int left, int right)
Definition: SparseMatrix.cpp:71
paso::SparseMatrix::nullifyRowsAndCols_CSC_BLK1
void nullifyRowsAndCols_CSC_BLK1(const double *mask_row, const double *mask_col, double main_diagonal_value)
Definition: SparseMatrix_nullifyRowsAndCols.cpp:55
paso::MKL_free
void MKL_free(SparseMatrix *A)
Definition: MKL.cpp:50
paso::SparseMatrixType
int SparseMatrixType
Definition: SparseMatrix.h:54
paso::SparseMatrix::nullifyRows_CSR
void nullifyRows_CSR(const double *mask_row, double main_diagonal_value)
Definition: SparseMatrix_nullifyRowsAndCols.cpp:156
paso::SparseMatrix::copyToMainDiagonal
void copyToMainDiagonal(const double *in)
Definition: SparseMatrix.cpp:452
paso::SparseMatrix::saveHB_CSC
void saveHB_CSC(const char *filename) const
Definition: SparseMatrix_saveHB.cpp:194
paso::SparseMatrix::~SparseMatrix
~SparseMatrix()
Definition: SparseMatrix.cpp:199
Pattern.h
PASO_PASO
#define PASO_PASO
Definition: Options.h:56
paso::SparseMatrix_MatrixMatrixTranspose
SparseMatrix_ptr SparseMatrix_MatrixMatrixTranspose(const_SparseMatrix_ptr A, const_SparseMatrix_ptr B, const_SparseMatrix_ptr T)
Definition: SparseMatrix_MatrixMatrixTranspose.cpp:76
paso::SparseMatrix::len
dim_t len
Definition: SparseMatrix.h:181
PASO_UMFPACK
#define PASO_UMFPACK
Definition: Options.h:51
paso::SparseMatrix::applyBlockMatrix
void applyBlockMatrix(double *block_diag, index_t *pivot, double *x, const double *b) const
Definition: SparseMatrix.cpp:556
paso::SparseMatrix::copyFromMainDiagonal
void copyFromMainDiagonal(double *out) const
Definition: SparseMatrix.cpp:438
paso::SparseMatrix::solver_package
index_t solver_package
package controlling the solver pointer
Definition: SparseMatrix.h:187
paso::SparseMatrix_ptr
boost::shared_ptr< SparseMatrix > SparseMatrix_ptr
Definition: SparseMatrix.h:50
paso::SparseMatrix::addRow_CSR_OFFSET0
void addRow_CSR_OFFSET0(double *array) const
Definition: SparseMatrix.cpp:396
paso::BlockOps_Cpy_N
void BlockOps_Cpy_N(dim_t N, double *R, const double *V)
Definition: BlockOps.h:54
paso::PasoException
PasoException exception class.
Definition: PasoException.h:47
paso::SparseMatrix::val
double * val
this is used for classical CSR or CSC
Definition: SparseMatrix.h:184
mm_initialize_typecode
#define mm_initialize_typecode(typecode)
Definition: mmio.h:92
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:88
mm_is_real
#define mm_is_real(typecode)
Definition: mmio.h:58
mm_read_banner
int mm_read_banner(std::istream &f, MM_typecode *matcode)
Definition: mmio.cpp:104
Preconditioner.h
paso::SparseMatrix_MatrixVector_CSR_OFFSET0
void SparseMatrix_MatrixVector_CSR_OFFSET0(const double alpha, const_SparseMatrix_ptr A, const double *in, const double beta, double *out)
Definition: SparseMatrix_MatrixVector.cpp:298
paso::SparseMatrix::getTranspose
SparseMatrix_ptr getTranspose() const
Definition: SparseMatrix.cpp:565
PasoUtil.h
paso::SparseMatrix::getSubmatrix
SparseMatrix_ptr getSubmatrix(dim_t n_row_sub, dim_t n_col_sub, const index_t *row_list, const index_t *new_col_index) const
Definition: SparseMatrix_getSubmatrix.cpp:58
paso::SparseMatrix::nullifyRowsAndCols_CSC
void nullifyRowsAndCols_CSC(const double *mask_row, const double *mask_col, double main_diagonal_value)
Definition: SparseMatrix_nullifyRowsAndCols.cpp:91
paso::SparseMatrix::getSize
double getSize() const
Definition: SparseMatrix.h:134
mm_write_banner
int mm_write_banner(std::ostream &f, MM_typecode matcode)
Definition: mmio.cpp:357
paso::M
static dim_t M
Definition: SparseMatrix_saveHB.cpp:52
paso::SparseMatrix::numRows
dim_t numRows
Definition: SparseMatrix.h:178
paso::SparseMatrix::getNumRows
dim_t getNumRows() const
Definition: SparseMatrix.h:124
paso::Pattern_ptr
boost::shared_ptr< Pattern > Pattern_ptr
Definition: Pattern.h:52
paso::SparseMatrix::borrowMainDiagonalPointer
index_t * borrowMainDiagonalPointer() const
Definition: SparseMatrix.h:94
paso::SparseMatrix_MatrixVector_CSC_OFFSET0
void SparseMatrix_MatrixVector_CSC_OFFSET0(const double alpha, const_SparseMatrix_ptr A, const double *in, const double beta, double *out)
Definition: SparseMatrix_MatrixVector.cpp:62
mm_set_coordinate
#define mm_set_coordinate(typecode)
Definition: mmio.h:73
escript::IndexList
Definition: escriptcore/src/IndexList.h:29
paso::SparseMatrix_MatrixMatrix
SparseMatrix_ptr SparseMatrix_MatrixMatrix(const_SparseMatrix_ptr A, const_SparseMatrix_ptr B)
Definition: SparseMatrix_MatrixMatrix.cpp:67
paso
Definition: BiCGStab.cpp:26
PASO_SMOOTHER
#define PASO_SMOOTHER
Definition: Options.h:74
paso::SparseMatrix
Definition: SparseMatrix.h:57
paso::SparseMatrix::unroll
SparseMatrix_ptr unroll(SparseMatrixType type) const
Definition: SparseMatrix.cpp:641
paso::q_sort
void q_sort(index_t *row, index_t *col, double *val, int begin, int end, int N)
Definition: SparseMatrix.cpp:89
MATRIX_FORMAT_DEFAULT
#define MATRIX_FORMAT_DEFAULT
Definition: Paso.h:62
paso::SparseMatrix::borrowColoringPointer
index_t * borrowColoringPointer() const
Definition: SparseMatrix.h:99
MATRIX_FORMAT_DIAGONAL_BLOCK
#define MATRIX_FORMAT_DIAGONAL_BLOCK
Definition: Paso.h:66
paso::SparseMatrix::applyDiagonal_CSR_OFFSET0
void applyDiagonal_CSR_OFFSET0(const double *left, const double *right)
Definition: SparseMatrix.cpp:466
paso::SparseMatrix::col_block_size
dim_t col_block_size
Definition: SparseMatrix.h:176
mm_is_sparse
#define mm_is_sparse(typecode)
Definition: mmio.h:52