DOLFINx 0.12.0.0
DOLFINx C++
Loading...
Searching...
No Matches
SparsityPattern Class Reference

#include <SparsityPattern.h>

Public Member Functions

 SparsityPattern (MPI_Comm comm, std::array< std::shared_ptr< const common::IndexMap >, 2 > maps, std::array< int, 2 > bs)
 Create an empty sparsity pattern with specified dimensions.
 SparsityPattern (MPI_Comm comm, const std::vector< std::vector< const SparsityPattern * > > &patterns, const std::array< std::vector< std::pair< std::reference_wrapper< const common::IndexMap >, int > >, 2 > &maps, const std::array< std::vector< int >, 2 > &bs)
 Create a new sparsity pattern by concatenating sub-patterns, e.g. pattern =[ pattern00 ][ pattern 01] [ pattern10 ][ pattern 11].
 SparsityPattern (const SparsityPattern &pattern)=delete
 SparsityPattern (SparsityPattern &&pattern)=default
 Move constructor.
 ~SparsityPattern ()=default
 Destructor.
SparsityPattern & operator= (SparsityPattern &&pattern)=default
 Move assignment.
void reserve_blocks (std::size_t num_blocks, std::size_t num_rows, std::size_t num_cols)
 Reserve storage for additional insert(rows, cols) calls.
void insert (std::int32_t row, std::int32_t col)
 Insert non-zero locations using local (process-wise) indices.
void insert (std::span< const std::int32_t > rows, std::span< const std::int32_t > cols)
 Insert non-zero locations using local (process-wise) indices.
void insert_diagonal (std::span< const std::int32_t > rows)
 Insert non-zero locations on the diagonal.
void finalize ()
 Finalize sparsity pattern and communicate off-process entries.
std::shared_ptr< const common::IndexMap > index_map (int dim) const
 Index map for the rows and columns that will be set by the current MPI rank.
std::shared_ptr< const common::IndexMap > input_index_map (int dim) const
 Input index map for the rows and columns used to construct the pattern.
std::vector< std::int64_t > column_indices () const
 Global column indices corresponding to the local column indices used by SparsityPattern::graph.
int block_size (int dim) const
 Return index map block size for dimension dim.
std::int64_t num_nonzeros () const
 Number of nonzeros on this rank after assembly, including ghost rows.
std::int32_t nnz_diag (std::int32_t row) const
 Number of non-zeros in owned columns (diagonal block) on a given row.
std::int32_t nnz_off_diag (std::int32_t row) const
 Number of non-zeros in unowned columns (off-diagonal block) on a given row.
std::pair< std::span< const std::int32_t >, std::span< const std::int64_t > > graph () const
 Sparsity pattern graph after assembly. Uses local indices for the columns.
std::span< const std::int32_t > off_diagonal_offsets () const
 Row-wise start of off-diagonals (unowned columns) for each row.
MPI_Comm comm () const
 Return MPI communicator.

Detailed Description

Sparsity pattern data structure that can be used to initialize sparse matrices. After assembly, column indices are always sorted in increasing order. Ghost entries are kept after assembly.

Constructor & Destructor Documentation

◆ SparsityPattern() [1/2]

SparsityPattern ( MPI_Comm comm,
std::array< std::shared_ptr< const common::IndexMap >, 2 > maps,
std::array< int, 2 > bs )

Create an empty sparsity pattern with specified dimensions.

Parameters
[in]commCommunicator that the pattern is defined on.
[in]mapsIndex maps describing the [0] row and [1] column index ranges (up to a block size).
[in]bsBlock sizes for the [0] row and [1] column maps.

◆ SparsityPattern() [2/2]

SparsityPattern ( MPI_Comm comm,
const std::vector< std::vector< const SparsityPattern * > > & patterns,
const std::array< std::vector< std::pair< std::reference_wrapper< const common::IndexMap >, int > >, 2 > & maps,
const std::array< std::vector< int >, 2 > & bs )

Create a new sparsity pattern by concatenating sub-patterns, e.g. pattern =[ pattern00 ][ pattern 01] [ pattern10 ][ pattern 11].

Parameters
[in]commCommunicator that the pattern is defined on.
[in]patternsRectangular array of sparsity pattern. The patterns must not be finalised. Null blocks are permitted.
[in]mapsPairs of (index map, block size) for each row block (maps[0]) and column blocks (maps[1]).
[in]bsBlock sizes for the sparsity pattern entries.

Member Function Documentation

◆ column_indices()

std::vector< std::int64_t > column_indices ( ) const

Global column indices corresponding to the local column indices used by SparsityPattern::graph.

Entry i of the returned vector is the global index of local column i: for i in the owned range this is every owned column (whether or not it holds a non-zero entry), and for i beyond the owned range it is the ghost column, i.e. a column with at least one non-zero entry owned by another rank.

Note
The ghosts are computed only once SparsityPattern::finalize has been called.
Returns
Global column indices on this process, including ghosts.

◆ graph()

std::pair< std::span< const std::int32_t >, std::span< const std::int64_t > > graph ( ) const

Sparsity pattern graph after assembly. Uses local indices for the columns.

Note
Column global indices can be obtained from SparsityPattern::column_indices()
Includes ghost rows
Returns
Adjacency list edges and offsets

◆ index_map()

std::shared_ptr< const common::IndexMap > index_map ( int dim) const

Index map for the rows and columns that will be set by the current MPI rank.

Note
After finalization, the column index map is updated to account for additional column entries from other processes.
Parameters
[in]dimRequested map, row (0) or column (1).
Returns
The index map.

◆ input_index_map()

std::shared_ptr< const common::IndexMap > input_index_map ( int dim) const

Input index map for the rows and columns used to construct the pattern.

Note
Finalization can add column ghosts to index_map(1). When no rank adds a column ghost, input_index_map(1) and index_map(1) return the same object.
Parameters
[in]dimRequested map, row (0) or column (1).
Returns
The input index map.

◆ insert() [1/2]

void insert ( std::int32_t row,
std::int32_t col )

Insert non-zero locations using local (process-wise) indices.

Parameters
[in]rowlocal row index
[in]collocal column index

◆ insert() [2/2]

void insert ( std::span< const std::int32_t > rows,
std::span< const std::int32_t > cols )

Insert non-zero locations using local (process-wise) indices.

This routine inserts non-zero locations at the outer product of rows and cols into the sparsity pattern, i.e. adds the matrix entries at A[row[i], col[j]] for all i, j.

Note
Passing the same span for rows and cols avoids caching a second copy of the indices.
Parameters
[in]rowslist of the local row indices
[in]colslist of the local column indices

◆ insert_diagonal()

void insert_diagonal ( std::span< const std::int32_t > rows)

Insert non-zero locations on the diagonal.

Parameters
[in]rowsRows in local (process-wise) indices. The indices must exist in the row IndexMap.

◆ nnz_diag()

std::int32_t nnz_diag ( std::int32_t row) const

Number of non-zeros in owned columns (diagonal block) on a given row.

Note
Can also be used on ghost rows

◆ nnz_off_diag()

std::int32_t nnz_off_diag ( std::int32_t row) const

Number of non-zeros in unowned columns (off-diagonal block) on a given row.

Note
Can also be used on ghost rows

◆ off_diagonal_offsets()

std::span< const std::int32_t > off_diagonal_offsets ( ) const

Row-wise start of off-diagonals (unowned columns) for each row.

Note
Includes ghost rows

◆ reserve_blocks()

void reserve_blocks ( std::size_t num_blocks,
std::size_t num_rows,
std::size_t num_cols )

Reserve storage for additional insert(rows, cols) calls.

Blocks are cached in the form they are inserted in, so the number of calls and the total number of row and column indices are needed rather than the number of (row, column) entries.

Note
The request is applied by the next insert(rows, cols) call, the first point at which the cache it belongs to is known.
Parameters
[in]num_blocksNumber of insert(rows, cols) calls.
[in]num_rowsTotal number of row indices over those calls.
[in]num_colsTotal number of column indices over those calls.

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