https://mooseframework.inl.gov
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Moose::Kokkos::Matrix Class Reference

The Kokkos wrapper class for PETSc matrix. More...

#include <KokkosMatrix.h>

Public Member Functions

 Matrix ()=default
 Default constructor. More...
 
 ~Matrix ()
 Destructor. More...
 
void destroy ()
 Free all data and reset. More...
 
bool isAlloc () const
 Get whether the matrix was allocated. More...
 
void create (libMesh::SparseMatrix< PetscScalar > &matrix, const System &system)
 Create the matrix from a libMesh PetscMatrix. More...
 
void close ()
 Assemble the underlying PETSc matrix. More...
 
KOKKOS_FUNCTION void zero (PetscInt i)
 Zero a row. More...
 
KOKKOS_FUNCTION PetscScalar & operator() (PetscInt i, PetscInt j) const
 Get an entry with given row and column indices. More...
 
auto & operator= (PetscScalar scalar)
 Assign a scalar value uniformly. More...
 

Private Member Functions

KOKKOS_FUNCTION PetscInt find (PetscInt i, PetscInt j) const
 Get the index of given row and column indices. More...
 

Private Attributes

Mat _matrix = PETSC_NULLPTR
 PETSc matrix. More...
 
PetscCount _nr = 0
 Number of rows local to this process. More...
 
bool _is_host = false
 Flag whether the PETSc matrix is a host matrix. More...
 
bool _is_alloc = false
 Flag whether the matrix was allocated. More...
 
Array< PetscInt > _col_idx
 CSR vectors on device. More...
 
Array< PetscInt > _row_idx
 
Array< PetscInt > _row_ptr
 
Array< PetscScalar > _val
 

Detailed Description

The Kokkos wrapper class for PETSc matrix.

Definition at line 30 of file KokkosMatrix.h.

Constructor & Destructor Documentation

◆ Matrix()

Moose::Kokkos::Matrix::Matrix ( )
default

Default constructor.

◆ ~Matrix()

Moose::Kokkos::Matrix::~Matrix ( )
inline

Destructor.

Definition at line 40 of file KokkosMatrix.h.

40 { destroy(); }
void destroy()
Free all data and reset.

Member Function Documentation

◆ close()

void Moose::Kokkos::Matrix::close ( )

Assemble the underlying PETSc matrix.

◆ create()

void Moose::Kokkos::Matrix::create ( libMesh::SparseMatrix< PetscScalar > &  matrix,
const System system 
)

Create the matrix from a libMesh PetscMatrix.

Parameters
matrixThe libMesh PetscMatrix
systemThe Kokkos system

◆ destroy()

void Moose::Kokkos::Matrix::destroy ( )

Free all data and reset.

Referenced by ~Matrix().

◆ find()

KOKKOS_FUNCTION PetscInt Moose::Kokkos::Matrix::find ( PetscInt  i,
PetscInt  j 
) const
inlineprivate

Get the index of given row and column indices.

Parameters
iThe row index local to this process
jThe global column index
Returns
The index into the nonzero vector, and -1 if not found

Definition at line 138 of file KokkosMatrix.h.

Referenced by operator()().

139 {
140  KOKKOS_ASSERT(i < _nr);
141 
142  auto begin = _col_idx.data() + _row_ptr[i];
143  auto end = _col_idx.data() + _row_ptr[i + 1];
144  auto target = Utils::find(j, begin, end);
145 
146  if (target == end)
147  return -1;
148  else
149  return target - _col_idx.data();
150 }
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:30
Array< PetscInt > _col_idx
CSR vectors on device.
Definition: KokkosMatrix.h:121
Array< PetscInt > _row_ptr
Definition: KokkosMatrix.h:123
PetscCount _nr
Number of rows local to this process.
Definition: KokkosMatrix.h:116

◆ isAlloc()

bool Moose::Kokkos::Matrix::isAlloc ( ) const
inline

Get whether the matrix was allocated.

Returns
Whether the matrix was allocated

Definition at line 51 of file KokkosMatrix.h.

51 { return _is_alloc; }
bool _is_alloc
Flag whether the matrix was allocated.
Definition: KokkosMatrix.h:133

◆ operator()()

KOKKOS_FUNCTION PetscScalar& Moose::Kokkos::Matrix::operator() ( PetscInt  i,
PetscInt  j 
) const
inline

Get an entry with given row and column indices.

Parameters
iThe row index local to this process
jThe global column index
Returns
The reference of the element

Definition at line 78 of file KokkosMatrix.h.

79  {
80  auto idx = find(i, j);
81 
82  KOKKOS_ASSERT(idx != -1)
83 
84  return _val[idx];
85  }
Array< PetscScalar > _val
Definition: KokkosMatrix.h:124
KOKKOS_FUNCTION PetscInt find(PetscInt i, PetscInt j) const
Get the index of given row and column indices.
Definition: KokkosMatrix.h:138
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)

◆ operator=()

auto& Moose::Kokkos::Matrix::operator= ( PetscScalar  scalar)
inline

Assign a scalar value uniformly.

Parameters
scalarThe scalar value to be assigned

Definition at line 90 of file KokkosMatrix.h.

91  {
92  _val = scalar;
93 
94  return *this;
95  }
Array< PetscScalar > _val
Definition: KokkosMatrix.h:124

◆ zero()

KOKKOS_FUNCTION void Moose::Kokkos::Matrix::zero ( PetscInt  i)
inline

Zero a row.

Parameters
iThe row index local to this process to be zeroed

Definition at line 67 of file KokkosMatrix.h.

68  {
69  for (PetscInt j = _row_ptr[i]; j < _row_ptr[i + 1]; ++j)
70  _val[j] = 0;
71  }
Array< PetscScalar > _val
Definition: KokkosMatrix.h:124
Array< PetscInt > _row_ptr
Definition: KokkosMatrix.h:123

Member Data Documentation

◆ _col_idx

Array<PetscInt> Moose::Kokkos::Matrix::_col_idx
private

CSR vectors on device.

Definition at line 121 of file KokkosMatrix.h.

Referenced by find().

◆ _is_alloc

bool Moose::Kokkos::Matrix::_is_alloc = false
private

Flag whether the matrix was allocated.

Definition at line 133 of file KokkosMatrix.h.

Referenced by isAlloc().

◆ _is_host

bool Moose::Kokkos::Matrix::_is_host = false
private

Flag whether the PETSc matrix is a host matrix.

Definition at line 129 of file KokkosMatrix.h.

◆ _matrix

Mat Moose::Kokkos::Matrix::_matrix = PETSC_NULLPTR
private

PETSc matrix.

Definition at line 112 of file KokkosMatrix.h.

◆ _nr

PetscCount Moose::Kokkos::Matrix::_nr = 0
private

Number of rows local to this process.

Definition at line 116 of file KokkosMatrix.h.

Referenced by find().

◆ _row_idx

Array<PetscInt> Moose::Kokkos::Matrix::_row_idx
private

Definition at line 122 of file KokkosMatrix.h.

◆ _row_ptr

Array<PetscInt> Moose::Kokkos::Matrix::_row_ptr
private

Definition at line 123 of file KokkosMatrix.h.

Referenced by find(), and zero().

◆ _val

Array<PetscScalar> Moose::Kokkos::Matrix::_val
private

Definition at line 124 of file KokkosMatrix.h.

Referenced by operator()(), operator=(), and zero().


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