Sparse Matrices

Implements sparse matrices data structures as dedicated CSR matrices. Each instance of sparse_matrix_csr corresponds to a rank-1 array of dynamically reallocated rows, sparse_row_csr, including one array for columns indices and one array for non-zero values of the dense matrix. Access to each element is \(O(1)\).

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:

sparse_row_csr, sparse_matrix_csr

Routines:

sp_init_matrix(), sp_insert_element(), sp_dump_matrix(), sp_set_mpi_matrix()

Used modules

  • ed_input_vars: Contains all global input variables which can be set by the user through the input file. A specific preocedure ed_read_input() should be called to read the input file using parse_input_variable() procedure from SciFortran. All variables are automatically set to a default, looked for and updated by reading into the file and, sequentially looked for and updated from command line (std.input) using the notation variable_name=variable_value(s) (case independent).

  • sf_mpi

  • 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:
    • cols (•) [integer, allocatable] – rank-1 array for column indices

    • cvals (•) [complex, allocatable] – rank-1 array for double complex values

    • dvals (•) [real, allocatable] – rank-1 array for double precision values

    • size [integer] – the current size of the row, corresponding to number of non-zero elements

  • 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:
    • iend [integer, optional/default=0] – ending index for the MPI decomposition of the sparse matrix

    • ishift [integer, optional/default=0] – integer shift index for the MPI decomposition of the sparse matrix

    • istart [integer, optional/default=0] – starting index for the MPI decomposition of the sparse matrix

    • loc (•) [sparse_row_csr, pointer] – the array of sparse_row_csr for the diagonal blocks

    • mpi [logical, optional/default=.false.]

    • ncol [integer] – the total number of columns

    • nrow [integer] – the total number of rows

    • row (•) [sparse_row_csr, pointer] – the array of sparse_row_csr

    • status [logical, optional/default=.false.] – Allocation status

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]

  • matrix (•, •) [real, complex, inout] – dense matrix corresponding to sparse having the same type.

  • 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