csrmat_m Module

Algebra routines for - vectors - sparse matrices in csr format



Derived Types

type, public, bind(C) ::  csrmat_data_t

Data type used to expose csrmat_t data to C/C++ Please see csrmat_t for descriptions of individual properties/members. Values are copied directly. Arrays are exposed with pointers.

Components

Type Visibility Attributes Name Initial
integer(kind=c_int32_t), public :: ndim
integer(kind=c_int32_t), public :: ncol
integer(kind=c_int32_t), public :: nnz
type(c_ptr), public :: i
type(c_ptr), public :: j
type(c_ptr), public :: val

type, public ::  csrmat_t

Compressed-sparse-row (CSR) matrix format

Components

Type Visibility Attributes Name Initial
integer, public :: ndim

Number of rows (dimension)

integer, public :: ncol

Number of columns

integer, public :: nnz

Number of non-zero elements

integer, public, allocatable, dimension(:) :: i

i-array in CSR format, of dimension ndim+1

integer, public, allocatable, dimension(:) :: j

j-array in CSR format, of dimension nnz

real(kind=FP), public, allocatable, dimension(:) :: val

val-array in CSR format, of dimension nnz

Finalizations Procedures

final :: destructor

Type-Bound Procedures

procedure, public :: write_netcdf
procedure, public :: read_netcdf
procedure, public :: sortsum
procedure, public :: create_copy
procedure, public :: display
procedure, public :: expose_data

Functions

public pure function csr_times_vec_single(a, x, row)

Computes element row of vector y = A*x Thread safe, i.e. can be called from within parallel region

Arguments

Type IntentOptional Attributes Name
type(csrmat_t), intent(in) :: a

csr matrix

real(kind=FP), intent(in), dimension(a%ncol) :: x

vector x

integer, intent(in) :: row

row of matrix

Return Value real(kind=fp)

public function diffvecs_nrm(n, x, y)

computes norm of difference of two vectors, i.e. ||x-y|| / n

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: n

dimension of vectors

real(kind=FP), intent(in), dimension(n) :: x

vector x

real(kind=FP), intent(in), dimension(n) :: y

vector y

Return Value real(kind=fp)


Subroutines

public subroutine read_netcdf(self, fgid)

Reads csr matrix from file

Arguments

Type IntentOptional Attributes Name
class(csrmat_t), intent(inout) :: self

csr matrix

integer, intent(in) :: fgid

File or group id number of existing Netcdf4 file

public subroutine write_netcdf(self, fgid)

writes csr matrix to file

Arguments

Type IntentOptional Attributes Name
class(csrmat_t), intent(in) :: self

csr matrix

integer, intent(in) :: fgid

file or group id number of existing Netcdf4 file

public subroutine create_copy(self, res)

Creates a copy of the matrix

Arguments

Type IntentOptional Attributes Name
class(csrmat_t), intent(in) :: self

Matrix

type(csrmat_t), intent(out) :: res

Copy of matrix

public subroutine sortsum(self)

sorts and sums entries in ascending j-order for each row

Arguments

Type IntentOptional Attributes Name
class(csrmat_t), intent(inout) :: self

csr matrix

public subroutine display(self)

displays some information on matrix

Arguments

Type IntentOptional Attributes Name
class(csrmat_t), intent(in) :: self

csr matrix

public subroutine expose_data(self, data_object)

Exposes csrmat data through csrmat_data_t object

Arguments

Type IntentOptional Attributes Name
class(csrmat_t), intent(in), target :: self

Instance of the type

type(csrmat_data_t), intent(out) :: data_object

Destination csrmat data object that contains the exposed data of the csrmat object.

public subroutine destructor(self)

destructor, frees memory

Arguments

Type IntentOptional Attributes Name
type(csrmat_t), intent(inout) :: self

csr matrix

public subroutine csr_times_vec(a, x, y)

Multiplies matrix with vector y = A*x Thread safe, i.e. can be called from within parallel region

Arguments

Type IntentOptional Attributes Name
type(csrmat_t), intent(in) :: a

csr matrix

real(kind=FP), intent(in), dimension(a%ncol) :: x

vector x

real(kind=FP), intent(out), dimension(a%ndim) :: y

vector y (result)

public subroutine csr_residuum(a, x, b, res, resmax, epsb)

Computes the residuum ||Ax-b|| / (||b||+eps)

Arguments

Type IntentOptional Attributes Name
type(csrmat_t), intent(in) :: a

csr matrix

real(kind=FP), intent(in), dimension(a%ncol) :: x

Vector x

real(kind=FP), intent(in), dimension(a%ndim) :: b

Vector b

real(kind=FP), intent(out) :: res

Residuum (root mean square)

real(kind=FP), intent(out), optional :: resmax

Residuum (maximum)

real(kind=FP), intent(in), optional :: epsb

Tolerance for division of b in residual Dafault value FP_EPS

public subroutine csr_transpose(a, atransp)

Transposes matrix a

Arguments

Type IntentOptional Attributes Name
type(csrmat_t), intent(in) :: a

CSR matrix

type(csrmat_t), intent(out), allocatable :: atransp

Transposed matrix in CSR format

public subroutine csr_transpose(a, atransp)

Transposes matrix a

Arguments

Type IntentOptional Attributes Name
type(csrmat_t), intent(in) :: a

CSR matrix

type(csrmat_t), intent(out), allocatable :: atransp

Transposed matrix in CSR format