SMG2S
Sparse Matrix Generator with Given Spectrum
parMatrixSparse< T, S > Class Template Reference

A class which defines a sparse matrix distributed across 1D MPI grid. More...

#include <parMatrixSparse.hpp>

Public Member Functions

 parMatrixSparse (parVector< T, S > vec)
 A constructor of `parMatrixSparse`. More...
 
 parMatrixSparse (parVectorMap< S > map)
 A constructor of `parMatrixSparse`. More...
 
GetNRows ()
 Return the number of rows of local matrix on each MPI proc.
 
GetNCols ()
 Return the number of columns of local matrix on each MPI proc.
 
GetNNzLoc ()
 Return the number of non-zeros entries of local matrix on each MPI proc.
 
parVectorMap< S > GetMap ()
 Return the parVectorMap object used to distribute sparse Matrix.
 
GetLowerBound ()
 Return parMatrixSparse::lower_b.
 
GetUpperBound ()
 Return parMatrixSparse::upper_b.
 
MPI_Comm GetComm ()
 Return parMatrixSparse::comm.
 
int GetProcId ()
 Return parMatrixSparse::ProcID.
 
int GetNProcs ()
 Return parMatrixSparse::nProcs.
 
std::map< S, T > * GetDynMatLoc ()
 Return parMatrixSparse::dynmat_loc.
 
void SetValueLocal (S row, S col, T value)
 Set a value to a distributed sparse matrix with a given local index on each MPI proc. More...
 
void SetValuesLocal (S nindex, S *rows, S *cols, T *values)
 Set multiple values to a distributed sparse matrix with given multiple local indices on each MPI proc. More...
 
void SetValue (S row, S col, T value)
 Set a value to a distributed sparse matrix with a given global index on each MPI proc. More...
 
void SetDiagonal (parVector< T, S > diag)
 Set the diagonal of a distributed sparse matrix with a given parVector object. More...
 
void AddValueLocal (S row, S col, T value)
 Add a value to an entry of a distributed sparse matrix with a given local index on each MPI proc. More...
 
void AddValue (S row, S col, T value)
 Add a value to an entry of a distributed sparse matrix with a given global index on each MPI proc. More...
 
GetValueLocal (S row, S col)
 Return a value of an entry of a distributed sparse matrix with a given local index on each MPI proc. More...
 
GetValue (S row, S col)
 Return a value to an entry of a distributed sparse matrix with a given global index on each MPI proc. More...
 
void MatScale (T scale)
 Perform an operation `A = scale * A`, in which `scale` is a scalar. More...
 
void MatAXPY (parMatrixSparse< T, S > X, T scale)
 Perform `A = A + scale * X`. More...
 
void MatAYPX (parMatrixSparse< T, S > X, T scale)
 Perform `A = scale * A + X`. More...
 
void initMat (S diag_l, S diag_u, Base< T > scale, T shift, Base< T > sparsity)
 filling the lower part of matrix between diagonal of offset `diag_l` and diagonal of offset `diag_u` with random values `scale * rnd + shift` where `rnd` is a randomly generated value between `0` and `1` More...
 
void initMat (S diag_l, S diag_u)
 filling the lower part of matrix between diagonal of offset `diag_l` and diagonal of offset `diag_u` with random values `rnd`, which is a randomly generated value between `0` and `1` More...
 
void setSpecNonHerm (parVector< T, S > spectrum)
 Set a given spectrum onto a parMatrixSparse object for constructing a non-Hermitian matrix. More...
 
void setSpecNonSymm (parVector< T, S > spectrum)
 Set a given spectrum (all eigenvalues are in real scalars) onto a parMatrixSparse object for constructing a non-Symmetric matrix. More...
 
void setSpecNonSymmCmplx (parVector< std::complex< Base< T >>, S > spectrum)
 Set a given spectrum (all eigenvalues can be in real scalars or appear as pairs of conjugate complex scalars) onto a parMatrixSparse object for constructing a non-Symmetric matrix. More...
 
void updateNnz ()
 Explicitly re-compute the number of nnz on each MPI proc. More...
 
void copy (parMatrixSparse< T, S > X)
 Duplicate from another parMatrixSparse object. More...
 
void rmZeros ()
 Explicitly remove all the zeros of parMatrixSparse object. More...
 
parMatrixSparse< T, S > MA (Nilpotent< S > nilp)
 Perform `M*A`, in which `A` is a nilpotent matrix. More...
 
parMatrixSparse< T, S > AM (Nilpotent< S > nilp)
 Perform `A*M`, in which `A` is a nilpotent matrix. More...
 
void ZeroEntries ()
 Make all the entries a sparse matrix to be zeros, but keep the sparsity structure as it is.
 
MatrixCSR< T, S > ConvertToCSR ()
 Convert a parMatrixSparse with dynamic memory into a distributed CSR matrix. More...
 
void show ()
 Display multiple information of a parMatrixSparse object. More...
 
void MatView ()
 Print a parMatrixSparse object in a distributed COO format. More...
 
void MatView (std::string matName)
 Print a parMatrixSparse object in a distributed COO format with matrix name indicated at the starting point of each line. More...
 
void writeToMatrixMarket (std::string file_name)
 A parallel IO to write a parMatrixSparse object into a file of MatrixMarket format. More...
 
void writeToMatrixMarketCmplx (std::string file_name)
 A parallel IO to write a parMatrixSparse object with complex scalar into a file of MatrixMarket format. More...
 

Private Attributes

std::map< S, T > * dynmat_loc
 An array of `std::map` in which each map stores the column index and related non-zero entry value of each row.
 
ncols
 number of columns of local matrix on each MPI proc
 
nrows
 number of rows of local matrix on each MPI proc
 
nnz_loc
 number of non-zero entries of local matrix on each MPI proc
 
parVectorMap< S > index_map
 the parVectorMap object used to distribute the global matrix across 1D MPI grid
 
lower_b
 the smallest index of row of a distributed matrix on each MPI proc
 
upper_b
 upper_b-1 = the largest index of row of a distributed matrix on each MPI proc
 
MPI_Comm comm
 the working MPI communicator
 
int ProcID
 rank of each MPI procs within the working MPI communicator
 
int nProcs
 number of MPI procs within the working MPI communicator
 

Detailed Description

template<typename T, typename S>
class parMatrixSparse< T, S >

A class which defines a sparse matrix distributed across 1D MPI grid.

  • This class can be constructed with a given parVector with the same distribution scheme.
  • This class can be constructed with a distribution scheme by a given parVectorMap object.
Template Parameters
Tdescribes the scalar types of the entries of a sparse matrix.
Stype of integer to describes the dimension of vector to be generated.

Constructor & Destructor Documentation

◆ parMatrixSparse() [1/2]

template<typename T , typename S >
parMatrixSparse< T, S >::parMatrixSparse ( parVector< T, S >  vec)

A constructor of `parMatrixSparse`.

Parameters
[in]veca given parVector, a parMatrixSparse object is constructed with the same distribution scheme of `vec`

◆ parMatrixSparse() [2/2]

template<typename T , typename S >
parMatrixSparse< T, S >::parMatrixSparse ( parVectorMap< S >  map)

A constructor of `parMatrixSparse`.

Parameters
[in]mapthe distribution scheme determined by this object of type parVectorMap

Member Function Documentation

◆ AddValue()

template<typename T , typename S >
void parMatrixSparse< T, S >::AddValue ( row,
col,
value 
)

Add a value to an entry of a distributed sparse matrix with a given global index on each MPI proc.

Parameters
[in]rowthe global index of row
[in]colthe global index of column
[in]valuethe scalar to be added

◆ AddValueLocal()

template<typename T , typename S >
void parMatrixSparse< T, S >::AddValueLocal ( row,
col,
value 
)

Add a value to an entry of a distributed sparse matrix with a given local index on each MPI proc.

Parameters
[in]rowthe local index of row
[in]colthe local index of column
[in]valuethe scalar to be added

◆ AM()

template<typename T , typename S >
parMatrixSparse< T, S > parMatrixSparse< T, S >::AM ( Nilpotent< S >  nilp)

Perform `A*M`, in which `A` is a nilpotent matrix.

Parameters
[in]nilpa Nilpotent object which determines a nilpotent matrix

◆ ConvertToCSR()

template<typename T , typename S >
MatrixCSR< T, S > parMatrixSparse< T, S >::ConvertToCSR

Convert a parMatrixSparse with dynamic memory into a distributed CSR matrix.

  • Attention, after the converting, any operations on the matrix can be implicity updated on the CSR matrix

◆ copy()

template<typename T , typename S >
void parMatrixSparse< T, S >::copy ( parMatrixSparse< T, S >  X)

Duplicate from another parMatrixSparse object.

Parameters
[in]Xanother parMatrixSparse object to be duplicated with a same distribution scheme

◆ GetValue()

template<typename T , typename S >
T parMatrixSparse< T, S >::GetValue ( row,
col 
)

Return a value to an entry of a distributed sparse matrix with a given global index on each MPI proc.

Parameters
[in]rowthe global index of row
[in]colthe global index of column

◆ GetValueLocal()

template<typename T , typename S >
T parMatrixSparse< T, S >::GetValueLocal ( row,
col 
)

Return a value of an entry of a distributed sparse matrix with a given local index on each MPI proc.

Parameters
[in]rowthe local index of row
[in]colthe local index of column

◆ initMat() [1/2]

template<typename T , typename S >
void parMatrixSparse< T, S >::initMat ( diag_l,
diag_u 
)

filling the lower part of matrix between diagonal of offset `diag_l` and diagonal of offset `diag_u` with random values `rnd`, which is a randomly generated value between `0` and `1`

Parameters
[in]diag_lthe offset of lower diagonal
[in]diag_uthe offset of lower diagonal

◆ initMat() [2/2]

template<typename T , typename S >
void parMatrixSparse< T, S >::initMat ( diag_l,
diag_u,
Base< T >  scale,
shift,
Base< T >  sparsity 
)

filling the lower part of matrix between diagonal of offset `diag_l` and diagonal of offset `diag_u` with random values `scale * rnd + shift` where `rnd` is a randomly generated value between `0` and `1`

Parameters
[in]diag_lthe offset of lower diagonal
[in]diag_uthe offset of lower diagonal
[in]scalea scalar to be multiplied on the randomly generated value
[in]shifta scalar to be added on the randomly generated value
[in]sparsitythe probability that a entry in the range set to be zero

◆ MA()

template<typename T , typename S >
parMatrixSparse< T, S > parMatrixSparse< T, S >::MA ( Nilpotent< S >  nilp)

Perform `M*A`, in which `A` is a nilpotent matrix.

Parameters
[in]nilpa Nilpotent object which determines a nilpotent matrix

◆ MatAXPY()

template<typename T , typename S >
void parMatrixSparse< T, S >::MatAXPY ( parMatrixSparse< T, S >  X,
scale 
)

Perform `A = A + scale * X`.

Parameters
[in]Xanother parMatrixSparse object with a same distribution scheme
[in]scalethe scalar to be multiplied on `X`

◆ MatAYPX()

template<typename T , typename S >
void parMatrixSparse< T, S >::MatAYPX ( parMatrixSparse< T, S >  X,
scale 
)

Perform `A = scale * A + X`.

Parameters
[in]Xanother parMatrixSparse object with a same distribution scheme
[in]scalethe scalar to be multiplied on `A`

◆ MatScale()

template<typename T , typename S >
void parMatrixSparse< T, S >::MatScale ( scale)

Perform an operation `A = scale * A`, in which `scale` is a scalar.

Parameters
[in]scalethe scalar to be multiplied on the distributed sparse matrix

◆ MatView() [1/2]

template<typename T , typename S >
void parMatrixSparse< T, S >::MatView

Print a parMatrixSparse object in a distributed COO format.

  • This is a distributed function that each MPI proc can only display the piece of local matrix on itself.

◆ MatView() [2/2]

template<typename T , typename S >
void parMatrixSparse< T, S >::MatView ( std::string  matName)

Print a parMatrixSparse object in a distributed COO format with matrix name indicated at the starting point of each line.

  • This is a distributed function that each MPI proc can only display the piece of local matrix on itself.

◆ rmZeros()

template<typename T , typename S >
void parMatrixSparse< T, S >::rmZeros

Explicitly remove all the zeros of parMatrixSparse object.

  • This member function is introduced in case any matrix operation would introduce some (explicit) zeros.

◆ SetDiagonal()

template<typename T , typename S >
void parMatrixSparse< T, S >::SetDiagonal ( parVector< T, S >  diag)

Set the diagonal of a distributed sparse matrix with a given parVector object.

Parameters
[in]diaga given parVector object to be set on the diagonal

◆ setSpecNonHerm()

template<typename T , typename S >
void parMatrixSparse< T, S >::setSpecNonHerm ( parVector< T, S >  spectrum)

Set a given spectrum onto a parMatrixSparse object for constructing a non-Hermitian matrix.

Parameters
[in]spectruma parVector object which stores the given spectrum in complex scalars
  • This operation is naturally in parallel since the spectrum is stored in a parVector object
  • Attention, this member function works only with complex scalar

◆ setSpecNonSymm()

template<typename T , typename S >
void parMatrixSparse< T, S >::setSpecNonSymm ( parVector< T, S >  spectrum)

Set a given spectrum (all eigenvalues are in real scalars) onto a parMatrixSparse object for constructing a non-Symmetric matrix.

Parameters
[in]spectruma parVector object which stores the given spectrum in real scalars
  • This operation is naturally in parallel since the spectrum is stored in a parVector object
  • Attention, this member function works only with real scalar

◆ setSpecNonSymmCmplx()

template<typename T , typename S >
void parMatrixSparse< T, S >::setSpecNonSymmCmplx ( parVector< std::complex< Base< T >>, S >  spectrum)

Set a given spectrum (all eigenvalues can be in real scalars or appear as pairs of conjugate complex scalars) onto a parMatrixSparse object for constructing a non-Symmetric matrix.

Parameters
[in]spectruma parVector object which stores the given spectrum with conjugate eigenvalues
  • This operation is naturally in parallel since the spectrum is stored in a parVector object
  • Attention, for each conjugate pairs of eigenvalues, they should be placed one after another, they cannot be placed in a random order. Before setting the spectrum to the matrix, the spectrum will be checked if it satisfies this condition

◆ SetValue()

template<typename T , typename S >
void parMatrixSparse< T, S >::SetValue ( row,
col,
value 
)

Set a value to a distributed sparse matrix with a given global index on each MPI proc.

Parameters
[in]rowthe global index of row
[in]colthe global index of column
[in]valuethe scalar to be set

◆ SetValueLocal()

template<typename T , typename S >
void parMatrixSparse< T, S >::SetValueLocal ( row,
col,
value 
)

Set a value to a distributed sparse matrix with a given local index on each MPI proc.

Parameters
[in]rowthe local index of row
[in]colthe local index of column
[in]valuethe scalar to be set

◆ SetValuesLocal()

template<typename T , typename S >
void parMatrixSparse< T, S >::SetValuesLocal ( nindex,
S *  rows,
S *  cols,
T *  values 
)

Set multiple values to a distributed sparse matrix with given multiple local indices on each MPI proc.

Parameters
[in]nindexnumber of values to be set
[in]rowsan array storing multiple local indices of row
[in]colsan array storing multiple local indices of column
[in]valuesan array storing multiple scalars to be set

◆ show()

template<typename T , typename S >
void parMatrixSparse< T, S >::show

Display multiple information of a parMatrixSparse object.

◆ updateNnz()

template<typename T , typename S >
void parMatrixSparse< T, S >::updateNnz

Explicitly re-compute the number of nnz on each MPI proc.

  • This member function is introduced in case any matrix operation would failed to update the number of nnz

◆ writeToMatrixMarket()

template<typename T , typename S >
void parMatrixSparse< T, S >::writeToMatrixMarket ( std::string  file_name)

A parallel IO to write a parMatrixSparse object into a file of MatrixMarket format.

Parameters
[in]file_namethe path and file name to write into
  • Attention, this method works only of sparse matrix with real scalar (`double`, `float`...)

◆ writeToMatrixMarketCmplx()

template<typename T , typename S >
void parMatrixSparse< T, S >::writeToMatrixMarketCmplx ( std::string  file_name)

A parallel IO to write a parMatrixSparse object with complex scalar into a file of MatrixMarket format.

Parameters
[in]file_namethe path and file name to write into
  • Attention, this method works only of sparse matrix with scalar scalar (std::complex<double>, std::complex<float>...)

The documentation for this class was generated from the following file: