Go to the documentation of this file. 1 #ifndef PARGEMSLR_CSR_MATRIX_H
2 #define PARGEMSLR_CSR_MATRIX_H
10 #include "../utils/utils.hpp"
11 #include "../vectors/int_vector.hpp"
12 #include "../vectors/sequential_vector.hpp"
27 class CsrMatrixClass:
public MatrixClass<T>
37 IntVectorClass<int> _i_vec;
43 IntVectorClass<int> _j_vec;
49 SequentialVectorClass<T> _a_vec;
88 #if (PARGEMSLR_CUDA_VERSION == 11)
93 cusparseSpMatDescr_t _cusparse_mat;
104 typename std::conditional<PargemslrIsDoublePrecision<T>::value,
159 int Setup(
int nrows,
int ncols,
int nnz);
170 int Setup(
int nrows,
int ncols,
int nnz,
int location);
182 int Setup(
int nrows,
int ncols,
int nnz,
bool setzero);
195 int Setup(
int nrows,
int ncols,
int nnz,
bool holdvalue,
bool setzero);
208 int Setup(
int nrows,
int ncols,
int nnz,
int location,
bool setzero);
222 int Setup(
int nrows,
int ncols,
int nnz,
int location,
bool holdvalue,
bool setzero);
237 int Setup(
int nrows,
int ncols,
int nnz,
int location,
bool holdvalue,
bool setzero,
bool iscsr);
429 #ifdef PARGEMSLR_CUDA
430 #if (PARGEMSLR_CUDA_VERSION == 11)
436 cusparseSpMatDescr_t GetCusparseMat()
const;
444 int SetCusparseMat(cusparseSpMatDescr_t cusparse_mat);
467 const bool&
IsCsr()
const;
503 virtual int Fill(
const T &v);
511 virtual int MoveData(
const int &location);
519 virtual int Scale(
const T &alpha);
600 int PlotPattern(
int *rperm,
int *cperm,
int conditiona,
int conditionb);
612 int PlotPatternGnuPlot(
const char *datafilename,
int *rperm,
int *cperm,
int conditiona,
int conditionb);
623 int Plot(
int *perm,
int conditiona,
int conditionb,
int width);
639 int Laplacian(
int nx,
int ny,
int nz, T alphax, T alphay, T alphaz, T shift,
bool rand_perturb =
false);
665 template <
typename T1>
668 this->_diagonal_shift = diagonal_shift;
669 return PARGEMSLR_SUCCESS;
678 template <
typename T1>
687 template <
typename T1>
700 comm = *parallel_log::_lcomm;
703 return PARGEMSLR_SUCCESS;
713 return *parallel_log::_lcomm;
718 typedef CsrMatrixClass<float> matrix_csr_float;
719 typedef CsrMatrixClass<double> matrix_csr_double;
720 typedef CsrMatrixClass<complexs> matrix_csr_complexs;
721 typedef CsrMatrixClass<complexd> matrix_csr_complexd;
virtual int Scale(const T &alpha)
Scale the current csr matrix.
Definition: csr_matrix.cpp:1262
bool & IsCsr()
Csr or csc.
Definition: csr_matrix.cpp:1144
virtual int Fill(const T &v)
Fill the matrix with constant value.
Definition: csr_matrix.cpp:1248
int Transpose()
Transpost the current matrix.
Definition: csr_matrix.cpp:1455
int GetComplexShift(T1 &diagonal_shift)
Get the diagonal complex shift for some preconditioner options.
Definition: csr_matrix.cpp:1723
int Plot(int *perm, int conditiona, int conditionb, int width)
Plot the csr matrix to the terminal output. Function for testing purpose.
Definition: csr_matrix.cpp:1658
int MatMat(const T &alpha, const CsrMatrixClass< T > &A, char transa, const CsrMatrixClass< T > &B, char transb, const T &beta)
Dense Matrix-Matrix multiplication, C = alpha*transa(A)*transb(B)+beta*C where C is this matrix.
Definition: csr_matrix.cpp:1372
bool & IsRowSorted()
Tell if the column/row indices in each row/column is sorted.
Definition: csr_matrix.cpp:1164
CsrMatrixClass()
The constructor of CsrMatrixClass.
Definition: csr_matrix.cpp:23
int SortRow()
Sort the column/row indices in each row/column.
Definition: csr_matrix.cpp:1189
SequentialVectorClass< T > & GetDataVector()
Get the reference to the data vector.
Definition: csr_matrix.cpp:1085
virtual int Eye()
Create an indentity matrix.
Definition: csr_matrix.cpp:1201
virtual int MatVec(char trans, const T &alpha, const VectorClass< T > &x, const T &beta, VectorClass< T > &y)
In place csr Matrix-Vector product ==> y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y.
Definition: csr_matrix.cpp:1340
IntVectorClass< int > & GetIVector()
Get the reference to the I vector.
Definition: csr_matrix.cpp:1043
virtual int GetDataLocation() const
Get the data location of the matrix.
Definition: csr_matrix.cpp:938
virtual int GetNumColsLocal() const
Get the local number of columns of the matrix.
Definition: csr_matrix.cpp:965
int SubMatrix(int row_start, int col_start, int num_rows, int num_cols, int location, CsrMatrixClass< T > &csrmat_out)
Copy data to extract a submatrix of the current matrix.
Definition: csr_matrix.cpp:398
int Helmholtz(int n, T w)
Generate 3D Helmholtz matrix with 7-pt on [0,1]^3. -\Delta u - w^2 u = 0.
Definition: csr_matrix.cpp:1692
int Convert(bool csr)
Convert between csr and csc.
Definition: csr_matrix.cpp:1383
CsrMatrixClass< T > & operator=(const CsrMatrixClass< T > &mat)
The = operator of CsrMatrixClass.
Definition: csr_matrix.cpp:111
bool IsHoldingData() const
Check if the matrix holding its own data.
Definition: csr_matrix.cpp:1134
int GetConnectedComponents(std::vector< vector_int > &comp_indices, int &ncomps)
Get the connected components of A + AT, where A is the current matrix.
Definition: csr_matrix.cpp:729
int SetComplexShift(T1 diagonal_shift)
Set the diagonal complex shift for some preconditioner options.
Definition: csr_matrix.hpp:666
int * GetI() const
Get the I pointer of the matrix.
Definition: csr_matrix.cpp:1013
The virtual class of real/complex vector class.
Definition: vector.hpp:126
int ReadFromMMFile(const char *matfile, int idxin)
Read matrix on the host memory, matrix market format.
Definition: csr_matrix.cpp:1706
The class of sequential real/complex vector.
Definition: structs.hpp:12
MPI_Comm GetComm() const
Get the MPI_comm.
Definition: csr_matrix.hpp:711
int SubMatrixNoPerm(vector_int &rows, vector_int &cols, vector_int &row_perm, vector_int &col_perm, bool complement, int location, CsrMatrixClass< T > &csrmat_out)
Copy data to extract a submatrix of the current matrix.
Definition: csr_matrix.cpp:668
int Laplacian(int nx, int ny, int nz, T alphax, T alphay, T alphaz, T shift, bool rand_perturb=false)
Generate Laplacian matrix on the host memory, 5-pt for 2D problem and 7-pt for 3D problem.
Definition: csr_matrix.cpp:1676
The virtual matrix classes.
The template class complex.
Definition: complex.hpp:24
int GetDiagScale(T &scale)
Get the value leads to max diagonal no.
Definition: csr_matrix.cpp:1275
int GetMpiInfo(int &np, int &myid, MPI_Comm &comm) const
Get comm, np, and myid. Get the sequential comm.
Definition: csr_matrix.hpp:698
IntVectorClass< int > & GetJVector()
Get the reference to the J vector.
Definition: csr_matrix.cpp:1064
int SetNumNonzeros()
Set the number of nonzeros in this matrix.
Definition: csr_matrix.cpp:985
virtual long int GetNumNonzeros() const
Get the number of nonzeros in this matrix.
Definition: csr_matrix.cpp:975
virtual int MoveData(const int &location)
Move the data to another memory location.
Definition: csr_matrix.cpp:1236
int PushBack(int col, T v)
Insert value at the end of the J and A vector, user need to update the I vector.
Definition: csr_matrix.cpp:373
int SetupVectorPtrStr(SequentialVectorClass< T > &vec)
Update the structure of a vector to have same row permutation.
Definition: csr_matrix.cpp:928
T * GetData() const
Get the data pointer of the matrix.
Definition: csr_matrix.cpp:1033
int PlotPattern(int *rperm, int *cperm, int conditiona, int conditionb)
Plot the pattern of the csr matrix to the terminal output. Similar to spy in the MATLAB....
Definition: csr_matrix.cpp:1493
virtual int Clear()
Free the current matrix.
Definition: csr_matrix.cpp:191
Tell if a value is a complex value.
Definition: complex.hpp:684
virtual int GetNumRowsLocal() const
Get the local number of rows of the matrix.
Definition: csr_matrix.cpp:955
int Setup(int nrows, int ncols, int nnz)
Free the current matrix, and allocate memory to create a new matrix.
Definition: csr_matrix.cpp:223
int * GetJ() const
Get the J pointer of the matrix.
Definition: csr_matrix.cpp:1023
int PlotPatternGnuPlot(const char *datafilename, int *rperm, int *cperm, int conditiona, int conditionb)
Plot the pattern of the csr matrix using gnuplot. Similar to spy in the MATLAB. Function for testing ...
Definition: csr_matrix.cpp:1574
Class of CSR/CSC matrices.
Definition: structs.hpp:16
virtual ~CsrMatrixClass()
The destructor of CsrMatrixClass.
Definition: csr_matrix.cpp:181
std::conditional< PargemslrIsDoublePrecision< T >::value, double, float >::type _diagonal_shift
The diagonal complex shift in some preconditioners. The preconditioner would be built on A+_diagonal_...
Definition: csr_matrix.hpp:106