Sparse Matrices
Implements sparse matrices data structures as dedicated CSR matrices
sparse_matrix_csr
.
Each instance of sparse_matrix_csr
corresponds to a rank-1
array of a tuple of dynamically reallocated arrays,
sparse_row_csr
:
one array store the columns indices and one array store the values of
the non-zero elements of a given matrix.
This structure guarantees \(O(1)\) access. If MPI parallelization is enabled the structure includes an automatic rows split balanced among the different threads and a further subdivision of the columns/values in local and non-local blocks.
Note
A more modern, object oriented, class for sparse matrices is available in SciFortran
Description
This class defines a data structure to efficiently store sparse matrices into dedicated CSR matrices, featuring support to MPI parallel storage, so that each matrix is spread across the threads.
Quick access
- Types:
- Routines:
sp_dump_matrix()
,sp_init_matrix()
,sp_insert_element()
,sp_set_mpi_matrix()
Used modules
ed_input_vars
: User-accessible input variables
External modules
mpi
Types
- type ed_sparse_matrix/sparse_row_csr
The sparse row data structure containing the non-zero elements on any given row of sparse matrix.
- Type fields:
size [integer] – the current size of the row, corresponding to number of non-zero elements
dvals (•) [real, allocatable] – rank-1 array for double precision values
cvals (•) [complex, allocatable] – rank-1 array for double complex values
cols (•) [integer, allocatable] – rank-1 array for column indices
- type ed_sparse_matrix/sparse_matrix_csr
The sparse matrix data structure realized as an allocatable array of of
sparse_row_csr
types.- Type fields:
row (•) [sparse_row_csr, pointer] – the array of
sparse_row_csr
nrow [integer] – the total number of rows
ncol [integer] – the total number of columns
status [logical] – Allocation status
loc (•) [sparse_row_csr, pointer] – the array of
sparse_row_csr
for the diagonal blocksistart [integer] – starting index for the MPI decomposition of the sparse matrix
iend [integer] – ending index for the MPI decomposition of the sparse matrix
ishift [integer] – integer shift index for the MPI decomposition of the sparse matrix
mpi [logical]
Subroutines and functions
- interface ed_sparse_matrix/sp_init_matrix(sparse, n, mpicomm[, n1])
Initialization of the
sparse_matrix_csr
via memory allocation. An empty matrix is returned- Parameters:
sparse [sparse_matrix_csr, inout] – sparse matrix to be initialized
n [integer] – Number of rows
mpicomm [integer] – MPI global communicator
- Options:
n1 [integer] – Number of columns [Optional]. If not present
N1=N
- interface ed_sparse_matrix/sp_insert_element(sparse, value, i, j, mpicomm)
Matrix element insertion at a given row and columns. If an active MPI communicator is passed as input the element is stored in the matrix chunk of the corresponding thread. Double precision and double complex values are supported.
- Parameters:
sparse [sparse_matrix_csr, inout]
value [real/complex, in] – matrix value to be inserted
i [integer, in] – row index of the matrix value to be inserted
j [integer, in] – column index of the matrix value to be inserted
mpicomm [integer] – MPI global communicator
- interface ed_sparse_matrix/sp_dump_matrix(sparse, matrix, mpicomm)
Dump the
sparse_matrix_csr
into a dense matrix.- Parameters:
sparse [sparse_matrix_csr, in] – sparse matrix to dump
matrix (•, •) [real/complex, inout] – dense matrix having the same type of the sparse one
mpicomm [integer] – MPI global communicator
- interface ed_sparse_matrix/sp_set_mpi_matrix(mpicomm, sparse, istart, iend, ishift)
Set up the MPI parameters in the
sparse_matrix_csr
for automatic spread of the values across the threads- Parameters:
mpicomm [integer] – MPI global communicator
sparse [sparse_matrix_csr, inout]
istart [integer] – starting index for the MPI decomposition of the sparse matrix
iend [integer] – ending index for the MPI decomposition of the sparse matrix
ishift [integer] – shift index for the MPI decomposition of the sparse matrix