Advances to the next block
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dbcsr_iterator), | intent(inout) | :: | iterator |
the iterator |
SUBROUTINE iterator_advance(iterator)
!! Advances to the next block
TYPE(dbcsr_iterator), INTENT(INOUT) :: iterator
!! the iterator
INTEGER :: ithread, my_old_row, p
LOGICAL :: advance, jumped_row
! ---------------------------------------------------------------------------
ithread = 0
!$ ithread = omp_get_thread_num()
IF (iterator%dynamic .AND. iterator%shared) THEN
IF (iterator%dynamic_byrows) THEN
! In this case common_row holds the last assigned row.
!
! The idea is to advance in this thread's row. If it gets bumped
! into the next row, then we have to find the correct one.
advance = .TRUE.
DO WHILE (advance)
iterator%pos = iterator%pos + 1
my_old_row = iterator%row
CALL find_proper_position_caller(iterator)
jumped_row = iterator%row .GT. my_old_row
advance = jumped_row
IF (jumped_row) THEN
!$OMP CRITICAL (crit_common_pos)
! Set the common_pos to the next available row.
iterator%common_pos = MAX(iterator%row, iterator%common_pos + 1)
iterator%row = iterator%common_pos
!$OMP END CRITICAL (crit_common_pos)
IF (iterator%row .GT. iterator%nblkrows_total) THEN
iterator%pos = 0
iterator%row = 0
advance = .FALSE.
ELSE
! To be incremented in the next loop.
IF (.NOT. iterator%local_indexing) THEN
iterator%pos = iterator%row_p(iterator%row)
ELSE
iterator%pos = iterator%row_p(iterator%global_rows(iterator%row))
END IF
END IF
END IF
END DO
ELSE
! In this case common_pos holds the last-assigned block.
!
!$OMP CRITICAL (crit_common_pos)
iterator%common_pos = iterator%common_pos + 1
iterator%pos = iterator%common_pos
CALL find_proper_position_caller(iterator)
p = iterator%pos
iterator%common_pos = MAX(iterator%common_pos, p)
!$OMP END CRITICAL (crit_common_pos)
END IF
ELSEIF (iterator%shared) THEN
iterator%pos = iterator%pos + 1
ithread = 0
!$ ithread = OMP_GET_THREAD_NUM()
CALL find_proper_position_caller(iterator, use_ithread=ithread)
ELSE
iterator%pos = iterator%pos + 1
CALL find_proper_position_caller(iterator)
END IF
END SUBROUTINE iterator_advance