dbcsr_csr_conversions Module

DBCSR to CSR matrix format conversion



Variables

Type Visibility Attributes Name Initial
character(len=*), private, parameter :: moduleN = 'dbcsr_csr_conversions'
logical, private, parameter :: careful_mod = .FALSE.
integer, public, parameter :: csr_dbcsr_blkrow_dist = 1
integer, public, parameter :: csr_eqrow_ceil_dist = 2
integer, public, parameter :: csr_eqrow_floor_dist = 3

Interfaces

private interface csr_create

  • public subroutine csr_create_new(csr_mat, nrows_total, ncols_total, nze_total, nze_local, nrows_local, mp_group, data_type)

    Create a new CSR matrix and allocate all internal data (excluding dbcsr_mapping)

    Arguments

    Type IntentOptional Attributes Name
    type(csr_type), intent(out) :: csr_mat

    CSR matrix to return

    integer, intent(in) :: nrows_total

    total number of rows total number of columns

    integer, intent(in) :: ncols_total

    total number of rows total number of columns

    integer(kind=int_8) :: nze_total

    total number of non-zero elements

    integer, intent(in) :: nze_local

    local number of non-zero elements local number of rows

    integer, intent(in) :: nrows_local

    local number of non-zero elements local number of rows

    type(mp_comm_type), intent(in) :: mp_group
    integer, intent(in), optional :: data_type

    data type of the CSR matrix (default real double prec.)

  • public subroutine csr_create_template(matrix_b, matrix_a)

    Create a new CSR matrix and allocate all internal data using an existing CSR matrix. Copies the indices but no actual matrix data.

    Arguments

    Type IntentOptional Attributes Name
    type(csr_type), intent(out) :: matrix_b

    Target CSR matrix

    type(csr_type), intent(in) :: matrix_a

    Source CSR matrix


Derived Types

type, private ::  csr_mapping_data

Mapping data relating local CSR indices to local indices of a block-row distributed (BRD) DBCSR matrix, and containing the block structure of the original DBCSR matrix from which the CSR matrix was created.

Components

Type Visibility Attributes Name Initial
integer, private, DIMENSION(:), POINTER :: csr_to_brd_ind => NULL()

csr_to_brd_ind(csr_ind) gives the location of a matrix element with CSR index csr_ind (location in nzval_local) inside the data_area of the corresponding BRD matrix. If an element of the DBCSR matrix is treated as 0 in the CSR format, the index of this value is not in csr_to_brd_ind. same as csr_to_brd_ind but inverse mapping. If a given DBCSR index dbcsr_ind points to a zero element, then brd_to_csr_ind(dbcsr_ind) is -1.

integer, private, DIMENSION(:), POINTER :: brd_to_csr_ind => NULL()

csr_to_brd_ind(csr_ind) gives the location of a matrix element with CSR index csr_ind (location in nzval_local) inside the data_area of the corresponding BRD matrix. If an element of the DBCSR matrix is treated as 0 in the CSR format, the index of this value is not in csr_to_brd_ind. same as csr_to_brd_ind but inverse mapping. If a given DBCSR index dbcsr_ind points to a zero element, then brd_to_csr_ind(dbcsr_ind) is -1.

type(dbcsr_type), private :: brd_mat = dbcsr_type()

DBCSR BRD matrix acting as an intermediate step in any conversion from and to DBCSR format.

logical, private :: has_dbcsr_block_data = .FALSE.

whether dbcsr_* fields are defined

integer, private :: dbcsr_nblkcols_total = -1

data from original DBCSR matrix (not block-row distributed), representing the original block structure.

integer, private :: dbcsr_nblkrows_total = -1

data from original DBCSR matrix (not block-row distributed), representing the original block structure.

integer, private :: dbcsr_nblks_local = -1

data from original DBCSR matrix (not block-row distributed), representing the original block structure.

integer, private, DIMENSION(:), POINTER :: dbcsr_row_p => NULL()

data from original DBCSR matrix (not block-row distributed), representing the original block structure.

integer, private, DIMENSION(:), POINTER :: dbcsr_col_i => NULL()

data from original DBCSR matrix (not block-row distributed), representing the original block structure.

integer, private, DIMENSION(:), POINTER :: dbcsr_row_blk_size => NULL()

data from original DBCSR matrix (not block-row distributed), representing the original block structure.

integer, private, DIMENSION(:), POINTER :: dbcsr_col_blk_size => NULL()

data from original DBCSR matrix (not block-row distributed), representing the original block structure.

type, private ::  csr_data_area_type

Data type of CSR matrices

Components

Type Visibility Attributes Name Initial
real(kind=real_4), public, DIMENSION(:), POINTER :: r_sp => Null()

real, single precision data array

real(kind=real_8), public, DIMENSION(:), POINTER :: r_dp => Null()

real, double precision data array

complex(kind=real_4), public, DIMENSION(:), POINTER :: c_sp => Null()

complex, double precision data array

complex(kind=real_8), public, DIMENSION(:), POINTER :: c_dp => Null()
integer, public :: data_type = -1

data type of CSR matrix

type, public ::  csr_type

Type for CSR matrices

Components

Type Visibility Attributes Name Initial
integer, public :: nrows_total = -1

total number of rows total number of columns local number of nonzero elements local number of rows

integer, public :: ncols_total = -1

total number of rows total number of columns local number of nonzero elements local number of rows

integer, public :: nze_local = -1

total number of rows total number of columns local number of nonzero elements local number of rows

integer, public :: nrows_local = -1

total number of rows total number of columns local number of nonzero elements local number of rows

type(mp_comm_type), public :: mp_group = mp_comm_type()

message-passing group ID

integer(kind=int_8), public :: nze_total = -1_int_8

total number of nonzero elements

integer, public, DIMENSION(:), POINTER :: rowptr_local => NULL()

indices of elements inside nzval_local starting a row column indices of elements inside nzval_local

integer, public, DIMENSION(:), POINTER :: colind_local => NULL()

indices of elements inside nzval_local starting a row column indices of elements inside nzval_local

integer, public, DIMENSION(:), POINTER :: nzerow_local => NULL()

indices of elements inside nzval_local starting a row column indices of elements inside nzval_local

type(csr_data_area_type), public :: nzval_local = csr_data_area_type()

values of local non-zero elements, row-wise ordering.

type(csr_mapping_data), public :: dbcsr_mapping = csr_mapping_data()

mapping data relating indices of nzval_local to indices of a block-row distributed DBCSR matrix

logical, public :: has_mapping = .FALSE.

whether dbcsr_mapping is defined

logical, public :: valid = .FALSE.

whether essential data (excluding dbcsr_mapping) is completely allocated

logical, public :: has_indices = .FALSE.

whether rowptr_local and colind_local are defined

type, public ::  csr_p_type

Components

Type Visibility Attributes Name Initial
type(csr_type), public, POINTER :: csr_mat => NULL()

Functions

private function dbcsr_has_same_block_structure(matrix_a, matrix_b) result(is_equal)

Helper function to assert that two DBCSR matrices have the same block structure and same sparsity pattern

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(in) :: matrix_a
type(dbcsr_type), intent(in) :: matrix_b

Return Value logical

whether matrix_a and matrix_b have the same block structure


Subroutines

public subroutine csr_create_new(csr_mat, nrows_total, ncols_total, nze_total, nze_local, nrows_local, mp_group, data_type)

Create a new CSR matrix and allocate all internal data (excluding dbcsr_mapping)

Arguments

Type IntentOptional Attributes Name
type(csr_type), intent(out) :: csr_mat

CSR matrix to return

integer, intent(in) :: nrows_total

total number of rows total number of columns

integer, intent(in) :: ncols_total

total number of rows total number of columns

integer(kind=int_8) :: nze_total

total number of non-zero elements

integer, intent(in) :: nze_local

local number of non-zero elements local number of rows

integer, intent(in) :: nrows_local

local number of non-zero elements local number of rows

type(mp_comm_type), intent(in) :: mp_group
integer, intent(in), optional :: data_type

data type of the CSR matrix (default real double prec.)

public subroutine csr_create_template(matrix_b, matrix_a)

Create a new CSR matrix and allocate all internal data using an existing CSR matrix. Copies the indices but no actual matrix data.

Arguments

Type IntentOptional Attributes Name
type(csr_type), intent(out) :: matrix_b

Target CSR matrix

type(csr_type), intent(in) :: matrix_a

Source CSR matrix

private subroutine csr_create_nzerow(csr_mat, nzerow)

create a vector containing the number of non-zero elements in each row of a CSR matrix

Arguments

Type IntentOptional Attributes Name
type(csr_type), intent(in) :: csr_mat

CSR matrix

integer, intent(inout), DIMENSION(:), POINTER :: nzerow

number of non-zero elements in each row

public subroutine csr_destroy(csr_mat)

destroy a CSR matrix

Arguments

Type IntentOptional Attributes Name
type(csr_type), intent(inout) :: csr_mat

private subroutine csr_create_from_brd(brd_mat, csr_mat, csr_sparsity_brd)

Allocate the internals of a CSR matrix using data from a block-row distributed DBCSR matrix

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(in) :: brd_mat

block-row-distributed DBCSR matrix

type(csr_type), intent(out) :: csr_mat

CSR matrix

type(dbcsr_type), intent(in) :: csr_sparsity_brd

BRD matrix representing sparsity pattern of CSR matrix

private subroutine csr_get_dbcsr_mapping(brd_mat, dbcsr_index, csr_index, csr_nze_local, csr_sparsity_brd)

create the mapping information between a block-row distributed DBCSR matrix and the corresponding CSR matrix

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(in) :: brd_mat

the block-row distributed DBCSR matrix

integer, intent(out), DIMENSION(:), POINTER :: dbcsr_index

csr to dbcsr index mapping dbcsr to csr index mapping

integer, intent(out), DIMENSION(:), POINTER :: csr_index

csr to dbcsr index mapping dbcsr to csr index mapping

integer, intent(out) :: csr_nze_local

number of local non-zero elements

type(dbcsr_type), intent(in) :: csr_sparsity_brd

sparsity of CSR matrix represented in BRD format

private subroutine convert_csr_to_brd(brd_mat, csr_mat)

Copies data from a CSR matrix to a block-row distributed DBCSR matrix. The DBCSR matrix must have a block structure consistent with the CSR matrix.

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(inout) :: brd_mat

block-row distributed DBCSR matrix

type(csr_type), intent(in) :: csr_mat

CSR matrix

private subroutine convert_brd_to_csr(brd_mat, csr_mat)

Convert a block-row distributed DBCSR matrix to a CSR matrix The DBCSR matrix must have a block structure consistent with the CSR matrix.

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(in) :: brd_mat

block-row distributed DBCSR matrix

type(csr_type), intent(inout) :: csr_mat

CSR matrix

public subroutine csr_create_from_dbcsr(dbcsr_mat, csr_mat, dist_format, csr_sparsity, numnodes)

create CSR matrix including dbcsr_mapping from arbitrary DBCSR matrix in order to prepare conversion.

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(in) :: dbcsr_mat
type(csr_type), intent(out) :: csr_mat
integer, intent(in) :: dist_format

how to distribute CSR rows over processes: csr_dbcsr_blkrow_dist: the number of rows per process is adapted to the row block sizes in the DBCSR format such that blocks are not split over different processes. csr_eqrow_ceil_dist: each process holds ceiling(N/P) CSR rows. csr_eqrow_floor_dist: each process holds floor(N/P) CSR rows.

type(dbcsr_type), intent(in), optional :: csr_sparsity

DBCSR matrix containing 0 and 1, representing CSR sparsity pattern 1: non-zero element 0: zero element (not present in CSR format) Note: matrix must be of data_type dbcsr_type_real_4 or dbcsr_type_real_8 (integer types not supported)

integer, intent(in), optional :: numnodes

number of nodes to use for distributing CSR matrix (optional, default is number of nodes used for DBCSR matrix)

private subroutine csr_assert_consistency_with_dbcsr(csr_mat, dbcsr_mat)

Helper function to assert that a given CSR matrix and a given DBCSR matrix are consistent before doing the conversion

Arguments

Type IntentOptional Attributes Name
type(csr_type), intent(in) :: csr_mat
type(dbcsr_type), intent(in) :: dbcsr_mat

public subroutine convert_dbcsr_to_csr(dbcsr_mat, csr_mat)

Convert a DBCSR matrix to a CSR matrix.

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(in) :: dbcsr_mat

DBCSR matrix to convert

type(csr_type), intent(inout) :: csr_mat

correctly allocated CSR matrix

public subroutine convert_csr_to_dbcsr(dbcsr_mat, csr_mat)

convert a CSR matrix to a DBCSR matrix

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(inout) :: dbcsr_mat

correctly allocated DBCSR matrix

type(csr_type), intent(inout) :: csr_mat

CSR matrix to convert

public subroutine dbcsr_to_csr_filter(dbcsr_mat, csr_sparsity, eps)

Apply filtering threshold eps to DBCSR blocks in order to improve CSR sparsity (currently only used for testing purposes)

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(in) :: dbcsr_mat
type(dbcsr_type), intent(out) :: csr_sparsity
real(kind=real_8), intent(in) :: eps

public subroutine csr_write(csr_mat, unit_nr, upper_triangle, threshold, binary)

Write a CSR matrix to file

Arguments

Type IntentOptional Attributes Name
type(csr_type), intent(in) :: csr_mat
integer, intent(in) :: unit_nr

unit number to which output is written

logical, intent(in), optional :: upper_triangle

If true (default: false), write only upper triangular part of matrix

real(kind=real_8), intent(in), optional :: threshold

threshold on the absolute value of the elements to be printed

logical, intent(in), optional :: binary

public subroutine csr_print_sparsity(csr_mat, unit_nr)

Print CSR sparsity

Arguments

Type IntentOptional Attributes Name
type(csr_type), intent(in) :: csr_mat
integer, intent(in) :: unit_nr

private subroutine dbcsr_create_brd(dbcsr_mat, brd_mat, equal_dist, floor_dist, numnodes)

Converts a DBCSR matrix to a block row distributed matrix.

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(in) :: dbcsr_mat

DBCSR matrix to be converted

type(dbcsr_type), intent(out) :: brd_mat

converted matrix

logical, intent(in) :: equal_dist

see documentation of csr_create_from_dbcsr see documentation of csr_create_from_dbcsr

logical, intent(in) :: floor_dist

see documentation of csr_create_from_dbcsr see documentation of csr_create_from_dbcsr

integer, intent(in) :: numnodes

number of nodes to use for block row distribution