Device Matrix

template<typename NumType>
class DeviceMatrix : public BaseMatrix<NumType>

Implementation of a Matrix class on the device system.

Template Parameters
  • NumType: Number type (double and float currently supported). This class uses the Compressed Row Storage (CRS) format.

Public Functions

DeviceMatrix()

Default constructor.

virtual ~DeviceMatrix()

Destructor.

virtual void allocate(int m, int n, int nnz)

Allocate a matrix of size m x n with nnz non-zero entries.

Parameters
  • m: The number of rows.
  • n: The number of columns.
  • nnz: The number of non-zero entries.

virtual void clear()

Clear matrix.

virtual void copy_from(const NumType *val, const int *row_ptr, const int *col_idx)

Copy data to the matrix.

Note
allocate should be called first.
Note
All 3 parameters should be on device memory.
Parameters
  • val: The pointer to the values to copy.
  • row_ptr: The pointer to the indices of val starting a new row.
  • col_idx: The pointer to the column indices of the elements in val.

virtual void copy_from(const BaseMatrix<NumType> &B)

A = B, where A is the matrix itself.

Parameters
  • B: The matrix to copy.

virtual void copy_to(BaseMatrix<NumType> &B) const

B = A, where A is the matrix itself.

Parameters
  • B: The matrix to copy to.

virtual NumType norm() const

Return
The Frobenius norm of the matrix.

virtual void scale(NumType alpha)

A = alpha * A, where A is the matrix itself.

Parameters
  • alpha: The value by which to scale the entries in the matrix.

virtual void multiply(const BaseVector<NumType> &v_in, BaseVector<NumType> *w_out) const

w_out = A * v_in, where A is the matrix itself.

Parameters
  • v_in: The vector right-multiplying the vector.
  • w_out: The outputted vector.

virtual void lower_solve(const BaseVector<NumType> &b, BaseVector<NumType> *x) const

Solvers for x in (L + D) * x = b, where L and D are respectively the lower triangular and diagonal parts of the matrix itself. \param[in] b The vector in the above equation \param[out] x The vector in the above equation

virtual void upper_solve(const BaseVector<NumType> &b, BaseVector<NumType> *x) const

Solvers for x in (U + D) * x = b, where U and D are respectively the upper triangular and diagonal parts of the matrix itself. \param[in] b The vector in the above equation \param[out] x The vector in the above equation

virtual void get_diagonals(BaseVector<NumType> *diag) const

Outputs the diagonal entries of the matrix.

Parameters
  • w_out: The outputted vector storing the diagonal entries.

virtual void compute_inverse_diagonals(BaseVector<NumType> *inv_diag) const

Compute the inverse of the diagonal entries of the matrix.

Parameters
  • w_out: The outputted vector storing the inverse of the diagonal entries.

bool read_matrix_market(const std::string filename)

Read a matrix market.

Return
True if successfully read, and False otherwise.
Parameters
  • filename: The matrix market file.