Template Numerical Library version\ main:9e7b0f4
Loading...
Searching...
No Matches
TNL::Matrices::HypreParCSRMatrix Class Reference

Wrapper for Hypre's sequential CSR matrix. More...

#include <TNL/Matrices/HypreParCSRMatrix.h>

Public Types

using ColumnIndexesVectorType = Containers::Vector< IndexType, DeviceType, IndexType >
using ColumnIndexesViewType = typename ColumnIndexesVectorType::ViewType
using ConstColumnIndexesViewType = typename ColumnIndexesVectorType::ConstViewType
using ConstSegmentsViewType = Algorithms::Segments::CSRView< DeviceType, std::add_const_t< IndexType > >
using ConstValuesViewType = typename ValuesViewType::ConstViewType
using DeviceType = HYPRE_Device
using IndexType = HYPRE_Int
using LocalRangeType = Containers::Subrange< IndexType >
using MatrixType = HypreCSRMatrix
using RealType = HYPRE_Real
using SegmentsViewType = Algorithms::Segments::CSRView< DeviceType, IndexType >
using ValuesViewType = Containers::VectorView< RealType, DeviceType, IndexType >
using ValueType = RealType

Public Member Functions

 HypreParCSRMatrix (const HypreParCSRMatrix &other)=delete
 HypreParCSRMatrix (hypre_ParCSRMatrix *handle, bool take_ownership=true)
 Convert Hypre's format to HypreParCSRMatrix.
 HypreParCSRMatrix (HypreParCSRMatrix &&other) noexcept
void bind (hypre_ParCSRMatrix *handle, bool take_ownership=true)
 Convert Hypre's format to HypreParCSRMatrix.
void bind (MPI_Comm communicator, IndexType global_num_rows, IndexType global_num_cols, LocalRangeType local_row_range, LocalRangeType local_col_range, hypre_CSRMatrix *diag, hypre_CSRMatrix *offd, IndexType *col_map_offd)
 Binds ParCSRMatrix to local diag and offd blocks.
IndexType getColumns () const
MPI_Comm getCommunicator () const
MatrixType getDiagonalBlock ()
LocalRangeType getLocalColumnRange () const
LocalRangeType getLocalRowRange () const
HypreCSRMatrix getMergedLocalMatrix () const
 Constructs a local matrix by merging the diagonal and off-diagonal blocks.
IndexType getNonzeroElementsCount () const
MatrixType getOffdiagonalBlock ()
Containers::VectorView< HYPRE_Int, HYPRE_Device, HYPRE_Int > getOffdiagonalColumnsMapping ()
IndexType getRows () const
 operator const hypre_ParCSRMatrix * () const noexcept
 operator HYPRE_ParCSRMatrix () const noexcept
 operator hypre_ParCSRMatrix * () noexcept
HypreParCSRMatrixoperator= (const HypreParCSRMatrix &other)=delete
HypreParCSRMatrixoperator= (HypreParCSRMatrix &&other) noexcept
void reset ()
 Reset the matrix to empty state.

Static Public Member Functions

static HypreParCSRMatrix fromLocalBlocks (MPI_Comm communicator, IndexType global_num_rows, IndexType global_num_cols, LocalRangeType local_row_range, LocalRangeType local_col_range, hypre_CSRMatrix *local_A)
 Constructs a ParCSRMatrix from local blocks distributed across the processors in communicator.
static HypreParCSRMatrix fromMasterRank (hypre_CSRMatrix *matrix, hypre_ParVector *x, hypre_ParVector *b)
 Constructs a ParCSRMatrix distributed across the processors in communicator from a CSRMatrix on rank 0.
static HypreParCSRMatrix fromMasterRank (MPI_Comm communicator, IndexType *global_row_starts, IndexType *global_col_starts, hypre_CSRMatrix *matrix)
 Constructs a ParCSRMatrix distributed across the processors in communicator from a CSRMatrix on rank 0.
static HypreParCSRMatrix wrapCSRMatrix (hypre_CSRMatrix *matrix)
 Wrap a global hypre_CSRMatrix into HypreParCSRMatrix.

Protected Attributes

hypre_ParCSRMatrix * m = nullptr
bool owns_col_map_offd = true
bool owns_diag = true
bool owns_handle = true
bool owns_offd = true

Detailed Description

Constructor & Destructor Documentation

◆ HypreParCSRMatrix()

TNL::Matrices::HypreParCSRMatrix::HypreParCSRMatrix ( hypre_ParCSRMatrix * handle,
bool take_ownership = true )
inlineexplicit

Convert Hypre's format to HypreParCSRMatrix.

Parameters
handleis the Hypre vector handle.
take_ownershipindicates if the matrix should take ownership of the handle, i.e. whether to call hypre_CSRMatrixDestroy when it does not need it anymore.

Member Function Documentation

◆ bind() [1/2]

void TNL::Matrices::HypreParCSRMatrix::bind ( hypre_ParCSRMatrix * handle,
bool take_ownership = true )
inline

Convert Hypre's format to HypreParCSRMatrix.

Parameters
handleis the Hypre vector handle.
take_ownershipindicates if the matrix should take ownership of the handle, i.e. whether to call hypre_CSRMatrixDestroy when it does not need it anymore.

◆ bind() [2/2]

void TNL::Matrices::HypreParCSRMatrix::bind ( MPI_Comm communicator,
IndexType global_num_rows,
IndexType global_num_cols,
LocalRangeType local_row_range,
LocalRangeType local_col_range,
hypre_CSRMatrix * diag,
hypre_CSRMatrix * offd,
IndexType * col_map_offd )
inline

Binds ParCSRMatrix to local diag and offd blocks.

Parameters
communicatorMPI communicator to associate with the matrix.
global_num_rowsGlobal number of rows of the distributed matrix.
global_num_colsGlobal number of columns of the distributed matrix.
local_row_rangeThe range [begin, end) of rows owned by the calling rank.
local_col_rangeThe range [begin, end) of columns owned by the calling rank. For square matrices it should be equal to local_row_range.
diagThe local diagonal matrix block owned by the calling rank.
offdThe local off-diagonal matrix block owned by the calling rank.
col_map_offdMapping of local-to-global indices for the columns in the off-diagonal block. It must be always a host pointer.

◆ fromLocalBlocks()

HypreParCSRMatrix TNL::Matrices::HypreParCSRMatrix::fromLocalBlocks ( MPI_Comm communicator,
IndexType global_num_rows,
IndexType global_num_cols,
LocalRangeType local_row_range,
LocalRangeType local_col_range,
hypre_CSRMatrix * local_A )
inlinestaticnodiscard

Constructs a ParCSRMatrix from local blocks distributed across the processors in communicator.

Parameters
communicatorMPI communicator to associate with the matrix.
global_num_rowsGlobal number of rows of the distributed matrix.
global_num_colsGlobal number of columns of the distributed matrix.
local_row_rangeThe range [begin, end) of rows owned by the calling rank.
local_col_rangeThe range [begin, end) of columns owned by the calling rank. For square matrices it should be equal to local_row_range.
local_AThe local matrix block owned by the calling rank. The number of rows must match the size of local_row_range and the column indices must span the whole [0, global_cols) range.

◆ fromMasterRank() [1/2]

HypreParCSRMatrix TNL::Matrices::HypreParCSRMatrix::fromMasterRank ( hypre_CSRMatrix * matrix,
hypre_ParVector * x,
hypre_ParVector * b )
inlinestaticnodiscard

Constructs a ParCSRMatrix distributed across the processors in communicator from a CSRMatrix on rank 0.

Note
This function can be used only for matrices allocated on the host.
Parameters
matrixMatrix allocated on the master rank to be distributed.
xThe values of the vector are unused, but its distribution is used for the distribution of the matrix columns.
bThe values of the vector are unused, but its distribution is used for the distribution of the matrix rows.

◆ fromMasterRank() [2/2]

HypreParCSRMatrix TNL::Matrices::HypreParCSRMatrix::fromMasterRank ( MPI_Comm communicator,
IndexType * global_row_starts,
IndexType * global_col_starts,
hypre_CSRMatrix * matrix )
inlinestaticnodiscard

Constructs a ParCSRMatrix distributed across the processors in communicator from a CSRMatrix on rank 0.

Note
This function can be used only for matrices allocated on the host.
Parameters
communicatorMPI communicator to associate with the matrix.
global_row_startsArray of nproc + 1 elements, where nproc is the number of ranks in the communicator.
global_col_startsArray of nproc + 1 elements, where nproc is the number of ranks in the communicator.
matrixMatrix allocated on the master rank to be distributed.

◆ wrapCSRMatrix()

HypreParCSRMatrix TNL::Matrices::HypreParCSRMatrix::wrapCSRMatrix ( hypre_CSRMatrix * matrix)
inlinestaticnodiscard

Wrap a global hypre_CSRMatrix into HypreParCSRMatrix.

Each rank will get its own independent HypreParCSRMatrix with the MPI_COMM_SELF communicator. The data is not copied, but HypreParCSRMatrix keeps a non-owning reference.


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