Finds block to which a full element belongs.
Assumptions It is assumed that block_start and block_end are sorted and that hint is in the range [0, nblocks].
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | full |
full element |
||
integer, | intent(out) | :: | block |
block to which full belongs |
||
integer, | intent(in) | :: | nblocks | |||
integer, | intent(in), | DIMENSION(1:nblocks + 1) | :: | block_offsets |
starting full elements of blocks |
|
integer, | intent(in) | :: | hint |
where to start looking; ignored if 0 |
SUBROUTINE find_block_of_element(full, block, nblocks, &
block_offsets, hint)
!! Finds block to which a full element belongs.
!!
!! Assumptions
!! It is assumed that block_start and block_end are sorted and
!! that hint is in the range [0, nblocks].
INTEGER, INTENT(in) :: full
!! full element
INTEGER, INTENT(out) :: block
!! block to which full belongs
INTEGER, INTENT(in) :: nblocks
INTEGER, DIMENSION(1:nblocks + 1), INTENT(in) :: block_offsets
!! starting full elements of blocks
INTEGER, INTENT(in) :: hint
!! where to start looking; ignored if 0
LOGICAL, PARAMETER :: dbg = .FALSE.
INTEGER :: count
IF (hint .NE. 0) THEN
block = hint
ELSE
block = MAX(1, (nblocks + 1)/2)
END IF
count = 0
DO WHILE (block_offsets(block) .GT. full .OR. block_offsets(block + 1) - 1 .LT. full)
IF (block_offsets(block) .GT. full) THEN
block = block - 1
ELSEIF (block_offsets(block + 1) - 1 .LT. full) THEN
block = block + 1
END IF
count = count + 1
IF (dbg) THEN
IF (count .GT. nblocks .OR. block .LT. 1 .OR. block .GT. nblocks) THEN
WRITE (*, '(1X,A,I9,A,I9,A)') "Want to find block", &
block, " of", nblocks, " blocks"
IF (count .GT. nblocks) &
DBCSR_ABORT("Too many searches")
END IF
END IF
END DO
END SUBROUTINE find_block_of_element