Converts BCSR global row index to local row index.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_type), | intent(inout) | :: | matrix |
matrix for which to make canonical index |
SUBROUTINE dbcsr_make_index_local_row(matrix) !! Converts BCSR global row index to local row index. TYPE(dbcsr_type), INTENT(INOUT) :: matrix !! matrix for which to make canonical index CHARACTER(len=*), PARAMETER :: routineN = 'dbcsr_make_index_local_row' INTEGER :: error_handle, lrow, nlocal_rows, & ntotal_rows, prow INTEGER, ALLOCATABLE, DIMENSION(:) :: local_row_p INTEGER, DIMENSION(:), POINTER :: local_rows ! --------------------------------------------------------------------------- CALL timeset(routineN, error_handle) IF (.NOT. ASSOCIATED(matrix%row_p)) & DBCSR_ABORT("The row index must be initialized.") IF (matrix%bcsc) & DBCSR_ABORT("Not support for BCSC yet.") ! prow = matrix%index(dbcsr_slot_home_vprow) IF (prow .LT. 0) THEN prow = matrix%index(dbcsr_slot_home_prow) END IF nlocal_rows = matrix%nblkrows_local ALLOCATE (local_row_p(nlocal_rows + 1)) ! The existing row_p is converted from an indexing array into a ! counting array. Because it is later discarded, the counting is ! done in-place. ntotal_rows = matrix%nblkrows_total CALL dbcsr_count_row_index(matrix%row_p, ntotal_rows) ! We first have to find the local rows for the given prow. local_rows => array_data(matrix%local_rows) IF (SIZE(local_rows) /= nlocal_rows) & DBCSR_ABORT("Mismatch in the number of local rows.") ! The counts are mapped to local rows, DO lrow = 1, nlocal_rows local_row_p(lrow) = matrix%row_p(local_rows(lrow)) END DO IF (SUM(matrix%row_p(1:ntotal_rows)) /= SUM(local_row_p(1:nlocal_rows))) & DBCSR_ABORT("Inconsistent row counts. Perhaps non-local rows contain data?.") ! then converted into an index. CALL dbcsr_build_row_index(local_row_p, nlocal_rows) ! The local row index replaces the global one. CALL dbcsr_clearfrom_index_array(matrix, dbcsr_slot_row_p) CALL dbcsr_addto_index_array(matrix, dbcsr_slot_row_p, DATA=local_row_p) ! Finally the matrix is designated as having a local-based index. matrix%local_indexing = .TRUE. IF (careful_mod) THEN IF (array_size(matrix%local_rows) /= nlocal_rows) & DBCSR_ABORT("Inconsistent local row counts.") IF (array_size(matrix%global_rows) /= ntotal_rows) & DBCSR_ABORT("Inconsistent global row counts.") IF (array_size(matrix%global_rows) .EQ. 0) THEN IF (nlocal_rows /= 0) & DBCSR_ABORT("Invalid number of local or global rows.") END IF END IF DEALLOCATE (local_row_p) ! CALL timestop(error_handle) END SUBROUTINE dbcsr_make_index_local_row