csr_create_from_brd Subroutine

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


Source Code

   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

      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

      CHARACTER(LEN=*), PARAMETER :: routineN = 'csr_create_from_brd'

      INTEGER                                            :: data_type, handle, &
                                                            nfullcols_total, nfullrows, &
                                                            nfullrows_total, nze_local
      INTEGER(KIND=int_8)                                :: nze_total
      INTEGER, DIMENSION(:), POINTER                     :: cdist, csr_index, dbcsr_index
      TYPE(dbcsr_distribution_obj)                       :: dist_current
      TYPE(mp_comm_type)                                 :: mp_group

      CALL timeset(routineN, handle)
      NULLIFY (dbcsr_index, csr_index, cdist)

      dist_current = dbcsr_distribution(brd_mat)

      mp_group = dbcsr_mp_group(dbcsr_distribution_mp(dist_current))
      cdist => dbcsr_distribution_col_dist(dist_current)

      IF (ANY(cdist .NE. 0)) &
         DBCSR_ABORT("DBCSR matrix not block-row distributed.")

      ! Calculate mapping between BRD and CSR indices
      CALL csr_get_dbcsr_mapping(brd_mat, dbcsr_index, csr_index, nze_local, &
                                 csr_sparsity_brd)

      CALL dbcsr_get_info(brd_mat, nfullrows_total=nfullrows_total, &
                          nfullcols_total=nfullcols_total)

      ! Sum up local number of non-zero elements to get total number
      nze_total = nze_local
      CALL mp_sum(nze_total, mp_group)

      nfullrows = dbcsr_nfullrows_local(brd_mat)
      data_type = dbcsr_get_data_type(brd_mat)

      ! Allocate CSR matrix
      CALL csr_create_new(csr_mat, nfullrows_total, nfullcols_total, nze_total, &
                          nze_local, nfullrows, mp_group, data_type)

      csr_mat%dbcsr_mapping%brd_to_csr_ind => csr_index
      csr_mat%dbcsr_mapping%csr_to_brd_ind => dbcsr_index

      csr_mat%has_mapping = .TRUE.
      csr_mat%dbcsr_mapping%brd_mat = brd_mat

      CALL timestop(handle)
   END SUBROUTINE csr_create_from_brd