build_csr_index Subroutine

private subroutine build_csr_index(mi, mf, ai, af, row_p, blk_info, list_index, nnorms, csr_norms, list_norms)

Builds and sorts a CSR index from a list index.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: mi
integer, intent(in) :: mf
integer, intent(in) :: ai
integer, intent(in) :: af
integer, intent(out), DIMENSION(mi:mf + 1) :: row_p
integer, intent(out), DIMENSION(2, 1:af - ai + 1) :: blk_info
integer, intent(in), DIMENSION(3, 1:af) :: list_index
integer, intent(in) :: nnorms
real(kind=sp), intent(out), DIMENSION(1:af - ai + 1) :: csr_norms
real(kind=sp), intent(in), DIMENSION(:) :: list_norms

Source Code

   SUBROUTINE build_csr_index(mi, mf, ai, af, row_p, blk_info, list_index, &
      !! Builds and sorts a CSR index from a list index.
                              nnorms, csr_norms, list_norms)
      INTEGER, INTENT(IN)                                :: mi, mf, ai, af
      INTEGER, DIMENSION(mi:mf + 1), INTENT(OUT)           :: row_p
      INTEGER, DIMENSION(2, 1:af - ai + 1), INTENT(OUT)      :: blk_info
      INTEGER, DIMENSION(3, 1:af), INTENT(IN)            :: list_index
      INTEGER, INTENT(IN)                                :: nnorms
      REAL(KIND=sp), DIMENSION(1:af - ai + 1), INTENT(OUT)   :: csr_norms
      REAL(KIND=sp), DIMENSION(:), INTENT(IN)            :: list_norms

      LOGICAL, PARAMETER                                 :: careful = .FALSE., dbg = .FALSE.

      INTEGER                                            :: i, row
      INTEGER, DIMENSION(mi:mf)                          :: counts

!   ---------------------------------------------------------------------------
! Counts blocks per row and calculates the offsets.

      IF (dbg) THEN
         WRITE (*, '(I7,1X,5(A,2(1X,I7)))') 0, "bci", mi, mf, ";", ai, af
         !write(*,'(3(I7))')list_index(:,ai:af)
      END IF

      counts(:) = 0
      DO i = ai, af
         IF (careful) THEN
            IF (list_index(1, i) < mi) DBCSR_ABORT("Out of range")
            IF (list_index(1, i) > mf) DBCSR_ABORT("Out of range")
         END IF
         counts(list_index(1, i)) = counts(list_index(1, i)) + 1
      END DO
      row_p(mi) = 0
      DO i = mi + 1, mf + 1
         row_p(i) = row_p(i - 1) + counts(i - 1)
      END DO
      ! Adds every block to its corresponding row.
      counts(:) = 0
      DO i = ai, af
         row = list_index(1, i)
         counts(row) = counts(row) + 1
         IF (careful) THEN
            IF (row_p(row) + counts(row) > af - ai + 1) DBCSR_ABORT("Out of range")
            IF (row_p(row) + counts(row) < 1) DBCSR_ABORT("Out of range")
         END IF
         blk_info(1, row_p(row) + counts(row)) = list_index(2, i)
         blk_info(2, row_p(row) + counts(row)) = list_index(3, i)
         IF (nnorms .GT. 0) THEN
            csr_norms(row_p(row) + counts(row)) = list_norms(i)
         END IF
      END DO
      IF (nnorms .EQ. 0) THEN
         csr_norms(:) = 0.0_sp
      END IF
   END SUBROUTINE build_csr_index